summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEunji, Lee <eunjieji.lee@samsung.com>2016-02-15 17:32:43 +0900
committerEunji, Lee <eunjieji.lee@samsung.com>2016-02-15 17:32:43 +0900
commit8d4c41bb2b7b756abbba6f78c62a802039b20608 (patch)
tree94f7942fbfbde1bafcf85552217e8eb5cbd50ee6
parent8552a887b63ec2d5051e975cb3aa520d2f2ce194 (diff)
downloadttrace-8d4c41bb2b7b756abbba6f78c62a802039b20608.tar.gz
ttrace-8d4c41bb2b7b756abbba6f78c62a802039b20608.tar.bz2
ttrace-8d4c41bb2b7b756abbba6f78c62a802039b20608.zip
sync with 2.4 branch (commit:1ae27085e86ce77d74922fc43a256a9e7108724e)
Change-Id: Ie3cba9e4c69c848ec88b4cad2e64c9c0a8c977e4 Signed-off-by: Eunji, Lee <eunjieji.lee@samsung.com>
-rwxr-xr-xpackaging/ttrace.spec3
-rwxr-xr-xsrc/atrace/atrace.cpp134
-rwxr-xr-xsrc/ttrace.c68
-rwxr-xr-xttrace.h.in9
4 files changed, 140 insertions, 74 deletions
diff --git a/packaging/ttrace.spec b/packaging/ttrace.spec
index b450a72..1dc0259 100755
--- a/packaging/ttrace.spec
+++ b/packaging/ttrace.spec
@@ -46,7 +46,8 @@ 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} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir}
+%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir} \
+ -DTTRACE_PROFILE=%{TTRACE_PROFILE}
make %{?jobs:-j%jobs}
%install
diff --git a/src/atrace/atrace.cpp b/src/atrace/atrace.cpp
index a31322f..146e99b 100755
--- a/src/atrace/atrace.cpp
+++ b/src/atrace/atrace.cpp
@@ -65,12 +65,21 @@ const char* k_traceAppCmdlineProperty = "debug.atrace.app_cmdlines";
typedef enum { OPT, REQ } requiredness ;
char str_error[256] = "";
+
struct CommonNode {
const char* path;
const mode_t perms;
};
+
+typedef enum {
+ TTRACE_TAG_IDX = 0,
+ DEBUG_FS_IDX,
+ TRACE_MARKER_IDX,
+ ESSENCE_NODE_IDX
+} commonNodeIdx;
+
static const CommonNode commonNodes[] = {
- { "/tmp/ttrace_tag", 0666 },
+ { ENABLED_TAG_FILE, 0664 },
{ "/sys/kernel/debug", 0755 },
{ "/sys/kernel/debug/tracing/trace_marker", 0222 },
{ "/sys/kernel/debug/tracing/trace_clock", 0666 },
@@ -208,6 +217,9 @@ static bool g_categoryEnables[NELEM(k_categories)] = {};
static bool g_init_exec = false;
static bool g_append_trace = false;
static bool g_backup_trace = false;
+
+static struct group group_dev;
+static struct group* group_ptr;
#endif
/* Sys file paths */
@@ -259,28 +271,35 @@ static bool fileExists(const char* filename) {
static bool fileIsWritable(const char* filename) {
return access(filename, W_OK) != -1;
}
+
+static bool setFilePermisstion (const char *path, const mode_t perms) {
+ //fprintf(stderr, "path: %s, perms: %d, gid: %d\n", path,perms, group_dev.gr_gid);
+ if (0 > chown(path, 0, group_dev.gr_gid)) return false;
+ if (0 > chmod(path, perms)) return false;
+ if (0 > smack_setlabel(path, "*", SMACK_LABEL_ACCESS)) return false;
+
+ return true;
+}
+
static bool initSysfsPermission() {
- struct group group_dev;
- struct group* group_ptr;
- char buf[128];
- if(0 != getgrnam_r("developer", &group_dev, buf, sizeof(buf), &group_ptr))
- return false;
- for (int i = 0 ; i < NELEM(commonNodes); i++) {
+ for (int i = TTRACE_TAG_IDX + 1 ; i < NELEM(commonNodes); i++) {
const CommonNode &node = commonNodes[i];
- if (node.path != NULL) {
- if (fileExists(node.path)) {
- if (strcmp(node.path, "/sys/kernel/debug") == 0) {
- chmod(node.path, node.perms);
- }
- else {
- chown(node.path, 0, group_dev.gr_gid);
- chmod(node.path, node.perms);
- smack_setlabel(node.path, "*", SMACK_LABEL_ACCESS);
- }
+ printf("initsysfsperm: path- %s, perms- %d\n", node.path, node.perms);
+ if (fileExists(node.path)) {
+ if (i == DEBUG_FS_IDX) {
+ if(0 > chmod(node.path, node.perms))
+ return false;
+ }
+ else {
+ if (!setFilePermisstion(node.path, node.perms))
+ return false;
}
}
else {
- return false;
+ if(i < ESSENCE_NODE_IDX)
+ {
+ return false;
+ }
}
}
return true;
@@ -418,7 +437,6 @@ static bool clearTrace()
static bool setTraceBufferSizeKB(int size)
{
char str[32] = "1";
- int len;
if (size < 1) {
size = 1;
}
@@ -477,48 +495,76 @@ static bool setTagsProperty(uint64_t tags)
#ifdef DEVICE_TYPE_TIZEN
uint64_t *sm_for_enabled_tag = NULL;
int fd = -1;
- if(g_init_exec) {
- fd = open("/tmp/tmp_tag", O_CREAT | O_RDWR | O_CLOEXEC, 0666);
+ char buf[128];
+ const CommonNode &tag_node = commonNodes[TTRACE_TAG_IDX];
- if(fd < 0){
- fprintf(stderr, "Fail to open enabled_tag file: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
+//atrace "--init_exec" mode
+ if(g_init_exec) {
+ if(0 != getgrnam_r("developer", &group_dev, buf, sizeof(buf), &group_ptr))
+ return false;
+
+ fd = open("/tmp/tmp_tag", 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);
+ return false;
+ }
+ //set file permission, smack label to "/tmp/tmp_tag" and then change it's name to "/tmp/ttrace_tag"
+ if (!setFilePermisstion("/tmp/tmp_tag", tag_node.perms))
+ {
+ fprintf(stderr, "error: setFilePermisstion failed(%s): /tmp/tmp_tag\n", strerror_r(errno, str_error, sizeof(str_error)));
+ close(fd);
return false;
}
+
if (ftruncate(fd, sizeof(uint64_t)) < 0) {
fprintf(stderr, "error: ftruncate() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
close(fd);
- return false;
- }
- sm_for_enabled_tag = (uint64_t*)mmap(NULL, sizeof(uint64_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ return false;
+ }
+ 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)));
- close(fd);
- return false;
- }
+ 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(!initSysfsPermission()) {
+ fprintf(stderr, "Fail to init sysfs permisions: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
+ close(fd);
+ return false;
+ }
memset(sm_for_enabled_tag, 0, sizeof(uint64_t));
- if(-1 == rename("/tmp/tmp_tag", ENABLED_TAG_FILE)) {
+ if(-1 == rename("/tmp/tmp_tag", tag_node.path)) {
fprintf(stderr, "Fail to rename enabled_tag file: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
}
- if(false == initSysfsPermission()) {
- fprintf(stderr, "Fail to init sysfs permisions: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
- }
+
if(fileExists(BOOTUP_TRACE)) {
FILE *ifile = NULL;
char bootup_cmd[128];
ifile = fopen(BOOTUP_TRACE, "r");
if (ifile == NULL) {
- munmap(sm_for_enabled_tag, sizeof(uint64_t));
- close(fd);
- return false;
- }
- fgets(bootup_cmd, sizeof(bootup_cmd), ifile);
+ munmap(sm_for_enabled_tag, sizeof(uint64_t));
+ close(fd);
+ return false;
+ }
+ if (fgets(bootup_cmd, sizeof(bootup_cmd), ifile) == NULL) {
+ munmap(sm_for_enabled_tag, sizeof(uint64_t));
+ close(fd);
+ fclose(ifile);
+ return false;
+ }
fclose(ifile);
remove(BOOTUP_TRACE);
- system(bootup_cmd);
+ if (0 > system(bootup_cmd)) {
+ munmap(sm_for_enabled_tag, sizeof(uint64_t));
+ close(fd);
+ return false;
+ }
}
}
+//atrace normal mode
else {
fd = open(ENABLED_TAG_FILE, O_RDWR | O_CLOEXEC, 0666);
if(fd < 0){
@@ -531,12 +577,11 @@ static bool setTagsProperty(uint64_t tags)
close(fd);
return false;
}
- *sm_for_enabled_tag = tags;
+ *sm_for_enabled_tag = tags;
}
// For debug
- // fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag);
+ //fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag);
//
-
munmap(sm_for_enabled_tag, sizeof(uint64_t));
close(fd);
#else
@@ -645,6 +690,7 @@ static bool setKernelTraceFuncs(const char* funcs)
ok &= setKernelOptionEnable(k_funcgraphCpuPath, true);
ok &= setKernelOptionEnable(k_funcgraphProcPath, true);
ok &= setKernelOptionEnable(k_funcgraphFlatPath, true);
+ ok &= setKernelOptionEnable(k_funcgraphDurationPath, true);
// Set the requested filter functions.
ok &= truncateFile(k_ftraceFilterPath);
diff --git a/src/ttrace.c b/src/ttrace.c
index e9277ae..12c953d 100755
--- a/src/ttrace.c
+++ b/src/ttrace.c
@@ -39,6 +39,7 @@
#define TTRACE_LOG(format, arg...)
#endif
+#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
@@ -62,27 +63,29 @@ static uint64_t traceInit()
{
uint64_t *sm_for_enabled_tag;
- if(g_trace_handle_fd == FD_INITIAL_VALUE) {
- 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)
- g_trace_handle_fd = TRACE_FILE_NOT_EXIST;
-
- set_last_result(TRACE_ERROR_IO_ERROR);
- return 0;
- }
- }
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;
}
+
+ /* access trace_marker after ensuring tag file creation */
+ if(g_trace_handle_fd == FD_INITIAL_VALUE) {
+ 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)
+ g_trace_handle_fd = TRACE_FILE_NOT_EXIST;
+
+ set_last_result(TRACE_ERROR_IO_ERROR);
+ return 0;
+ }
+ }
+
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));
@@ -120,7 +123,7 @@ void traceBegin(uint64_t tag, const char *name, ...)
{
if (isTagEnabled(tag)) {
char buf[MAX_LEN];
- int len = 0;
+ int len = 0, ret = 0;
va_list ap;
TTRACE_LOG("traceBegin:: write >> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
@@ -128,7 +131,9 @@ void traceBegin(uint64_t tag, const char *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);
+ ret = write(g_trace_handle_fd, buf, len);
+ if (ret < 0)
+ fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceBegin.\n", len, ret, errno);
}
#ifdef TTRACE_DEBUG
else
@@ -141,9 +146,12 @@ void traceBegin(uint64_t tag, const char *name, ...)
void traceEnd(uint64_t tag)
{
if (isTagEnabled(tag)) {
+ int ret = 0;
char end = 'E';
TTRACE_LOG("traceEnd:: write>> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
- write(g_trace_handle_fd, &end, 1);
+ ret = write(g_trace_handle_fd, &end, 1);
+ if (ret < 0)
+ fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceEnd.\n", 1, ret, errno);
}
#ifdef TTRACE_DEBUG
else
@@ -163,7 +171,7 @@ void traceAsyncBegin(uint64_t tag, int cookie, const char *name, ...)
{
if (isTagEnabled(tag)) {
char buf[MAX_LEN];
- int len = 0;
+ int len = 0, ret = 0;
va_list ap;
TTRACE_LOG("traceAsyncBegin:: write >> tag: %u tag_bit: %u cookie: %d", tag, *cur_enabled_tag, cookie);
@@ -172,7 +180,9 @@ void traceAsyncBegin(uint64_t tag, int cookie, const char *name, ...)
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);
+ ret = write(g_trace_handle_fd, buf, len);
+ if (ret < 0)
+ fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceAsyncBegin.\n", len, ret, errno);
}
#ifdef TTRACE_DEBUG
else
@@ -185,7 +195,7 @@ void traceAsyncEnd(uint64_t tag, int cookie, const char *name, ...)
{
if (isTagEnabled(tag)) {
char buf[MAX_LEN];
- int len = 0;
+ int len = 0, ret = 0;
va_list ap;
TTRACE_LOG("traceAsyncEnd:: write>> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
@@ -194,7 +204,9 @@ void traceAsyncEnd(uint64_t tag, int cookie, const char *name, ...)
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);
+ ret = write(g_trace_handle_fd, buf, len);
+ if (ret < 0)
+ fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceAsyncEnd.\n", len, ret, errno);
}
#ifdef TTRACE_DEBUG
else
@@ -213,7 +225,7 @@ void traceMark(uint64_t tag, const char *name, ...)
{
if (isTagEnabled(tag)) {
char buf[MAX_LEN], end = 'E';
- int len = 0;
+ int len = 0, ret = 0;
va_list ap;
TTRACE_LOG("traceMark:: write >> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
@@ -221,8 +233,12 @@ void traceMark(uint64_t tag, const char *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);
+ ret = write(g_trace_handle_fd, buf, len);
+ if (ret < 0)
+ fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceMark.\n", len, ret, errno);
+ ret = write(g_trace_handle_fd, &end, 1);
+ if (ret < 0)
+ fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceMark.\n", 1, ret, errno);
}
#ifdef TTRACE_DEBUG
else
@@ -242,7 +258,7 @@ void traceCounter(uint64_t tag, int value, const char *name, ...)
{
if (isTagEnabled(tag)) {
char buf[MAX_LEN];
- int len = 0;
+ int len = 0, ret = 0;
va_list ap;
va_start(ap, name);
@@ -251,7 +267,9 @@ void traceCounter(uint64_t tag, int value, const char *name, ...)
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);
+ ret = write(g_trace_handle_fd, buf, len);
+ if (ret < 0)
+ fprintf(stderr, "error writing, len: %d, ret: %d, errno: %d at traceCounter.\n", len, ret, errno);
}
#ifdef TTRACE_DEBUG
else
diff --git a/ttrace.h.in b/ttrace.h.in
index f52b85b..cfd6890 100755
--- a/ttrace.h.in
+++ b/ttrace.h.in
@@ -18,16 +18,17 @@
#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 <stdio.h>
#include "stdint.h"
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
/* Define TTRACE_TAG */
#define TTRACE_TAG_NEVER 0 // This tag is never enabled.
#define TTRACE_TAG_ALWAYS (1<<0) // This tag is always enabled.