diff --git a/src/task.c b/src/task.c index 09eda42c..95240092 100644 --- a/src/task.c +++ b/src/task.c @@ -341,6 +341,7 @@ int tf_task_execute(tf_task_t* task, const char* fileName) if (!*task->_scriptName) { strncpy(task->_scriptName, fileName, sizeof(task->_scriptName) - 1); + tf_trace_set_process_name(task->_trace, fileName); } if (!task->_path) { diff --git a/src/trace.c b/src/trace.c index 77a0e91b..4024edc9 100644 --- a/src/trace.c +++ b/src/trace.c @@ -31,6 +31,7 @@ typedef struct _tf_trace_stack_t typedef struct _tf_trace_t { char buffer[k_buffer_size]; + char process_name[256]; int write_offset; tf_trace_write_callback_t* callback; @@ -74,6 +75,11 @@ void tf_trace_destroy(tf_trace_t* trace) tf_free(trace); } +void tf_trace_set_process_name(tf_trace_t* trace, const char* name) +{ + snprintf(trace->process_name, sizeof(trace->process_name), "%s", name); +} + void tf_trace_raw(tf_trace_t* trace, const char* buffer, size_t size) { trace->callback(trace, buffer, size, trace->user_data); @@ -216,6 +222,13 @@ char* tf_trace_export(tf_trace_t* trace) int begin = newline ? newline - trace->buffer : 0; size_t size = 0; size += snprintf(buffer, k_buffer_size, "{\"displayTimeUnit\": \"ns\",\n\"traceEvents\": [\n"); + if (*trace->process_name) + { + size += snprintf(buffer + size, k_buffer_size - size, + "{\"name\":\"process_name\",\"ph\":\"M\",\"pid\":%d,\"args\":{\"name\":\"%s\"}},", + getpid(), + trace->process_name); + } if (begin) { size_t this_size = strlen(trace->buffer + begin); diff --git a/src/trace.h b/src/trace.h index 53a0936e..f56aaa73 100644 --- a/src/trace.h +++ b/src/trace.h @@ -9,6 +9,8 @@ typedef struct sqlite3 sqlite3; tf_trace_t* tf_trace_create(); void tf_trace_destroy(tf_trace_t* trace); +void tf_trace_set_process_name(tf_trace_t* trace, const char* name); + void tf_trace_counter(tf_trace_t* trace, const char* name, int argc, const char** arg_names, const int64_t* arg_values); void tf_trace_begin(tf_trace_t* trace, const char* name); void tf_trace_end(tf_trace_t* trace);