summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoon.c.baek <joon.c.baek@samsung.com>2017-09-14 16:51:37 +0900
committerjoon.c.baek <joon.c.baek@samsung.com>2017-09-15 13:40:19 +0900
commitf7e64040f0ed2204c940f4042f588ef43c74f34e (patch)
tree3a0f7129cece6595e3b24022e493ea1fd7ab3898
parent37138335b180b9c610c671c2103a00fd8a9fca82 (diff)
downloadttrace-f7e64040f0ed2204c940f4042f588ef43c74f34e.tar.gz
ttrace-f7e64040f0ed2204c940f4042f588ef43c74f34e.tar.bz2
ttrace-f7e64040f0ed2204c940f4042f588ef43c74f34e.zip
Align indentation and remove build warningsubmit/tizen/20170915.063230
Used invalid type in printf(), change to correct type. Many code lines did keep a indentation, aligned indent for all of source codes. Change-Id: I7cc0438d061c734b5356accd9ff9ff0801f64ff6
-rwxr-xr-xsrc/atrace/atrace.cpp301
1 files changed, 154 insertions, 147 deletions
diff --git a/src/atrace/atrace.cpp b/src/atrace/atrace.cpp
index ea2758a..c509354 100755
--- a/src/atrace/atrace.cpp
+++ b/src/atrace/atrace.cpp
@@ -35,13 +35,13 @@
#include <sys/smack.h>
#include <unistd.h>
#include "ttrace.h"
-#define TTRACE_TAG_NONE 9999
-#define TAG_NONE_IDX 0
+#define TTRACE_TAG_NONE 9999
+#define TAG_NONE_IDX 0
-#define BACKUP_TRACE "/tmp/trace.backup"
-#define BOOTUP_TRACE "/etc/ttrace.conf"
-#define DEF_GR_SIZE 1024
-#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
+#define BACKUP_TRACE "/tmp/trace.backup"
+#define BOOTUP_TRACE "/etc/ttrace.conf"
+#define DEF_GR_SIZE 1024
+#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
enum { MAX_SYS_FILES = 8 };
@@ -127,8 +127,8 @@ static const TracingCategory k_categories[] = {
} },
#ifdef TTRACE_PROFILE_MOBILE
#elif defined TTRACE_PROFILE_TV
- { "system", "System", TTRACE_TAG_SYSTEM, { } },
- { "perftest", "For Performance test", TTRACE_TAG_PERFTEST, { } },
+ { "system", "System", TTRACE_TAG_SYSTEM, { } },
+ { "perftest", "For Performance test", TTRACE_TAG_PERFTEST, { } },
#elif defined TTRACE_PROFILE_WEARABLE
#endif
};
@@ -394,8 +394,8 @@ static void setBootupTags(char* bootupTagStr)
static bool initEnabledTagFile()
{
- uint64_t *sm_for_enabled_tag = NULL;
- int fd = -1;
+ uint64_t *sm_for_enabled_tag = NULL;
+ int fd = -1;
if(fileExists(ENABLED_TAG_FILE)) {
fprintf(stderr, "[Info] T-trace has been already initailized\n");
@@ -426,8 +426,8 @@ static bool initEnabledTagFile()
fprintf(stderr, "Fail to rename enabled_tag file: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
}
- munmap(sm_for_enabled_tag, sizeof(uint64_t));
- close(fd);
+ munmap(sm_for_enabled_tag, sizeof(uint64_t));
+ close(fd);
return true;
}
@@ -435,28 +435,28 @@ static bool initEnabledTagFile()
// processes to pick up the new value.
static bool setTagsProperty(uint64_t tags)
{
- uint64_t *sm_for_enabled_tag = NULL;
- int fd = -1;
-
- // atrace normal mode
- fd = open(ENABLED_TAG_FILE, O_RDWR | O_CLOEXEC, 0600);
- 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;
- }
- 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, "mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
- close(fd);
- return false;
- }
- *sm_for_enabled_tag = tags;
-
- // For debug
- // fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag);
- //
- munmap(sm_for_enabled_tag, sizeof(uint64_t));
- close(fd);
+ uint64_t *sm_for_enabled_tag = NULL;
+ int fd = -1;
+
+ // atrace normal mode
+ fd = open(ENABLED_TAG_FILE, O_RDWR | O_CLOEXEC, 0600);
+ 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;
+ }
+ 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, "mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
+ close(fd);
+ return false;
+ }
+ *sm_for_enabled_tag = tags;
+
+ // For debug
+ // fprintf(stderr, "Enabled TAGs: %u\n", (uint32_t)*sm_for_enabled_tag);
+ //
+ munmap(sm_for_enabled_tag, sizeof(uint64_t));
+ close(fd);
return true;
}
@@ -527,8 +527,8 @@ static bool setUpTrace()
// Set up the tracing options.
ok &= setTraceOverwriteEnable(g_traceOverwrite);
if(!g_append_trace) {
- ok &= setTraceBufferSizeKB(g_traceBufferSizeKB);
- ok &= setGlobalClockEnable(true);
+ ok &= setTraceBufferSizeKB(g_traceBufferSizeKB);
+ ok &= setGlobalClockEnable(true);
ok &= setKernelTraceFuncs(g_kernelTraceFuncs);
}
ok &= setPrintTgidEnableIfPresent(true);
@@ -537,25 +537,25 @@ static bool setUpTrace()
uint64_t tags = 0;
if (g_categoryEnables[TAG_NONE_IDX]) tags = TTRACE_TAG_NEVER;
else {
- for (int i = 0; i < NELEM(k_categories); i++) {
- if (g_categoryEnables[i]) {
- const TracingCategory &c = k_categories[i];
- if ((c.tags & excludedTags) == 0)
- tags |= c.tags;
- }
- }
- if (tags == 0 && excludedTags == 0) {
- tags |= TTRACE_TAG_ALWAYS;
- }
- else if (tags == 0 && excludedTags != 0) {
- excludedTags |= TTRACE_TAG_ALWAYS;
- tags |= ~excludedTags;
- }
- else {
- excludedTags |= TTRACE_TAG_ALWAYS;
- tags &= ~excludedTags;
- }
- printf("Tags: 0x%lx, excludedTags: 0x%lx\n", tags, excludedTags);
+ for (int i = 0; i < NELEM(k_categories); i++) {
+ if (g_categoryEnables[i]) {
+ const TracingCategory &c = k_categories[i];
+ if ((c.tags & excludedTags) == 0)
+ tags |= c.tags;
+ }
+ }
+ if (tags == 0 && excludedTags == 0) {
+ tags |= TTRACE_TAG_ALWAYS;
+ }
+ else if (tags == 0 && excludedTags != 0) {
+ excludedTags |= TTRACE_TAG_ALWAYS;
+ tags |= ~excludedTags;
+ }
+ else {
+ excludedTags |= TTRACE_TAG_ALWAYS;
+ tags &= ~excludedTags;
+ }
+ printf("Tags: 0x%llx, excludedTags: 0x%llx\n", tags, excludedTags);
}
ok &= startTrace();
@@ -614,27 +614,27 @@ static void stopTrace()
// Read the current kernel trace and write it to stdout.
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, 0600);
-
- 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;
- }
+ backup_fd = open(BACKUP_TRACE, O_CREAT|O_RDWR|O_TRUNC, 0600);
+
+ 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;
+ }
}
if (traceFD == -1) {
fprintf(stderr, "error opening %s: %s (%d)\n", k_tracePath,
strerror_r(errno, str_error, sizeof(str_error)), errno);
if (backup_fd > -1)
- close(backup_fd);
+ close(backup_fd);
return;
}
@@ -649,7 +649,7 @@ static void dumpTrace(bool startup)
fprintf(stderr, "error initializing zlib: %d\n", result);
close(traceFD);
if (backup_fd > -1)
- close(backup_fd);
+ close(backup_fd);
return;
}
@@ -657,16 +657,16 @@ static void dumpTrace(bool startup)
in = (uint8_t*)malloc(bufSize);
out = (uint8_t*)malloc(bufSize);
if ((in == NULL) || (out == NULL)) {
- fprintf(stderr, "Could not allocate memory");
- if (in != NULL)
- free(in);
- if (out != NULL)
- free(out);
- close(traceFD);
- if (backup_fd > -1)
- close(backup_fd);
- return;
- }
+ fprintf(stderr, "Could not allocate memory");
+ if (in != NULL)
+ free(in);
+ if (out != NULL)
+ free(out);
+ close(traceFD);
+ if (backup_fd > -1)
+ close(backup_fd);
+ return;
+ }
flush = Z_NO_FLUSH;
zs.next_out = out;
@@ -692,8 +692,11 @@ static void dumpTrace(bool startup)
if (zs.avail_out == 0) {
// Need to write the output.
- if(startup) result = write(backup_fd, out, bufSize);
- else result = write(STDOUT_FILENO, out, bufSize);
+ if(startup)
+ result = write(backup_fd, out, bufSize);
+ else
+ result = write(STDOUT_FILENO, out, bufSize);
+
if ((size_t)result < bufSize) {
fprintf(stderr, "error writing deflated trace: %s (%d)\n",
strerror_r(errno, str_error, sizeof(str_error)), errno);
@@ -713,8 +716,11 @@ static void dumpTrace(bool startup)
if (zs.avail_out < bufSize) {
size_t bytes = bufSize - zs.avail_out;
- if(startup) result = write(backup_fd, out, bytes);
- else result = write(STDOUT_FILENO, out, bytes);
+ if(startup)
+ result = write(backup_fd, out, bytes);
+ else
+ result = write(STDOUT_FILENO, out, bytes);
+
if ((size_t)result < bytes) {
fprintf(stderr, "error writing deflated trace: %s (%d)\n",
strerror_r(errno, str_error, sizeof(str_error)), errno);
@@ -729,19 +735,20 @@ static void dumpTrace(bool startup)
free(in);
free(out);
} else {
- ssize_t sent = 0;
- 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);
- if (sent == -1) {
- fprintf(stderr, "error dumping trace: %s (%d)\n", strerror_r(errno, str_error, sizeof(str_error)),
- errno);
- }
+ ssize_t sent = 0;
+ 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);
+
+ if (sent == -1) {
+ fprintf(stderr, "error dumping trace: %s (%d)\n", strerror_r(errno, str_error, sizeof(str_error)),
+ errno);
+ }
}
- if (backup_fd > -1)
- close(backup_fd);
+ if (backup_fd > -1)
+ close(backup_fd);
close(traceFD);
}
@@ -804,25 +811,25 @@ static void showHelp(const char *cmd)
{
fprintf(stderr, "usage: %s [options] [categories...]\n", cmd);
fprintf(stderr, "options include:\n"
- " -b N use a trace buffer size of N KB\n"
- " -c trace into a circular buffer\n"
- " -e category specify a category to exclude [default None]\n"
- " example, $ atrace -e wm -e am -e gfx\n"
- " -k fname,... trace the listed kernel functions\n"
- " -n ignore signals\n"
- " -s N sleep for N seconds before tracing [default 0]\n"
- " -t N trace for N seconds [defualt 5]\n"
- " -z compress the trace dump\n"
- " --async_start start circular trace and return immediatly\n"
- " --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"
- " --append append traces to the existing traces. do not clear the trace buffer \n"
- " and kernel trace events set\n"
- " --backup back up the existing traces to /tmp/trace.backup and then clear the trace buffer\n"
- " --list_categories\n"
- " list the available tracing categories\n"
- );
+ " -b N use a trace buffer size of N KB\n"
+ " -c trace into a circular buffer\n"
+ " -e category specify a category to exclude [default None]\n"
+ " example, $ atrace -e wm -e am -e gfx\n"
+ " -k fname,... trace the listed kernel functions\n"
+ " -n ignore signals\n"
+ " -s N sleep for N seconds before tracing [default 0]\n"
+ " -t N trace for N seconds [defualt 5]\n"
+ " -z compress the trace dump\n"
+ " --async_start start circular trace and return immediatly\n"
+ " --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"
+ " --append append traces to the existing traces. do not clear the trace buffer \n"
+ " and kernel trace events set\n"
+ " --backup back up the existing traces to /tmp/trace.backup and then clear the trace buffer\n"
+ " --list_categories\n"
+ " list the available tracing categories\n"
+ );
}
int main(int argc, char **argv)
@@ -850,13 +857,13 @@ int main(int argc, char **argv)
{"async_stop", no_argument, 0, 0 },
{"async_dump", no_argument, 0, 0 },
{"list_categories", no_argument, 0, 0 },
- {"init_exec", no_argument, 0, 0 },
- {"append", no_argument, 0, 0 },
- {"backup", no_argument, 0, 0 },
- { 0, 0, 0, 0 }
+ {"init_exec", no_argument, 0, 0 },
+ {"append", no_argument, 0, 0 },
+ {"backup", no_argument, 0, 0 },
+ {0, 0, 0, 0 }
};
- ret = getopt_long(argc, argv, "b:ck:e:ns:t:z",
- long_options, &option_index);
+ ret = getopt_long(argc, argv, "b:ck:e:ns:t:z",
+ long_options, &option_index);
if (ret < 0) {
for (int i = optind; i < argc; i++) {
if (!setCategoryEnable(argv[i], true)) {
@@ -870,48 +877,48 @@ int main(int argc, char **argv)
switch(ret) {
case 'a':
g_debugAppCmdLine = optarg;
- break;
+ break;
case 'b':
g_traceBufferSizeKB = atoi(optarg);
- break;
+ break;
case 'c':
g_traceOverwrite = true;
- break;
-
- case 'e':
- setCategoryEnable(optarg, true);
- for (int i = 0; i < NELEM(k_categories); i++) {
- const TracingCategory &c = k_categories[i];
- if (!strcmp(c.name, optarg)) {
- excludedTags |= c.tags;
- }
- }
- break;
+ break;
+
+ case 'e':
+ setCategoryEnable(optarg, true);
+ for (int i = 0; i < NELEM(k_categories); i++) {
+ const TracingCategory &c = k_categories[i];
+ if (!strcmp(c.name, optarg)) {
+ excludedTags |= c.tags;
+ }
+ }
+ break;
case 'k':
g_kernelTraceFuncs = optarg;
- break;
+ break;
case 'n':
g_nohup = true;
- break;
+ break;
case 's':
g_initialSleepSecs = atoi(optarg);
- break;
+ break;
case 't':
g_traceDurationSeconds = atoi(optarg);
- break;
+ break;
case 'z':
g_compress = true;
- break;
+ break;
case 0:
- if (!strcmp(long_options[option_index].name, "list_categories")) {
+ if (!strcmp(long_options[option_index].name, "list_categories")) {
listSupportedCategories();
exit(0);
}
@@ -946,18 +953,18 @@ int main(int argc, char **argv)
else {
exit(0);
}
- } else if (!strcmp(long_options[option_index].name, "append")) {
+ } else if (!strcmp(long_options[option_index].name, "append")) {
g_append_trace = true;
- } else if (!strcmp(long_options[option_index].name, "backup")) {
+ } else if (!strcmp(long_options[option_index].name, "backup")) {
g_backup_trace = true;
- }
- break;
+ }
+ break;
default:
fprintf(stderr, "\n");
showHelp(argv[0]);
exit(-1);
- break;
+ break;
}
}
@@ -969,15 +976,15 @@ int main(int argc, char **argv)
bool ok = true;
if(traceStart && g_backup_trace) {
-//before start tracing by atrace, backup existig traces
- stopTrace();
- dumpTrace(true);
+ //before start tracing by atrace, backup existig traces
+ stopTrace();
+ dumpTrace(true);
}
if (!(async && !g_traceOverwrite)) {
- ok &= setUpTrace();
+ ok &= setUpTrace();
}
if (ok && traceStart) {
- // For debug
+ // For debug
// printf("capturing trace...");
//
fflush(stdout);
@@ -1008,7 +1015,7 @@ int main(int argc, char **argv)
if (!g_traceAborted) {
printf(" done\nTRACE:\n");
fflush(stdout);
- dumpTrace(false);
+ dumpTrace(false);
} else {
printf("\ntrace aborted.\n");
fflush(stdout);