Add process name to trace.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4160 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-02-01 23:20:16 +00:00
parent a8cecb5c64
commit e0dcec074c
3 changed files with 16 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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);