From 030788aff3654a7c4beebbf4d2b5dfc8a7633f22 Mon Sep 17 00:00:00 2001 From: "Eunji, Lee" Date: Tue, 30 Jun 2015 11:16:17 +0900 Subject: [PATCH] [TTRACE] Sync. with T-trace package on tizen2.4 Change-Id: I6f35ad1861ea2d5fee51f4690183d969b4b50f47 Signed-off-by: Eunji, Lee --- CMakeLists.txt | 1 - include/ttrace.h | 5 +- packaging/exec-ttrace-marker | 5 +- packaging/ttrace-marker.service | 1 + packaging/ttrace.spec | 5 + packaging/ttrace_tag | 1 + src/atrace/atrace.cpp | 112 +++++++++-------- src/ttrace.c | 270 +++++++++++++++++++++++----------------- ttrace.manifest | 22 +--- 9 files changed, 230 insertions(+), 192 deletions(-) create mode 100755 packaging/ttrace_tag diff --git a/CMakeLists.txt b/CMakeLists.txt index c8f2fcf..7bd06ce 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ SET(VERSION "${VERSION_MAJOR}.1") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") - # compiler flags SET(EXTRA_CFLAGS "${EXTRA_CFLAGS}") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") diff --git a/include/ttrace.h b/include/ttrace.h index 809d124..5bfc5b9 100644 --- a/include/ttrace.h +++ b/include/ttrace.h @@ -25,7 +25,6 @@ extern "C" { /* Define TTRACE_TAG */ #define TTRACE_TAG_NEVER 0 // This tag is never enabled. #define TTRACE_TAG_ALWAYS (1<<0) // This tag is always enabled. -#define TTRACE_TAG_APP TTRACE_TAG_ALWAYS #define TTRACE_TAG_GRAPHICS (1<<1) #define TTRACE_TAG_INPUT (1<<2) #define TTRACE_TAG_VIEW (1<<3) @@ -40,8 +39,10 @@ extern "C" { #define TTRACE_TAG_MEDIA_CONTENT (1<<12) #define TTRACE_TAG_MEDIA_DB (1<<13) #define TTRACE_TAG_SCREEN_MIRRORING (1<<14) -#define TTRACE_TAG_LAST TTRACE_TAG_SCREEN_MIRRORING +#define TTRACE_TAG_APP (1<<15) +#define TTRACE_TAG_LAST TTRACE_TAG_APP +#define ENABLED_TAG_FILE "/etc/ttrace/ttrace_tag" void traceBegin(int tag, const char *name, ...); void traceEnd(int tag); void traceAsyncBegin(int tag, int cookie, const char *name, ...); diff --git a/packaging/exec-ttrace-marker b/packaging/exec-ttrace-marker index ebdb9f0..0acd9c0 100755 --- a/packaging/exec-ttrace-marker +++ b/packaging/exec-ttrace-marker @@ -1,6 +1,6 @@ #!/bin/bash -conf="/etc/ttrace.conf" +conf="/etc/ttrace/ttrace.conf" change_permission="--update" chmod 0222 /sys/kernel/debug/tracing/trace_marker @@ -44,7 +44,6 @@ attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/events/power/clock_set_rate/ #attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/events/cpufreq_interactive/enable attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/tracing_on attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/trace -attr -S -s SMACK64 -V '*' /usr/bin/atrace if [ -e "$conf" ] then @@ -62,7 +61,7 @@ then rm "$conf" else echo "$conf was NOT found!!!" - atrace + atrace --init_exec echo 0 > "/sys/kernel/debug/tracing/trace" echo 0 > "/sys/kernel/debug/tracing/tracing_on" fi diff --git a/packaging/ttrace-marker.service b/packaging/ttrace-marker.service index ac7b938..cdfccc9 100644 --- a/packaging/ttrace-marker.service +++ b/packaging/ttrace-marker.service @@ -6,6 +6,7 @@ After=sys-kernel-debug.mount [Service] Type=simple ExecStart=/usr/bin/exec-ttrace-marker +SmackProcessLabel=ttrace [Install] WantedBy=sys-kernel-debug.mount diff --git a/packaging/ttrace.spec b/packaging/ttrace.spec index 7f20546..605acea 100755 --- a/packaging/ttrace.spec +++ b/packaging/ttrace.spec @@ -7,6 +7,8 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz SOURCE101: packaging/exec-ttrace-marker SOURCE102: packaging/ttrace-marker.service +SOURCE103: packaging/ttrace_tag + BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(zlib) BuildRequires: pkgconfig(capi-base-common) @@ -43,6 +45,8 @@ mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} mkdir -p %{buildroot}/etc/systemd/system/sys-kernel-debug.mount.wants/ ln -s %{_libdir}/systemd/system/ttrace-marker.service %{buildroot}/etc/systemd/system/sys-kernel-debug.mount.wants/ttrace-marker.service +mkdir -p %{buildroot}/etc/ttrace +cp %{SOURCE103} %{buildroot}/etc/ttrace %post -p /sbin/ldconfig @@ -57,6 +61,7 @@ ln -s %{_libdir}/systemd/system/ttrace-marker.service %{buildroot}/etc/systemd/s %attr(755,root,root) %{_bindir}/atrace %attr(755,root,root) %{_bindir}/atrace-1.1 %attr(755,root,root) %{_bindir}/exec-ttrace-marker +%attr(664,root,root) /etc/ttrace/ttrace_tag /etc/systemd/system/sys-kernel-debug.mount.wants/ttrace-marker.service /usr/share/license/%{name} diff --git a/packaging/ttrace_tag b/packaging/ttrace_tag new file mode 100755 index 0000000..c227083 --- /dev/null +++ b/packaging/ttrace_tag @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/src/atrace/atrace.cpp b/src/atrace/atrace.cpp index 5eb915c..bef8226 100755 --- a/src/atrace/atrace.cpp +++ b/src/atrace/atrace.cpp @@ -31,11 +31,11 @@ #include #include #include -#include -#include +#include #include "ttrace.h" #define TTRACE_TAG_NONE 9999 #define TAG_NONE_IDX 0 + #else #include #include @@ -52,15 +52,13 @@ using namespace android; enum { MAX_SYS_FILES = 8 }; -#ifdef DEVICE_TYPE_TIZEN -static uint32_t *sm_for_enabled_tag = NULL; -#else const char* k_traceTagsProperty = "debug.atrace.tags.enableflags"; const char* k_traceAppCmdlineProperty = "debug.atrace.app_cmdlines"; -#endif typedef enum { OPT, REQ } requiredness ; +char str_error[256] = ""; + struct TracingCategory { // The name identifying the category. const char* name; @@ -86,21 +84,22 @@ struct TracingCategory { /* Tracing categories */ static const TracingCategory k_categories[] = { #ifdef DEVICE_TYPE_TIZEN - { "none", "None", TTRACE_TAG_NONE, { } }, //do not change "none" option's index - { "gfx", "Graphics", TTRACE_TAG_GRAPHICS, { } }, - { "input", "Input", TTRACE_TAG_INPUT, { } }, - { "view", "View System", TTRACE_TAG_VIEW, { } }, - { "web", "Web", TTRACE_TAG_WEB, { } }, - { "wm", "Window Manager", TTRACE_TAG_WINDOW_MANAGER, { } }, - { "am", "Application Manager", TTRACE_TAG_APPLICATION_MANAGER, { } }, - { "image", "Image", TTRACE_TAG_IMAGE, { } }, - { "audio", "Audio", TTRACE_TAG_AUDIO, { } }, - { "video", "Video", TTRACE_TAG_VIDEO, { } }, - { "camera", "Camera", TTRACE_TAG_CAMERA, { } }, - { "hal", "Hardware Modules", TTRACE_TAG_HAL, { } }, - { "mc", "Multimedia content", TTRACE_TAG_MEDIA_CONTENT, { } }, - { "mdb", "Multimedia database", TTRACE_TAG_MEDIA_DB, { } }, - { "scmirroring","Screen mirroring", TTRACE_TAG_SCREEN_MIRRORING, { } }, + { "none", "None", TTRACE_TAG_NONE, { } }, //do not change "none" option's index + { "gfx", "Graphics", TTRACE_TAG_GRAPHICS, { } }, + { "input", "Input", TTRACE_TAG_INPUT, { } }, + { "view", "View System", TTRACE_TAG_VIEW, { } }, + { "web", "Web", TTRACE_TAG_WEB, { } }, + { "wm", "Window Manager", TTRACE_TAG_WINDOW_MANAGER, { } }, + { "am", "Application Manager", TTRACE_TAG_APPLICATION_MANAGER, { } }, + { "image", "Image", TTRACE_TAG_IMAGE, { } }, + { "audio", "Audio", TTRACE_TAG_AUDIO, { } }, + { "video", "Video", TTRACE_TAG_VIDEO, { } }, + { "camera", "Camera", TTRACE_TAG_CAMERA, { } }, + { "hal", "Hardware Modules", TTRACE_TAG_HAL, { } }, + { "mc", "Multimedia content", TTRACE_TAG_MEDIA_CONTENT, { } }, + { "mdb", "Multimedia database", TTRACE_TAG_MEDIA_DB, { } }, + { "scmirroring", "Screen mirroring", TTRACE_TAG_SCREEN_MIRRORING, { } }, + { "app", "Application", TTRACE_TAG_APP, { } }, #else { "gfx", "Graphics", ATRACE_TAG_GRAPHICS, { } }, { "input", "Input", ATRACE_TAG_INPUT, { } }, @@ -223,7 +222,7 @@ static bool truncateFile(const char* path) int traceFD = creat(path, 0); if (traceFD == -1) { fprintf(stderr, "error truncating %s: %s (%d)\n", path, - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); return false; } @@ -237,7 +236,7 @@ static bool _writeStr(const char* filename, const char* str, int flags) int fd = open(filename, flags); if (fd == -1) { fprintf(stderr, "error opening %s: %s (%d)\n", filename, - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); return false; } @@ -245,7 +244,7 @@ static bool _writeStr(const char* filename, const char* str, int flags) ssize_t len = strlen(str); if (write(fd, str, len) != len) { fprintf(stderr, "error writing to %s: %s (%d)\n", filename, - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); ok = false; } @@ -403,30 +402,25 @@ static bool pokeBinderServices() static bool setTagsProperty(uint64_t tags) { #ifdef DEVICE_TYPE_TIZEN - int shmid; - int skey = 1106; - void *shm_val = (void *) 0; - - if (sm_for_enabled_tag == NULL) { - if(-1 == (shmid = shmget((key_t)skey, sizeof(int), 0666|IPC_CREAT))) - { - fprintf(stderr, "error: shmget() failed\n"); - return false; - } - if((void *)-1 == (shm_val = (void *) shmat(shmid, (void *)0, 0))) - { - fprintf(stderr, "error: shmat() failed\n"); - return false; - } - sm_for_enabled_tag = (uint32_t *)shm_val; + uint64_t *sm_for_enabled_tag = NULL; + int fd = -1; + fd = open(ENABLED_TAG_FILE, O_RDWR | O_CLOEXEC, 0666); + + if(fd < 0){ + fprintf(stderr, "Fail to open enabled_tag file: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno); + return false; } - - if(tags){ - *sm_for_enabled_tag = (uint32_t)tags; - fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag); /* just for debugging */ - } else { - *sm_for_enabled_tag = (uint32_t)0; + sm_for_enabled_tag = (uint64_t*)mmap(NULL, sizeof(uint64_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + if(sm_for_enabled_tag == MAP_FAILED) { + fprintf(stderr, "error: mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error))); + return false; } + *sm_for_enabled_tag = tags; + fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag); + + munmap(sm_for_enabled_tag, sizeof(uint64_t)); + close(fd); #else char buf[64]; snprintf(buf, 64, "%#llx", tags); @@ -474,7 +468,7 @@ static bool verifyKernelTraceFuncs(const char* funcs) int fd = open(k_ftraceFilterPath, O_RDONLY); if (fd == -1) { fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath, - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); return false; } @@ -483,7 +477,7 @@ static bool verifyKernelTraceFuncs(const char* funcs) close(fd); if (n == -1) { fprintf(stderr, "error reading %s: %s (%d)\n", k_ftraceFilterPath, - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); return false; } @@ -649,7 +643,7 @@ static void dumpTrace() int traceFD = open(k_tracePath, O_RDWR); if (traceFD == -1) { fprintf(stderr, "error opening %s: %s (%d)\n", k_tracePath, - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); return; } @@ -690,7 +684,7 @@ static void dumpTrace() result = read(traceFD, in, bufSize); if (result < 0) { fprintf(stderr, "error reading trace: %s (%d)\n", - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); result = Z_STREAM_END; break; } else if (result == 0) { @@ -706,7 +700,7 @@ static void dumpTrace() result = write(STDOUT_FILENO, out, bufSize); if ((size_t)result < bufSize) { fprintf(stderr, "error writing deflated trace: %s (%d)\n", - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); result = Z_STREAM_END; // skip deflate error message zs.avail_out = bufSize; // skip the final write break; @@ -726,7 +720,7 @@ static void dumpTrace() result = write(STDOUT_FILENO, out, bytes); if ((size_t)result < bytes) { fprintf(stderr, "error writing deflated trace: %s (%d)\n", - strerror(errno), errno); + strerror_r(errno, str_error, sizeof(str_error)), errno); } } @@ -741,7 +735,7 @@ static void dumpTrace() ssize_t sent = 0; while ((sent = sendfile(STDOUT_FILENO, traceFD, NULL, 64*1024*1024)) > 0); if (sent == -1) { - fprintf(stderr, "error dumping trace: %s (%d)\n", strerror(errno), + fprintf(stderr, "error dumping trace: %s (%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno); } } @@ -850,6 +844,9 @@ int main(int argc, char **argv) {"async_stop", no_argument, 0, 0 }, {"async_dump", no_argument, 0, 0 }, {"list_categories", no_argument, 0, 0 }, +#ifdef DEVICE_TYPE_TIZEN + {"init_exec", no_argument, 0, 0 }, +#endif { 0, 0, 0, 0 } }; #ifndef DEVICE_TYPE_TIZEN @@ -924,7 +921,11 @@ int main(int argc, char **argv) } else if (!strcmp(long_options[option_index].name, "list_categories")) { listSupportedCategories(); exit(0); - } + } else if (!strcmp(long_options[option_index].name, "init_exec")) { + fprintf(stderr, "init_exec\n"); + setTagsProperty(0); + exit(0); + } #endif break; @@ -943,7 +944,8 @@ int main(int argc, char **argv) } bool ok = true; - ok &= setUpTrace(); + if (!(async && !g_traceOverwrite)) + ok &= setUpTrace(); ok &= startTrace(); if (ok && traceStart) { diff --git a/src/ttrace.c b/src/ttrace.c index f04b2f5..9fbeee9 100644 --- a/src/ttrace.c +++ b/src/ttrace.c @@ -25,12 +25,13 @@ #include "dlog.h" #include "ttrace.h" #include "trace.h" +#include "stdint.h" #define ENABLE_TTRACE #ifdef ENABLE_TTRACE /* In "TTRACE_DEBUG" mode, dlog will print T-trace debug log */ -//#define TTRACE_DEBUG -//#undef TTRACE_DEBUG +#define TTRACE_DEBUG +#undef TTRACE_DEBUG #ifdef TTRACE_DEBUG #define TTRACE_LOG(format, arg...) dlog_print(3, "TTRACE", format, ##arg) @@ -40,82 +41,82 @@ #include #include -#include #include #include -#include -#include +#include #define TRACE_FILE "/sys/kernel/debug/tracing/trace_marker" + #define MAX_TRACE_LEN 1024 #define MAX_LEN 512 #define FD_INITIAL_VALUE -1 #define TRACE_FILE_NOT_EXIST -2 int g_trace_handle_fd = FD_INITIAL_VALUE; -static unsigned int *cur_enabled_tag = NULL; +int g_enabled_tag_fd = FD_INITIAL_VALUE; -static unsigned int traceInit() { - int shmid; - int skey = 1106; - int *sm_for_enabled_tag; +static uint64_t dummy = 0; +uint64_t *cur_enabled_tag = (void *)&dummy; - g_trace_handle_fd = open(TRACE_FILE, O_WRONLY); +static uint64_t traceInit() +{ + uint64_t *sm_for_enabled_tag; - if (g_trace_handle_fd < 0) { + g_trace_handle_fd = open(TRACE_FILE, O_WRONLY); + if (g_trace_handle_fd < 0) { TTRACE_LOG("Fail to open trace file: %s(%d)", strerror(errno), errno); - //in case ftrace debugfs is not mounted, ttrace does not call traceInit() anymore. - if(errno == ENOENT){ + /* in case ftrace debugfs is not mounted, ttrace does not call traceInit() anymore. */ + if (errno == ENOENT) g_trace_handle_fd = TRACE_FILE_NOT_EXIST; - } - set_last_result(TRACE_ERROR_IO_ERROR); + + set_last_result(TRACE_ERROR_IO_ERROR); return 0; - } - if(cur_enabled_tag == NULL) { - //create shared memory for caching enabled tag - if(-1 == (shmid = shmget((key_t)skey, sizeof(unsigned int), 0666|IPC_CREAT))) - { - TTRACE_LOG("Fail to create new segment!(or Fail to get existing segment identifier), %s(%d)", strerror(errno), errno); - goto error; + } + if (cur_enabled_tag == ((void *)&dummy)) { + g_enabled_tag_fd = open(ENABLED_TAG_FILE, O_RDONLY | O_CLOEXEC); + if (g_enabled_tag_fd < 0) { + TTRACE_LOG("Fail to open enabled_tag file: %s(%d)", strerror(errno), errno); + if (errno == ENOENT) + g_enabled_tag_fd = TRACE_FILE_NOT_EXIST; + + return 0; } - if((void *)-1 == (sm_for_enabled_tag = (int *)shmat(shmid, (void *)0, 0))) - { - TTRACE_LOG("Fail to attach the shared memory segment to this proc, %s(%d)", strerror(errno), errno); - goto error; + sm_for_enabled_tag = mmap(NULL, sizeof(uint64_t), PROT_READ, MAP_SHARED, g_enabled_tag_fd, 0); + if (sm_for_enabled_tag == MAP_FAILED) { + TTRACE_LOG("error: mmap() failed(%s)\n", strerror(errno)); + return 0; } - cur_enabled_tag = (unsigned int *)sm_for_enabled_tag; - TTRACE_LOG("attach success: %u %p", *cur_enabled_tag, cur_enabled_tag); + cur_enabled_tag = sm_for_enabled_tag; + TTRACE_LOG("cur_enabled_tag: %u %p", *cur_enabled_tag, cur_enabled_tag); + return *cur_enabled_tag; } else { TTRACE_LOG("traceInit: %u", *cur_enabled_tag); - return *cur_enabled_tag; + return *cur_enabled_tag; } -error: - close(g_trace_handle_fd); - g_trace_handle_fd = FD_INITIAL_VALUE; - return 0; } -static inline unsigned int isTagEnabled(unsigned int cur_tag) { - if (g_trace_handle_fd == TRACE_FILE_NOT_EXIST) +static inline uint64_t isTagEnabled(uint64_t cur_tag) +{ + if (g_trace_handle_fd == TRACE_FILE_NOT_EXIST || g_enabled_tag_fd == TRACE_FILE_NOT_EXIST) return 0; - //if no tag is enabled, trace all tags. - if(cur_tag == TTRACE_TAG_APP) cur_enabled_tag = &cur_tag; - else cur_tag |= TTRACE_TAG_ALWAYS; + /* if no tag is enabled, trace all tags. */ + cur_tag |= TTRACE_TAG_ALWAYS; - if (g_trace_handle_fd < 0 || cur_enabled_tag == NULL){ + if (g_trace_handle_fd < 0 || cur_enabled_tag == ((void *)&dummy)) return (cur_tag & traceInit()); - } + return (cur_tag & *cur_enabled_tag); } -/* +/* * Tracing API for synchronous events: traceBegin()/traceEnd() * - tag: the tracing tag * - name: the event name */ -inline void traceBegin(int tag, const char *name, ...) { - if(isTagEnabled(tag)) { +inline void traceBegin(int tag, const char *name, ...) +{ + if (isTagEnabled(tag)) { char buf[MAX_LEN]; int len = 0; va_list ap; @@ -123,38 +124,42 @@ inline void traceBegin(int tag, const char *name, ...) { TTRACE_LOG("traceBegin:: write >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); va_start(ap, name); len = snprintf(buf, MAX_LEN, "B|%d|", getpid()); - len += vsnprintf(buf+len, MAX_LEN-len, name, ap); + len += vsnprintf(buf + len, MAX_LEN - len, name, ap); va_end(ap); write(g_trace_handle_fd, buf, len); } #ifdef TTRACE_DEBUG - else { - TTRACE_LOG("traceBegin:: disabled tag"); - } + else + TTRACE_LOG("traceBegin:: disabled tag >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); + #endif } -inline void traceEnd(int tag) { - if(isTagEnabled(tag)) { + +inline void traceEnd(int tag) +{ + if (isTagEnabled(tag)) { char end = 'E'; TTRACE_LOG("traceEnd:: write>> tag: %u tag_bit: %u", tag, *cur_enabled_tag); write(g_trace_handle_fd, &end, 1); } #ifdef TTRACE_DEBUG - else { - TTRACE_LOG("traceEnd:: disabled tag"); - } + else + TTRACE_LOG("traceEnd:: disabled tag >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); + #endif } -/* + +/* * Tracing API for asynchronous events: traceAsyncBegin()/traceAsyncEnd() * - tag: the tracing tag * - name: the event name - * - cookie: an unique identifier for distinguishing simultaneous events. + * - cookie: an unique identifier for distinguishing simultaneous events. * The name and cookie used to begin an event must be used to end it. */ -inline void traceAsyncBegin(int tag, int cookie, const char *name, ...) { - if(isTagEnabled(tag)) { +inline void traceAsyncBegin(int tag, int cookie, const char *name, ...) +{ + if (isTagEnabled(tag)) { char buf[MAX_LEN]; int len = 0; va_list ap; @@ -162,71 +167,77 @@ inline void traceAsyncBegin(int tag, int cookie, const char *name, ...) { TTRACE_LOG("traceAsyncBegin:: write >> tag: %u tag_bit: %u cookie: %d", tag, *cur_enabled_tag, cookie); va_start(ap, name); len = snprintf(buf, MAX_LEN, "S|%d|", getpid()); - len += vsnprintf(buf+len, MAX_LEN-len, name, ap); - len += snprintf(buf+len, MAX_LEN-len, "|%d", cookie); + len += vsnprintf(buf + len, MAX_LEN - len, name, ap); + len += snprintf(buf + len, MAX_LEN - len, "|%d", cookie); va_end(ap); write(g_trace_handle_fd, buf, len); } #ifdef TTRACE_DEBUG - else { - TTRACE_LOG("traceAsyncBegin:: disabled tag"); - } + else + TTRACE_LOG("traceAsyncBegin:: disabled tag >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); + #endif } -inline void traceAsyncEnd(int tag, int cookie, const char *name, ...) { - if(isTagEnabled(tag)) { + +inline void traceAsyncEnd(int tag, int cookie, const char *name, ...) +{ + if (isTagEnabled(tag)) { char buf[MAX_LEN]; - int len = 0; + int len = 0; va_list ap; TTRACE_LOG("traceAsyncEnd:: write>> tag: %u tag_bit: %u", tag, *cur_enabled_tag); va_start(ap, name); len = snprintf(buf, MAX_LEN, "F|%d|", getpid()); - len += vsnprintf(buf+len, MAX_LEN-len, name, ap); - len += snprintf(buf+len, MAX_LEN-len, "|%d", cookie); - write(g_trace_handle_fd, buf, len); + len += vsnprintf(buf + len, MAX_LEN - len, name, ap); + len += snprintf(buf + len, MAX_LEN - len, "|%d", cookie); + write(g_trace_handle_fd, buf, len); } #ifdef TTRACE_DEBUG - else { - TTRACE_LOG("traceAsyncEnd:: disabled tag"); - } + else + TTRACE_LOG("traceAsyncEnd:: disabled tag >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); + #endif } -/* +/* * Tracing API for marking occurrences of trace event: traceMark * - tag: the tracing tag * - name: the event name */ -inline void traceMark(int tag, const char *name, ...) { - if(isTagEnabled(tag)) { +/* LCOV_EXCL_START */ +inline void traceMark(int tag, const char *name, ...) +{ + if (isTagEnabled(tag)) { char buf[MAX_LEN], end = 'E'; - int len = 0; - va_list ap; + int len = 0; + va_list ap; - TTRACE_LOG("traceMark:: write >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); + TTRACE_LOG("traceMark:: write >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); va_start(ap, name); - len = snprintf(buf, MAX_LEN, "B|%d|", getpid()); - len +=vsnprintf(buf+len, MAX_LEN-len, name, ap); - va_end(ap); - write(g_trace_handle_fd, buf, len); - write(g_trace_handle_fd, &end, 1); - } + len = snprintf(buf, MAX_LEN, "B|%d|", getpid()); + len += vsnprintf(buf + len, MAX_LEN - len, name, ap); + va_end(ap); + write(g_trace_handle_fd, buf, len); + write(g_trace_handle_fd, &end, 1); + } #ifdef TTRACE_DEBUG - else { - TTRACE_LOG("traceMark:: disabled tag"); - } + else + TTRACE_LOG("traceMark:: disabled tag >> tag: %u tag_bit: %u", tag, *cur_enabled_tag); + #endif } -/* +/* LCOV_EXCL_STOP */ +/* * Tracing API for tracing change of integer counter value: traceCounter * - tag: the tracing tag * - name: the event name * - value: the value tracing */ -inline void traceCounter(int tag, int value, const char* name, ...) { - if(isTagEnabled(tag)) { +inline void traceCounter(int tag, int value, const char *name, ...) +{ + if (isTagEnabled(tag)) { char buf[MAX_LEN]; int len = 0; va_list ap; @@ -234,76 +245,107 @@ inline void traceCounter(int tag, int value, const char* name, ...) { va_start(ap, name); len = snprintf(buf, MAX_LEN, "C|%d|", getpid()); - len += vsnprintf(buf+len, MAX_LEN-len, name, ap); - len += snprintf(buf+len, MAX_LEN-len, "|%d", value); + len += vsnprintf(buf + len, MAX_LEN - len, name, ap); + len += snprintf(buf + len, MAX_LEN - len, "|%d", value); write(g_trace_handle_fd, buf, len); } #ifdef TTRACE_DEBUG - else { + else TTRACE_LOG("traceCounter:: disabled tag"); - } + #endif } -/* +/* * Tracing API for Native Application * - tag: the tracing tag * - name: the event name * - value: the value tracing */ -inline void trace_begin(const char *name, ...) { +inline void trace_begin(const char *name, ...) +{ va_list ap; char v_name[MAX_LEN]; va_start(ap, name); vsnprintf(v_name, MAX_LEN, name, ap); - + traceBegin(TTRACE_TAG_APP, v_name); va_end(ap); } -inline void trace_end() { + +inline void trace_end() +{ traceEnd(TTRACE_TAG_APP); } -inline void trace_async_begin(int cookie, const char *name, ...) { + +inline void trace_async_begin(int cookie, const char *name, ...) +{ va_list ap; char v_name[MAX_LEN]; va_start(ap, name); vsnprintf(v_name, MAX_LEN, name, ap); - + traceAsyncBegin(TTRACE_TAG_APP, cookie, v_name); va_end(ap); } -inline void trace_async_end(int cookie, const char *name, ...) { + +inline void trace_async_end(int cookie, const char *name, ...) +{ va_list ap; char v_name[MAX_LEN]; va_start(ap, name); vsnprintf(v_name, MAX_LEN, name, ap); - + traceAsyncEnd(TTRACE_TAG_APP, cookie, v_name); va_end(ap); } -inline void trace_update_counter(int value, const char *name, ...) { + +inline void trace_update_counter(int value, const char *name, ...) +{ va_list ap; char v_name[MAX_LEN]; va_start(ap, name); vsnprintf(v_name, MAX_LEN, name, ap); - + traceCounter(TTRACE_TAG_APP, value, v_name); va_end(ap); } #else -inline void traceBegin(int tag, const char *name, ...) {;} -inline void traceEnd(int tag) {;} -inline void traceAsyncBegin(int tag, int cookie, const char *name, ...) {;} -inline void traceAsyncEnd(int tag, int cookie, const char *name, ...) {;} -inline void traceMark(int tag, const char *name, ...) {;} -inline void traceCounter(int tag, int value, const char *name, ...) {;} -inline void trace_begin(const char *name, ...) {;} -inline void trace_end() {;} -inline void trace_async_begin(int cookie, const char *name, ...) {;} -inline void trace_async_end(int cookie, const char *name, ...) {;} -inline void trace_update_counter(int value, const char *name, ...) {;} +inline void traceBegin(int tag, const char *name, ...) +{; } + +inline void traceEnd(int tag) +{; } + +inline void traceAsyncBegin(int tag, int cookie, const char *name, ...) +{; } + +inline void traceAsyncEnd(int tag, int cookie, const char *name, ...) +{; } + +inline void traceMark(int tag, const char *name, ...) +{; } + +inline void traceCounter(int tag, int value, const char *name, ...) +{; } + +inline void trace_begin(const char *name, ...) +{; } + +inline void trace_end() +{; } + +inline void trace_async_begin(int cookie, const char *name, ...) +{; } + +inline void trace_async_end(int cookie, const char *name, ...) +{; } + +inline void trace_update_counter(int value, const char *name, ...) +{; } #endif + diff --git a/ttrace.manifest b/ttrace.manifest index 3756694..1ae051a 100644 --- a/ttrace.manifest +++ b/ttrace.manifest @@ -2,26 +2,14 @@ - + - - - - - - - - - - - - - - - - + + + + -- 2.7.4