size_t bufSize = DEF_GR_SIZE;
char buf[DEF_GR_SIZE];
int ret = 0;
+
+ if(fileExists(ENABLED_TAG_FILE)) {
+ fprintf(stderr, "[Info] T-trace has been already initailized\n");
+ return false; //atrace has been already initailized.
+ }
ret = getgrnam_r(TTRACE_GROUP_NAME, &group_dev, buf, bufSize, &group_ptr);
if (ret != 0 && ret != ERANGE)
if(ret == ERANGE) isInvalid = true;
free(dynbuf);
}
-
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);
//set file permission, smack label to "/tmp/tmp_tag" and then change it's name to "/tmp/ttrace_tag"
if (!setFilePermission("/tmp/tmp_tag", tag_node.perms))
{
- fprintf(stderr, "error: setFilePermission failed(%s): /tmp/tmp_tag\n", strerror_r(errno, str_error, sizeof(str_error)));
+ fprintf(stderr, "setFilePermission 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)));
+ fprintf(stderr, "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);
if(sm_for_enabled_tag == MAP_FAILED) {
- fprintf(stderr, "error: mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
+ fprintf(stderr, "mmap() 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);
if(sm_for_enabled_tag == MAP_FAILED) {
- fprintf(stderr, "error: mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
+ fprintf(stderr, "mmap() failed(%s)\n", strerror_r(errno, str_error, sizeof(str_error)));
close(fd);
return false;
}
listSupportedCategories();
exit(0);
} else if (!strcmp(long_options[option_index].name, "init_exec")) {
- fprintf(stderr, "init_exec\n");
+ fprintf(stderr, "[Info] Initailize T-trace\n");
g_init_exec = true;
setTagsProperty(0);
exit(0);
#define MAX_TRACE_LEN 1024
#define MAX_LEN 512
+#define MAX_TAIL_LEN 13
+#define MAX_HEAD_LEN 8
+#define POS_LABEL_ST (MAX_LEN - MAX_HEAD_LEN)
+#define POS_LABEL_ED (MAX_LEN - MAX_TAIL_LEN)
+
#define FD_INITIAL_VALUE -1
#define TRACE_FILE_NOT_EXIST -2
{
if (isTagEnabled(tag) || g_extension_state == EXT_ACTIVATED) {
char buf[MAX_LEN];
- int len = 0, ret = 0;
+ int len = MAX_HEAD_LEN, ret = 0;
va_list ap;
TTRACE_LOG("traceBegin:: write >> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
va_start(ap, name);
- len = snprintf(buf, MAX_LEN, "B|%d|", getpid());
- len += vsnprintf(buf + len, MAX_LEN - len, name, ap);
+ snprintf(buf, MAX_LEN, "B|%5d|", getpid());
+ len += vsnprintf(buf + MAX_HEAD_LEN, POS_LABEL_ST, name, ap);
va_end(ap);
+
+ if (len > MAX_LEN) len = MAX_LEN - 1;
if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len);
else ret = write(g_trace_handle_fd, buf, len);
* - cookie: an unique identifier for distinguishing simultaneous events.
* The name and cookie used to begin an event must be used to end it.
*/
-void traceAsyncBegin(uint64_t tag, int cookie, const char *name, ...)
+void traceAsyncBegin(uint64_t tag, int32_t cookie, const char *name, ...)
{
if (isTagEnabled(tag) || g_extension_state == EXT_ACTIVATED) {
char buf[MAX_LEN];
- int len = 0, ret = 0;
+ int len = MAX_HEAD_LEN, ret = 0;
va_list ap;
TTRACE_LOG("traceAsyncBegin:: write >> tag: %u tag_bit: %u cookie: %d", tag, *cur_enabled_tag, cookie);
va_start(ap, name);
- len = snprintf(buf, MAX_LEN, "S|%d|", getpid());
- len += vsnprintf(buf + len, MAX_LEN - len, name, ap);
- len += snprintf(buf + len, MAX_LEN - len, "|%d", cookie);
+ snprintf(buf, MAX_LEN, "S|%5d|", getpid());
+ len += vsnprintf(buf + MAX_HEAD_LEN, POS_LABEL_ST, name, ap);
va_end(ap);
+ if (len + MAX_TAIL_LEN < MAX_LEN) {
+ len += snprintf(buf + len, MAX_LEN - len, "|%d", cookie);
+ }
+ else {
+ snprintf(buf + POS_LABEL_ED, MAX_TAIL_LEN, "|%d", cookie);
+ len = MAX_LEN - 1;
+ }
+
if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len);
else ret = write(g_trace_handle_fd, buf, len);
#endif
}
-void traceAsyncEnd(uint64_t tag, int cookie, const char *name, ...)
+void traceAsyncEnd(uint64_t tag, int32_t cookie, const char *name, ...)
{
if (isTagEnabled(tag) || g_extension_state == EXT_ACTIVATED) {
char buf[MAX_LEN];
- int len = 0, ret = 0;
+ int len = MAX_HEAD_LEN, ret = 0;
va_list ap;
TTRACE_LOG("traceAsyncEnd:: write>> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
va_start(ap, name);
- len = snprintf(buf, MAX_LEN, "F|%d|", getpid());
- len += vsnprintf(buf + len, MAX_LEN - len, name, ap);
- len += snprintf(buf + len, MAX_LEN - len, "|%d", cookie);
+ snprintf(buf, MAX_LEN, "F|%5d|", getpid());
+ len += vsnprintf(buf + MAX_HEAD_LEN, POS_LABEL_ST, name, ap);
va_end(ap);
+ if (len + MAX_TAIL_LEN < MAX_LEN) {
+ len += snprintf(buf + len, MAX_LEN - len, "|%d", cookie);
+ }
+ else {
+ snprintf(buf + POS_LABEL_ED, MAX_TAIL_LEN, "|%d", cookie);
+ len = MAX_LEN - 1;
+ }
+
+
if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len);
else ret = write(g_trace_handle_fd, buf, len);
{
if (isTagEnabled(tag) || g_extension_state == EXT_ACTIVATED) {
char buf[MAX_LEN], end = 'E';
- int len = 0, ret = 0;
+ int len = MAX_HEAD_LEN, ret = 0;
va_list ap;
TTRACE_LOG("traceMark:: write >> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
va_start(ap, name);
- len = snprintf(buf, MAX_LEN, "B|%d|", getpid());
- len += vsnprintf(buf + len, MAX_LEN - len, name, ap);
+ snprintf(buf, MAX_LEN, "B|%5d|", getpid());
+ len += vsnprintf(buf + MAX_HEAD_LEN, POS_LABEL_ST, name, ap);
va_end(ap);
+ if (len > MAX_LEN) len = MAX_LEN - 1;
+
if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len);
else ret = write(g_trace_handle_fd, buf, len);
* - name: the event name
* - value: the value tracing
*/
-void traceCounter(uint64_t tag, int value, const char *name, ...)
+void traceCounter(uint64_t tag, int32_t value, const char *name, ...)
{
if (isTagEnabled(tag) || g_extension_state == EXT_ACTIVATED) {
char buf[MAX_LEN];
- int len = 0, ret = 0;
+ int len = MAX_HEAD_LEN, ret = 0;
va_list ap;
va_start(ap, name);
- len = snprintf(buf, MAX_LEN, "C|%d|", getpid());
- len += vsnprintf(buf + len, MAX_LEN - len, name, ap);
- len += snprintf(buf + len, MAX_LEN - len, "|%d", value);
+ snprintf(buf, MAX_LEN, "C|%5d|", getpid());
+ len += vsnprintf(buf + MAX_HEAD_LEN, POS_LABEL_ST, name, ap);
va_end(ap);
+ if (len + MAX_TAIL_LEN < MAX_LEN) {
+ len += snprintf(buf + len, MAX_LEN - len, "|%d", value);
+ }
+ else {
+ snprintf(buf + POS_LABEL_ED, MAX_TAIL_LEN, "|%d", value);
+ len = MAX_LEN - 1;
+ }
+
if (g_extension_state == EXT_ACTIVATED) ttrace_extension_write(buf, len);
else ret = write(g_trace_handle_fd, buf, len);
void traceEnd(uint64_t tag)
{; }
-void traceAsyncBegin(uint64_t tag, int cookie, const char *name, ...)
+void traceAsyncBegin(uint64_t tag, int32_t cookie, const char *name, ...)
{; }
-void traceAsyncEnd(uint64_t tag, int cookie, const char *name, ...)
+void traceAsyncEnd(uint64_t tag, int32_t cookie, const char *name, ...)
{; }
void traceMark(uint64_t tag, const char *name, ...)