resolve smack permission issuses and update ttrace to the latest version 50/47950/2
authorEunji, Lee <eunjieji.lee@samsung.com>
Thu, 10 Sep 2015 08:10:27 +0000 (17:10 +0900)
committerEunji, Lee <eunjieji.lee@samsung.com>
Thu, 10 Sep 2015 09:08:47 +0000 (18:08 +0900)
* remarkable changes
- creates ttrace_tag file when boot-up the device
- provides static lib. version of ttrace library
- dynamically generates ttrace.h

Change-Id: I2e08d234e96e4d921e0a52d403fed34e21175105
Signed-off-by: Eunji, Lee <eunjieji.lee@samsung.com>
CMakeLists.txt
include/TTraceWrapper.h
packaging/atrace-bootup.sh [new file with mode: 0755]
packaging/exec-ttrace-marker
packaging/ttrace.spec
src/TTraceWrapper.cpp
src/atrace/atrace.cpp
src/trace.c [new file with mode: 0755]
src/ttrace.c
ttrace-static.pc.in [new file with mode: 0644]
ttrace.h.in [new file with mode: 0755]

index 7bd06ce9fddcd167ccf283cc70e8a4acc79bbdef..438b5b8a0eebb4920fd7fabdd865762153c4f461 100755 (executable)
@@ -9,6 +9,7 @@ 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}")
@@ -16,8 +17,19 @@ SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS}")
 
 SET(CMAKE_SKIP_BUILD_RPATH TRUE)
 
+# Generate ttrace.h 
+SET(TTRACE_H_IN ttrace.h.in)
+IF("${TTRACE_PROFILE}" STREQUAL "tv")
+       SET(TTRACE_PROFILE_TV ON)
+ELSEIF("${TTRACE_PROFILE}" STREQUAL "wearable")
+       SET(TTRACE_PROFILE_WERABLE ON)
+ELSE()
+       SET(TTRACE_PROFILE_MOBILE ON)
+ENDIF()
+configure_file(${TTRACE_H_IN} "include/ttrace.h")
+
 #################################################################
-# Build ttrace Library
+# Build ttrace Library (Shared)
 # ------------------------------
 SET(TTRACE "ttrace")
 SET(SRCS_ttrace src/ttrace.c
@@ -27,12 +39,14 @@ SET(HEADERS_ttrace ttrace.h
                    trace.h)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkg_ttrace REQUIRED dlog capi-base-common)   
+pkg_check_modules(pkg_ttrace REQUIRED dlog capi-base-common)
 FOREACH(flag ${pkg_ttrace_CFLAGS})
        SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} ${flag}")
 ENDFOREACH(flag)
 
-ADD_LIBRARY(${TTRACE} SHARED ${SRCS_ttrace})
+ADD_LIBRARY(${TTRACE} SHARED ${SRCS_ttrace}
+                             src/trace.c
+                             )
 SET_TARGET_PROPERTIES(${TTRACE} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${TTRACE} PROPERTIES VERSION ${VERSION})
 SET_TARGET_PROPERTIES(${TTRACE} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_common})
@@ -42,10 +56,25 @@ CONFIGURE_FILE(${TTRACE}.pc.in ${TTRACE}.pc @ONLY)
 
 INSTALL(TARGETS ${TTRACE} DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TTRACE}.pc DESTINATION ${LIBDIR}/pkgconfig)
+
+#################################################################
+# Build ttrace Library (Static)
+# ------------------------------
+SET(TTRACE_STATIC "ttrace-static")
+
+ADD_LIBRARY(${TTRACE_STATIC} STATIC ${SRCS_ttrace})
+SET_TARGET_PROPERTIES(${TTRACE_STATIC} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS_common} -fpic")
+SET_TARGET_PROPERTIES(${TTRACE_STATIC} PROPERTIES OUTPUT_NAME ttrace)
+
+CONFIGURE_FILE(${TTRACE_STATIC}.pc.in ${TTRACE_STATIC}.pc @ONLY) 
+
+INSTALL(TARGETS ${TTRACE_STATIC} DESTINATION ${LIBDIR})
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TTRACE_STATIC}.pc DESTINATION ${LIBDIR}/pkgconfig)
+TARGET_LINK_LIBRARIES(${TTRACE_STATIC} ${pkg_ttrace_LDFLAGS} "-ldl")
+
 FOREACH(hfile ${HEADERS_ttrace})
        INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION ${INCLUDEDIR})
 ENDFOREACH(hfile)
-
 #################################################################
 # Build atrace Library (KK)
 # ------------------------------
index 43ece64b2bbeba6498846b172e54f2a466a1714d..04dcb96f6e8d36ad12aef74ade497bb94a4ade47 100644 (file)
 
 #include <ttrace.h>
 #include <stdarg.h>
+#include <stdint.h>
+
 class TTraceWrapper {
        private:
-               int tag;
+               uint64_t tag;
        public:
-               TTraceWrapper(int tags, const char* label, ...);
+               TTraceWrapper(uint64_t tags, const char* label, ...);
                ~TTraceWrapper();
 };
 
diff --git a/packaging/atrace-bootup.sh b/packaging/atrace-bootup.sh
new file mode 100755 (executable)
index 0000000..8e45f2a
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+SCRIPT=`basename ${BASH_SOURCE[0]}`
+
+#Help function
+function HELP {
+  echo -e \\n"Help documentation for ${SCRIPT}."\\n
+  echo -e "Basic usage: $SCRIPT file.ext"\\n
+  echo -e "-h  --Displays this help message. No further functions are performed."\\n
+  exit 1
+}
+
+CONF="/etc/ttrace.conf"
+
+SPACE=" "
+COMMAND="atrace --async_start --append"
+DEFTAGS=""
+
+NUMARGS=$#
+if [ $NUMARGS -eq 0 ]; then
+  COMMAND=$COMMAND$SPACE$DEFTAGS
+else
+       shift $((OPTIND-1))  #This tells getopts to move on to the next argument.
+       while [ $# -ne 0 ]; do
+               PARAM=$1
+               COMMAND=$COMMAND$SPACE$PARAM
+               shift
+       done
+fi
+
+echo "COMMAND is: $COMMAND"
+echo "$COMMAND" > "$CONF"
+
+sync
+sleep 1
+reboot
+
+exit 0
index 0acd9c008a0b6542a5f3a8bca5ce68b3a2a134d0..8b3b87a207682febb7904f37e709b5b3f9e4b032 100755 (executable)
@@ -1,49 +1,94 @@
 #!/bin/bash
 
-conf="/etc/ttrace/ttrace.conf"
+tag="/tmp/ttrace_tag"
+conf="/etc/ttrace.conf"
 change_permission="--update"
 
-chmod 0222 /sys/kernel/debug/tracing/trace_marker
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/trace_marker
+function init_perms(){
+    chown root:users /sys/kernel/debug/tracing/trace_clock
+    chown root:users /sys/kernel/debug/tracing/buffer_size_kb
+    chown root:users /sys/kernel/debug/tracing/options/overwrite
+    chown root:users /sys/kernel/debug/tracing/options/print-tgid
+    chown root:users /sys/kernel/debug/tracing/events/sched/sched_switch/enable
+    chown root:users /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
+    chown root:users /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
+    chown root:users /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
+    chown root:users /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
+    chown root:users /sys/kernel/debug/tracing/events/power/cpu_idle/enable
+    chown root:users /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
+    chown root:users /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
+    chown root:users /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
+    chown root:users /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
+    chown root:users /sys/kernel/debug/tracing/events/mmc/enable
+    chown root:users /sys/kernel/debug/tracing/events/sync/enable
+    chown root:users /sys/kernel/debug/tracing/events/workqueue/enable
+    chown root:users /sys/kernel/debug/tracing/current_tracer
+    chown root:users /sys/kernel/debug/tracing/tracing_on
+    chown root:users /sys/kernel/debug/tracing/trace
+    chown root:users /usr/bin/atrace
+    chown root:users /tmp/ttrace_tag
 
-chown root:developer /sys/kernel/debug/tracing/trace_clock
-chown root:developer /sys/kernel/debug/tracing/buffer_size_kb
-chown root:developer /sys/kernel/debug/tracing/options/overwrite
-chown root:developer /sys/kernel/debug/tracing/options/print-tgid
-chown root:developer /sys/kernel/debug/tracing/events/sched/sched_switch/enable
-chown root:developer /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
-chown root:developer /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
-chown root:developer /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
-#chown root:developer /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
-chown root:developer /sys/kernel/debug/tracing/tracing_on
-chown root:developer /sys/kernel/debug/tracing/trace
-chown root:developer /usr/bin/atrace
+    chmod 0664 /sys/kernel/debug/tracing/trace_clock
+    chmod 0664 /sys/kernel/debug/tracing/buffer_size_kb
+    chmod 0664 /sys/kernel/debug/tracing/options/overwrite
+    chmod 0664 /sys/kernel/debug/tracing/options/print-tgid
+    chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_switch/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/power/cpu_idle/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/mmc/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/sync/enable
+    chmod 0664 /sys/kernel/debug/tracing/events/workqueue/enable
+    chmod 0664 /sys/kernel/debug/tracing/current_tracer
+    chmod 0222 /sys/kernel/debug/tracing/trace_marker
+    chmod 0664 /sys/kernel/debug/tracing/tracing_on
+    chmod 0660 /sys/kernel/debug/tracing/trace
+    chmod 0755 /sys/kernel/debug
+    chmod 0755 /usr/bin/atrace
+    chmod 0664 /tmp/ttrace_tag
 
-chmod 0664 /sys/kernel/debug/tracing/trace_clock
-chmod 0664 /sys/kernel/debug/tracing/buffer_size_kb
-chmod 0664 /sys/kernel/debug/tracing/options/overwrite
-chmod 0664 /sys/kernel/debug/tracing/options/print-tgid
-chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_switch/enable
-chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
-chmod 0664 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
-chmod 0664 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
-#chmod 0664 /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
-chmod 0664 /sys/kernel/debug/tracing/tracing_on
-chmod 0660 /sys/kernel/debug/tracing/trace
-chmod 0755 /sys/kernel/debug
-chmod 0755 /usr/bin/atrace
+    chsmack -a '*' /sys/kernel/debug/tracing/trace_clock
+    chsmack -a '*' /sys/kernel/debug/tracing/buffer_size_kb
+    chsmack -a '*' /sys/kernel/debug/tracing/options/overwrite
+    chsmack -a '*' /sys/kernel/debug/tracing/options/print-tgid
+    chsmack -a '*' /sys/kernel/debug/tracing/events/sched/sched_switch/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/power/cpu_idle/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/mmc/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/sync/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/events/workqueue/enable
+    chsmack -a '*' /sys/kernel/debug/tracing/current_tracer
+    chsmack -a '*' /sys/kernel/debug/tracing/trace_marker
+    chsmack -a '*' /sys/kernel/debug/tracing/tracing_on
+    chsmack -a '*' /sys/kernel/debug/tracing/trace
+    chsmack -a '*' /tmp/ttrace_tag
+}
 
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/trace_clock
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/buffer_size_kb
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/options/overwrite
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/options/print-tgid
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/events/sched/sched_switch/enable
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
-attr -S -s SMACK64 -V '*' /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
-#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
+
+if [ -e "$tag" ]
+then
+       echo "$tag was created already!!!"
+       exit 0
+else
+       # create ttrace tag 
+       atrace --init_exec
+
+       # initialize permission, smack rule for ttrace_tag, sysfs nodes
+       init_perms
+fi
 
 if [ -e "$conf" ]
 then
@@ -55,15 +100,11 @@ then
                echo "File name is - $conf"
                echo "Options is - $options"
        done < "$conf"
-
-       change-booting-mode.sh "$change_permission"
-       $options > "/tmp/trace"
+       # below script is not available on TV profile
+       change-booting-mode.sh "$change_permission" 
+       $options
        rm "$conf"
 else
        echo "$conf was NOT found!!!"
-       atrace --init_exec
-       echo 0 > "/sys/kernel/debug/tracing/trace"
-       echo 0 > "/sys/kernel/debug/tracing/tracing_on"
 fi
-
 exit 0
index 197b1bcbac9941ad10e4631916c84737532ef058..48077448583a2e0f3c1bee29356ec4605d770e28 100755 (executable)
@@ -7,13 +7,28 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 SOURCE101:     packaging/exec-ttrace-marker
 SOURCE102:     packaging/ttrace-marker.service
-SOURCE103:     packaging/ttrace_tag
+SOURCE103:     packaging/atrace-bootup.sh
 
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(zlib)
 BuildRequires: pkgconfig(capi-base-common)
 BuildRequires: cmake
 
+%define keepstatic 1
+
+%define TTRACE_PROFILE none
+%if "%{?tizen_profile_name}" == "mobile"
+%define TTRACE_PROFILE mobile
+%else
+%if "%{?tizen_profile_name}" == "tv"
+%define TTRACE_PROFILE tv
+%else
+%if "%{?tizen_profile_name}" == "wearable"
+%define TTRACE_PROFILE wearable
+%endif
+%endif
+%endif
+
 %description
 T-trace library
 
@@ -31,22 +46,19 @@ T-trace library devel
 %build
 export CFLAGS="$CFLAGS -g -Wall -std=gnu99"
 export CXXFLAGS="$CXXFLAGS -std=c++0x -fPIE -pie"
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DBUILD_PKGTYPE=rpm -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir}
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir}
 make %{?jobs:-j%jobs}
 
 %install
 rm -rf %{buildroot}
-
 %make_install
 install -d %{buildroot}%{_unitdir}/ttrace-marker.service.wants
 install -m0644 %{SOURCE102} %{buildroot}%{_unitdir}
 mkdir -p %{buildroot}%{_bindir}
 cp %{SOURCE101} %{buildroot}%{_bindir}
+cp %{SOURCE103} %{buildroot}%{_bindir}
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
-mkdir -p %{buildroot}/etc/ttrace
-cp %{SOURCE103} %{buildroot}/etc/ttrace
-
 %install_service sys-kernel-debug.mount.wants ttrace-marker.service
 
 %post -p /sbin/ldconfig
@@ -59,11 +71,11 @@ cp %{SOURCE103} %{buildroot}/etc/ttrace
 %{_libdir}/libttrace.so.*
 %{_unitdir}/ttrace-marker.service
 %{_unitdir}/ttrace-marker.service.wants/
-%attr(755,root,root) %{_bindir}/atrace
-%attr(755,root,root) %{_bindir}/atrace-1.1
+%attr(755,root,developer) %{_bindir}/atrace
+%attr(755,root,developer) %{_bindir}/atrace-1.1
 %attr(755,root,root) %{_bindir}/exec-ttrace-marker
-%attr(664,root,root) /etc/ttrace/ttrace_tag
 %{_unitdir}/sys-kernel-debug.mount.wants/ttrace-marker.service
+%attr(755,root,root) %{_bindir}/atrace-bootup.sh
 /usr/share/license/%{name}
 
 %files devel
@@ -72,5 +84,7 @@ cp %{SOURCE103} %{buildroot}/etc/ttrace
 %{_includedir}/TTraceWrapper.h
 %{_includedir}/trace.h
 %{_libdir}/libttrace.so
+%{_libdir}/libttrace.a
 %{_libdir}/pkgconfig/ttrace.pc
+%{_libdir}/pkgconfig/ttrace-static.pc
 %{_libdir}/pkgconfig/atrace.pc
index 100aacba011840be800a93998b05ceaa88dc51b6..c926095bfcb9a349e2872fba57b6d05ac0e35d72 100644 (file)
@@ -18,7 +18,7 @@
 #include "TTraceWrapper.h"
 #include <stdio.h>
 
-TTraceWrapper::TTraceWrapper(int tags, const char* label, ...) {
+TTraceWrapper::TTraceWrapper(uint64_t tags, const char* label, ...) {
        va_list ap;
        char fmtd_label[MAX_LEN];
 
index bef8226c63527e1ee2337d8888256ef38caa0934..129e72060bb123295c338279ba79686fa51f667c 100755 (executable)
@@ -36,6 +36,7 @@
 #define TTRACE_TAG_NONE                9999
 #define TAG_NONE_IDX           0
 
+#define BACKUP_TRACE   "/tmp/trace.backup"
 #else
 #include <binder/IBinder.h>
 #include <binder/IServiceManager.h>
@@ -100,7 +101,7 @@ static const TracingCategory k_categories[] = {
     { "mdb",         "Multimedia database", TTRACE_TAG_MEDIA_DB, { } },
     { "scmirroring", "Screen mirroring",    TTRACE_TAG_SCREEN_MIRRORING, { } },
     { "app",         "Application",         TTRACE_TAG_APP, { } },
-#else
+#else          // Android tags
     { "gfx",        "Graphics",         ATRACE_TAG_GRAPHICS, { } },
     { "input",      "Input",            ATRACE_TAG_INPUT, { } },
     { "view",       "View System",      ATRACE_TAG_VIEW, { } },
@@ -114,7 +115,7 @@ static const TracingCategory k_categories[] = {
     { "res",        "Resource Loading", ATRACE_TAG_RESOURCES, { } },
     { "dalvik",     "Dalvik VM",        ATRACE_TAG_DALVIK, { } },
     { "rs",         "RenderScript",     ATRACE_TAG_RS, { } },
-#endif
+#endif // Linux kernel tags
     { "sched",      "CPU Scheduling",   0, {
         { REQ,      "/sys/kernel/debug/tracing/events/sched/sched_switch/enable" },
         { REQ,      "/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable" },
@@ -147,6 +148,10 @@ static const TracingCategory k_categories[] = {
     { "workq",      "Kernel Workqueues", 0, {
         { REQ,      "/sys/kernel/debug/tracing/events/workqueue/enable" },
     } },
+#ifdef TTRACE_PROFILE_MOBILE
+#elif defined TTRACE_PROFILE_TV
+#elif defined TTRACE_PROFILE_WEARABLE
+#endif
 };
 
 /* Command line options */
@@ -163,6 +168,12 @@ static const char* g_debugAppCmdLine = "";
 static bool g_traceAborted = false;
 static bool g_categoryEnables[NELEM(k_categories)] = {};
 
+#ifdef DEVICE_TYPE_TIZEN
+static bool g_init_exec = false;
+static bool g_append_trace = false;
+static bool g_backup_trace = false;
+#endif
+
 /* Sys file paths */
 static const char* k_traceClockPath =
     "/sys/kernel/debug/tracing/trace_clock";
@@ -404,7 +415,7 @@ static bool setTagsProperty(uint64_t tags)
 #ifdef DEVICE_TYPE_TIZEN
        uint64_t *sm_for_enabled_tag = NULL;
        int fd = -1;
-       fd = open(ENABLED_TAG_FILE, O_RDWR | O_CLOEXEC, 0666);          
+       fd = open(ENABLED_TAG_FILE, O_CREAT | 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);
@@ -414,10 +425,22 @@ static bool setTagsProperty(uint64_t tags)
 
        if(sm_for_enabled_tag == MAP_FAILED) {
                fprintf(stderr, "error: mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
+               close(fd);
                return false;
        }
+       if(g_init_exec) {
+               if (ftruncate(fd, sizeof(uint64_t)) < 0) {
+                           fprintf(stderr, "error: ftruncate() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
+                           munmap(sm_for_enabled_tag, sizeof(uint64_t));
+                           close(fd);
+                       return false;
+               }
+               memset(sm_for_enabled_tag, 0, sizeof(uint64_t));
+       }
        *sm_for_enabled_tag = tags;
-       fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag);
+       // For debug
+       // fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag);
+       //
 
        munmap(sm_for_enabled_tag, sizeof(uint64_t));
        close(fd);
@@ -510,6 +533,7 @@ static bool verifyKernelTraceFuncs(const char* funcs)
 static bool setKernelTraceFuncs(const char* funcs)
 {
     bool ok = true;
+    char *ptr[2];
 
     if (funcs == NULL || funcs[0] == '\0') {
         // Disable kernel function tracing.
@@ -530,10 +554,10 @@ static bool setKernelTraceFuncs(const char* funcs)
         // Set the requested filter functions.
         ok &= truncateFile(k_ftraceFilterPath);
         char* myFuncs = strdup(funcs);
-        char* func = strtok(myFuncs, ",");
+        char* func = strtok_r(myFuncs, ",", &ptr[0]);
         while (func) {
             ok &= appendStr(k_ftraceFilterPath, func);
-            func = strtok(NULL, ",");
+            func = strtok_r(NULL, ",", &ptr[1]);
         }
         free(myFuncs);
 
@@ -554,10 +578,19 @@ static bool setUpTrace()
 
     // Set up the tracing options.
     ok &= setTraceOverwriteEnable(g_traceOverwrite);
+#ifdef DEVICE_TYPE_TIZEN
+    if(!g_append_trace) {
+       ok &= setTraceBufferSizeKB(g_traceBufferSizeKB);
+       ok &= setGlobalClockEnable(true);
+        ok &= setKernelTraceFuncs(g_kernelTraceFuncs);
+    }
+#else
     ok &= setTraceBufferSizeKB(g_traceBufferSizeKB);
     ok &= setGlobalClockEnable(true);
-    ok &= setPrintTgidEnableIfPresent(true);
     ok &= setKernelTraceFuncs(g_kernelTraceFuncs);
+#endif
+    ok &= setPrintTgidEnableIfPresent(true);
+
 
     // Set up the tags property.
     uint64_t tags = 0;
@@ -638,12 +671,36 @@ static void stopTrace()
 }
 
 // Read the current kernel trace and write it to stdout.
+#ifdef DEVICE_TYPE_TIZEN
+static void dumpTrace(bool startup)
+{      
+    int backup_fd = -1;
+    int traceFD = open(k_tracePath, O_RDWR);
+
+    if(startup) {
+       backup_fd = open(BACKUP_TRACE, O_CREAT|O_RDWR|O_TRUNC, 0666);
+
+       if (backup_fd == -1) {
+               fprintf(stderr, "error opening %s: %s (%d)\n", BACKUP_TRACE,
+               strerror_r(errno, str_error, sizeof(str_error)), errno);
+               if (traceFD > -1)
+                       close(traceFD);
+               return;
+       }
+    }
+
+#else
 static void dumpTrace()
 {
     int traceFD = open(k_tracePath, O_RDWR);
+#endif
     if (traceFD == -1) {
         fprintf(stderr, "error opening %s: %s (%d)\n", k_tracePath,
                 strerror_r(errno, str_error, sizeof(str_error)), errno);
+#ifdef DEVICE_TYPE_TIZEN
+        if (backup_fd > -1)
+               close(backup_fd);
+#endif
         return;
     }
 
@@ -657,6 +714,10 @@ static void dumpTrace()
         if (result != Z_OK) {
             fprintf(stderr, "error initializing zlib: %d\n", result);
             close(traceFD);
+#ifdef DEVICE_TYPE_TIZEN
+            if (backup_fd > -1)
+               close(backup_fd);
+#endif
             return;
         }
 
@@ -670,6 +731,10 @@ static void dumpTrace()
                                        if (out != NULL)
                                                        free(out);
                close(traceFD);
+#ifdef DEVICE_TYPE_TIZEN
+               if (backup_fd > -1)
+                               close(backup_fd);
+#endif
                return;
                                }
         flush = Z_NO_FLUSH;
@@ -697,7 +762,12 @@ static void dumpTrace()
 
             if (zs.avail_out == 0) {
                 // Need to write the output.
+#ifdef DEVICE_TYPE_TIZEN
+               if(startup)     result = write(backup_fd, out, bufSize);
+               else            result = write(STDOUT_FILENO, out, bufSize);
+#else
                 result = write(STDOUT_FILENO, out, bufSize);
+#endif
                 if ((size_t)result < bufSize) {
                     fprintf(stderr, "error writing deflated trace: %s (%d)\n",
                             strerror_r(errno, str_error, sizeof(str_error)), errno);
@@ -717,7 +787,12 @@ static void dumpTrace()
 
         if (zs.avail_out < bufSize) {
             size_t bytes = bufSize - zs.avail_out;
+#ifdef DEVICE_TYPE_TIZEN
+           if(startup)         result = write(backup_fd, out, bytes);
+           else                result = write(STDOUT_FILENO, out, bytes);
+#else
             result = write(STDOUT_FILENO, out, bytes);
+#endif
             if ((size_t)result < bytes) {
                 fprintf(stderr, "error writing deflated trace: %s (%d)\n",
                         strerror_r(errno, str_error, sizeof(str_error)), errno);
@@ -733,13 +808,24 @@ static void dumpTrace()
         free(out);
     } else {
                ssize_t sent = 0;
+#ifdef DEVICE_TYPE_TIZEN 
+               if (startup) 
+                       while ((sent = sendfile(backup_fd, traceFD, NULL, 64*1024*1024)) > 0);
+               else 
+                       while ((sent = sendfile(STDOUT_FILENO, traceFD, NULL, 64*1024*1024)) > 0);
+#else
                while ((sent = sendfile(STDOUT_FILENO, traceFD, NULL, 64*1024*1024)) > 0);
+#endif
                if (sent == -1) {
                        fprintf(stderr, "error dumping trace: %s (%d)\n", strerror_r(errno, str_error, sizeof(str_error)),
                                        errno);
                }
     }
 
+#ifdef DEVICE_TYPE_TIZEN
+       if (backup_fd > -1)
+               close(backup_fd);
+#endif
     close(traceFD);
 }
 
@@ -819,6 +905,10 @@ static void showHelp(const char *cmd)
                     "  --async_dump    dump the current contents of circular trace buffer\n"
                     "  --async_stop    stop tracing and dump the current contents of circular\n"
                     "                    trace buffer\n"
+#ifdef DEVICE_TYPE_TIZEN
+                    "  --append        append traces to the existing traces. do not clear the trace buffer\n"
+                   "  --backup        back up the existing traces to /tmp/trace.backup and then clear the trace buffer\n"
+#endif
                     "  --list_categories\n"
                     "                  list the available tracing categories\n"
             );
@@ -845,12 +935,14 @@ int main(int argc, char **argv)
             {"async_dump",      no_argument, 0,  0 },
             {"list_categories", no_argument, 0,  0 },
 #ifdef DEVICE_TYPE_TIZEN
-            {"init_exec",              no_argument, 0,  0 },
+            {"init_exec",      no_argument, 0,  0 },
+            {"append",         no_argument, 0,  0 },
+            {"backup",         no_argument, 0,  0 },
 #endif
             {           0,                0, 0,  0 }
         };
 #ifndef DEVICE_TYPE_TIZEN
-        ret = getopt_long(argc, argv, "a:b:ck:ns:t:z",
+        ret = getopt_long(argc, argv, "a:b:ck:ns:t:z:p",
                           long_options, &option_index);
 #else
                ret = getopt_long(argc, argv, "b:ck:ns:t:z",
@@ -922,10 +1014,17 @@ int main(int argc, char **argv)
                     listSupportedCategories();
                     exit(0);
                 } else if (!strcmp(long_options[option_index].name, "init_exec")) {
-                                       fprintf(stderr, "init_exec\n");
-                                       setTagsProperty(0);
-                                       exit(0);
-                               }
+                    fprintf(stderr, "init_exec\n");
+                    g_init_exec = true;
+                    setTagsProperty(0);
+                    exit(0);
+               } else if (!strcmp(long_options[option_index].name, "append")) {
+                    g_append_trace = true;
+               } else if (!strcmp(long_options[option_index].name, "backup")) {
+                    g_backup_trace = true;
+               }
+#else
+            case 0:
 #endif
             break;
 
@@ -944,12 +1043,22 @@ int main(int argc, char **argv)
     }
 
     bool ok = true;
-    if (!(async && !g_traceOverwrite))
+#ifdef DEVICE_TYPE_TIZEN
+    if(traceStart && g_backup_trace) {
+//before start tracing by atrace, backup existig traces
+       stopTrace();
+       dumpTrace(true);
+    }
+#endif
+    if (!(async && !g_traceOverwrite)) {
            ok &= setUpTrace();
+    }
     ok &= startTrace();
 
     if (ok && traceStart) {
-        printf("capturing trace...");
+               // For debug
+        // printf("capturing trace...");
+        //
         fflush(stdout);
 
         // We clear the trace after starting it because tracing gets enabled for
@@ -957,7 +1066,12 @@ int main(int argc, char **argv)
         // contain entries from only one CPU can cause "begin" entries without a
         // matching "end" entry to show up if a task gets migrated from one CPU to
         // another.
-        ok = clearTrace();
+       if(!g_append_trace) {
+               // For debug
+               // printf("\nclear the trace\n");
+               //
+               ok = clearTrace();
+       }
 
         if (ok && !async) {
             // Sleep to allow the trace to be captured.
@@ -980,7 +1094,11 @@ int main(int argc, char **argv)
         if (!g_traceAborted) {
             printf(" done\nTRACE:\n");
             fflush(stdout);
+#ifdef DEVICE_TYPE_TIZEN
+           dumpTrace(false);
+#else
             dumpTrace();
+#endif
         } else {
             printf("\ntrace aborted.\n");
             fflush(stdout);
diff --git a/src/trace.c b/src/trace.c
new file mode 100755 (executable)
index 0000000..dced1e4
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * =============================================================================
+ *
+ * SLP
+ * Copyright (c) 2012 Samsung Electronics, Inc.
+ * All rights reserved.
+ *
+ * This software is a confidential and proprietary information
+ * of Samsung Electronics, Inc. ("Confidential Information").  You
+ * shall not disclose such Confidential Information and shall use
+ * it only in accordance with the terms of the license agreement
+ * you entered into with Samsung Electronics.
+ *
+ * @file:  trace.c
+ * @brief:  trace public api
+ * @author:  @samsung.com
+ * @created:  Thursday 27 September 2012 08:05:23  KST
+ * @compiler:  gcc
+ * @company:  Samsung
+ * @version:  0.1
+ * @revision:  none
+ *
+ * =============================================================================
+ */
+#include "ttrace.h"
+#include "stdarg.h"
+
+#define ENABLE_TTRACE
+#define MAX_LEN 512
+
+#ifdef ENABLE_TTRACE
+/*
+ * Tracing API for Native Application
+ * - tag: the tracing tag
+ * - name: the event name
+ * - value: the value tracing
+ */
+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);
+}
+
+void trace_end()
+{
+       traceEnd(TTRACE_TAG_APP);
+}
+
+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);
+}
+
+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);
+}
+
+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
+void trace_begin(const char *name, ...)
+{; }
+
+void trace_end()
+{; }
+
+void trace_async_begin(int cookie, const char *name, ...)
+{; }
+
+void trace_async_end(int cookie, const char *name, ...)
+{; }
+
+void trace_update_counter(int value, const char *name, ...)
+{; }
+#endif
index 9fbeee9f62a514166d0d28eb34378c6a20c9a757..ec009496d74e618ce6acece2bd2d41b6a191b3d4 100644 (file)
  *
  * =============================================================================
  */
-#include "dlog.h"
 #include "ttrace.h"
 #include "trace.h"
-#include "stdint.h"
+#include "dlog.h"
+
 #define ENABLE_TTRACE
 
 #ifdef ENABLE_TTRACE
@@ -114,7 +114,7 @@ static inline uint64_t isTagEnabled(uint64_t cur_tag)
  * - tag: the tracing tag
  * - name: the event name
  */
-inline void traceBegin(int tag, const char *name, ...)
+void traceBegin(uint64_t tag, const char *name, ...)
 {
        if (isTagEnabled(tag)) {
                char buf[MAX_LEN];
@@ -136,7 +136,7 @@ inline void traceBegin(int tag, const char *name, ...)
 
 }
 
-inline void traceEnd(int tag)
+void traceEnd(uint64_t tag)
 {
        if (isTagEnabled(tag)) {
                char end = 'E';
@@ -157,7 +157,7 @@ inline void traceEnd(int tag)
  * - 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, ...)
+void traceAsyncBegin(uint64_t tag, int cookie, const char *name, ...)
 {
        if (isTagEnabled(tag)) {
                char buf[MAX_LEN];
@@ -179,7 +179,7 @@ inline void traceAsyncBegin(int tag, int cookie, const char *name, ...)
 #endif
 }
 
-inline void traceAsyncEnd(int tag, int cookie, const char *name, ...)
+void traceAsyncEnd(uint64_t tag, int cookie, const char *name, ...)
 {
        if (isTagEnabled(tag)) {
                char buf[MAX_LEN];
@@ -191,6 +191,7 @@ inline void traceAsyncEnd(int tag, int cookie, const char *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);
+               va_end(ap);
                write(g_trace_handle_fd, buf, len);
        }
 #ifdef TTRACE_DEBUG
@@ -206,7 +207,7 @@ inline void traceAsyncEnd(int tag, int cookie, const char *name, ...)
  * - name: the event name
  */
 /* LCOV_EXCL_START */
-inline void traceMark(int tag, const char *name, ...)
+void traceMark(uint64_t tag, const char *name, ...)
 {
        if (isTagEnabled(tag)) {
                char buf[MAX_LEN], end = 'E';
@@ -235,7 +236,7 @@ inline void traceMark(int tag, const char *name, ...)
  * - name: the event name
  * - value: the value tracing
  */
-inline void traceCounter(int tag, int value, const char *name, ...)
+void traceCounter(uint64_t tag, int value, const char *name, ...)
 {
        if (isTagEnabled(tag)) {
                char buf[MAX_LEN];
@@ -247,6 +248,7 @@ inline void traceCounter(int tag, int value, const char *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);
+               va_end(ap);
                write(g_trace_handle_fd, buf, len);
        }
 #ifdef TTRACE_DEBUG
@@ -256,96 +258,22 @@ inline void traceCounter(int tag, int value, const char *name, ...)
 #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, ...)
-{
-       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()
-{
-       traceEnd(TTRACE_TAG_APP);
-}
-
-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, ...)
-{
-       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, ...)
-{
-       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, ...)
+void traceBegin(uint64_t tag, const char *name, ...)
 {; }
 
-inline void traceEnd(int tag)
+void traceEnd(uint64_t tag)
 {; }
 
-inline void traceAsyncBegin(int tag, int cookie, const char *name, ...)
+void traceAsyncBegin(uint64_t tag, int cookie, const char *name, ...)
 {; }
 
-inline void traceAsyncEnd(int tag, int cookie, const char *name, ...)
+void traceAsyncEnd(uint64_t tag, int cookie, const char *name, ...)
 {; }
 
-inline void traceMark(int tag, const char *name, ...)
+void traceMark(uint64_t 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, ...)
+void traceCounter(uint64_t tag, int value, const char *name, ...)
 {; }
 #endif
-
diff --git a/ttrace-static.pc.in b/ttrace-static.pc.in
new file mode 100644 (file)
index 0000000..b34eb31
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: ttrace static lib.
+Description: T-trace for tizen
+Version: @VERSION@
+Requires: dlog
+Libs: -L${libdir} libttrace.a
+Cflags: -I${includedir}
diff --git a/ttrace.h.in b/ttrace.h.in
new file mode 100755 (executable)
index 0000000..a6aabf4
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * T-trace
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CDBG_TIZEN_TTRACE_H_
+#define _CDBG_TIZEN_TTRACE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#cmakedefine TTRACE_PROFILE_MOBILE
+#cmakedefine TTRACE_PROFILE_TV
+#cmakedefine TTRACE_PROFILE_WEARABLE
+
+#include "stdint.h"
+
+/* 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_GRAPHICS            (1<<1)
+#define TTRACE_TAG_INPUT               (1<<2)
+#define TTRACE_TAG_VIEW                (1<<3)
+#define TTRACE_TAG_WEB                 (1<<4)
+#define TTRACE_TAG_WINDOW_MANAGER      (1<<5)
+#define TTRACE_TAG_APPLICATION_MANAGER (1<<6)
+#define TTRACE_TAG_IMAGE               (1<<7)
+#define TTRACE_TAG_AUDIO               (1<<8)
+#define TTRACE_TAG_VIDEO               (1<<9)
+#define TTRACE_TAG_CAMERA              (1<<10)
+#define TTRACE_TAG_HAL                 (1<<11)
+#define TTRACE_TAG_MEDIA_CONTENT       (1<<12)
+#define TTRACE_TAG_MEDIA_DB            (1<<13)
+#define TTRACE_TAG_SCREEN_MIRRORING    (1<<14)
+#define TTRACE_TAG_APP                 (1<<15)
+
+#ifdef TTRACE_PROFILE_MOBILE
+//define TAGs belonging to mobile profile only
+#elif defined TTRACE_PROFILE_TV
+//define TAGs belonging to mobile profile only
+#elif defined TTRACE_PROFILE_WEARABLE
+//define TAGs belonging to mobile profile only
+#endif
+
+#define TTRACE_TAG_LAST                (1<<63)
+
+#define ENABLED_TAG_FILE "/tmp/ttrace_tag"
+
+void traceBegin(uint64_t tag, const char *name, ...);
+void traceEnd(uint64_t tag);
+void traceAsyncBegin(uint64_t tag, int cookie, const char *name, ...);
+void traceAsyncEnd(uint64_t tag, int cookie, const char *name, ...);
+void traceMark(uint64_t tag, const char *name, ...);
+void traceCounter(uint64_t tag, int value, const char *name, ...);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _CDBG_TIZEN_TTRACE_H_ */
+