Add standard msg header
authorNikita Kalyazin <n.kalyazin@samsung.com>
Thu, 13 Jun 2013 05:44:01 +0000 (09:44 +0400)
committerNikita Kalyazin <n.kalyazin@samsung.com>
Thu, 13 Jun 2013 05:44:01 +0000 (09:44 +0400)
TODO: add sequence number obtaining.

include/binproto.h
probe_memory/libdanew.cpp

index c6c83bd..bf469ee 100644 (file)
 #include <unistd.h>
 #include <sys/syscall.h>
 
+#include <sys/time.h>
+
+#define MSG_PROBE_MEMORY 0x3001
+#define MSG_PROBE_UICONTROL 0x3002
+#define MSG_PROBE_UIEVENT 0x3003
+#define MSG_PROBE_RESOUCE 0x3004
+#define MSG_PROBE_LIFECYCLE 0x30015
+#define MSG_PROBE_SCREENSHOT 0x3006
+#define MSG_PROBE_SCENE 0x3007
+#define MSG_PROBE_THREAD 0x3008
+#define MSG_PROBE_CUSTOM 0x3009
+#define MSG_PROBE_SYNC 0x3010
+
 // TODO: remove this copy-paste
 #define CALLER_ADDRESS \
        ((void*) __builtin_extract_return_addr(__builtin_return_address(0)))
@@ -50,6 +63,28 @@ static  char *pack_string(char *to, const char *str)
 }
 
 
+static  char *pack_msg_id(char *to, uint32_t msg_id)
+{
+       return pack_int32(to, msg_id);
+}
+
+static  char *pack_seq_num(char *to)
+{
+       // TODO: get seq num
+       return pack_int32(to, 0);
+}
+
+static  char *pack_timestamp(char *to)
+{
+       struct timeval tv;
+
+       gettimeofday(&tv, NULL);
+       to = pack_int32(to, tv.tv_sec);
+       to = pack_int32(to, tv.tv_usec * 1000);
+
+       return to;
+}
+
 static  char *pack_api_id(char *to, uint32_t api_id)
 {
        return pack_int32(to, api_id);
@@ -172,18 +207,24 @@ static  char *pack_caller_pc(char *to)
 }
 
 
-#define PACK_COMMON_BEGIN(to, api_id, fmt, ...) \
-       to = pack_api_id(to, api_id); \
-       to = pack_pid(to); \
-       to = pack_tid(to); \
+#define PACK_COMMON_BEGIN(to, msg_id, api_id, fmt, ...)        \
+       to = pack_msg_id(to, msg_id);                   \
+       to = pack_seq_num(to);                          \
+       to = pack_timestamp(to);                        \
+       to = pack_int32(to, 0);                         \
+       to = pack_api_id(to, api_id);                   \
+       to = pack_pid(to);                              \
+       to = pack_tid(to);                              \
        to = pack_args(to, fmt, __VA_ARGS__)
 
-#define PACK_COMMON_END(to, ret, pc)        \
-       to = pack_return(to, (uintptr_t)ret); \
-       to = pack_pc(to, (uintptr_t)pc);             \
-       to = pack_errno(to, (uint32_t)newerrno);     \
-       to = pack_internal_call(to); \
-       to = pack_caller_pc(to);
+#define PACK_COMMON_END(to, ret, pc, errn)           \
+       to = pack_return(to, (uintptr_t)ret);         \
+       to = pack_pc(to, (uintptr_t)pc);              \
+       to = pack_errno(to, (uint32_t)errn);          \
+       to = pack_internal_call(to);                  \
+       to = pack_caller_pc(to);                      \
+       to = pack_int32(to, 0);                       \
+       to = pack_int32(to, 0);
 
 #define PACK_MEMORY(to, size, memory_api_type, addr) \
        to = pack_int32(to, size); \
@@ -270,7 +311,10 @@ static  char *pack_caller_pc(char *to)
        char buf[LOCAL_BUF_SIZE];               \
        char *p = buf;
 
+#define MSG_LEN_OFFSET 16
+#define MSG_HDR_LEN 20
 #define FLUSH_LOCAL_BUF()                      \
+       *(uint32_t *)(buf + MSG_LEN_OFFSET) = (p - buf) - MSG_HDR_LEN;  \
        write(log_fd, buf, p - buf);
 
 
index 9246ffa..b854171 100644 (file)
@@ -69,8 +69,8 @@ void *operator new(std::size_t size) throw (std::bad_alloc)
        APPEND_LOG_CALLSTACK();
 
        PREPARE_LOCAL_BUF();
-       PACK_COMMON_BEGIN(p, LC_MEMORY, "d", size);
-       PACK_COMMON_END(p, pret, newp);
+       PACK_COMMON_BEGIN(p, MSG_PROBE_MEMORY, LC_MEMORY, "d", size);
+       PACK_COMMON_END(p, pret, newp, newerrno);
        PACK_MEMORY(p, size, MEMORY_API_ALLOC, pret);
        FLUSH_LOCAL_BUF();