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}")
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
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})
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)
# ------------------------------
#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();
};
--- /dev/null
+#!/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
#!/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
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
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
%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
%{_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
%{_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
#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];
#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>
{ "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, { } },
{ "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" },
{ "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 */
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";
#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);
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);
static bool setKernelTraceFuncs(const char* funcs)
{
bool ok = true;
+ char *ptr[2];
if (funcs == NULL || funcs[0] == '\0') {
// Disable kernel function tracing.
// 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);
// 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;
}
// 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;
}
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;
}
if (out != NULL)
free(out);
close(traceFD);
+#ifdef DEVICE_TYPE_TIZEN
+ if (backup_fd > -1)
+ close(backup_fd);
+#endif
return;
}
flush = Z_NO_FLUSH;
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);
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);
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);
}
" --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"
);
{"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",
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;
}
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
// 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.
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);
--- /dev/null
+/*
+ * =============================================================================
+ *
+ * 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
*
* =============================================================================
*/
-#include "dlog.h"
#include "ttrace.h"
#include "trace.h"
-#include "stdint.h"
+#include "dlog.h"
+
#define ENABLE_TTRACE
#ifdef ENABLE_TTRACE
* - 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];
}
-inline void traceEnd(int tag)
+void traceEnd(uint64_t tag)
{
if (isTagEnabled(tag)) {
char end = 'E';
* - 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];
#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];
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
* - 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';
* - 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];
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
#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
-
--- /dev/null
+# 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}
--- /dev/null
+/*
+ * 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_ */
+