Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace: fix new json start #648

Merged
merged 2 commits into from
Jan 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static struct {
struct trace_event *event_buffer_flush;
mtx_t lock;
bool init;
bool new;
uint64_t start_time;
} trace = {
.init = false
Expand Down Expand Up @@ -92,6 +93,13 @@ static inline int get_process_id(void)
}


/**
* Init new trace json file
*
* @param json_file json file for trace events
*
* @return 0 if success, otherwise errorcode
*/
int re_trace_init(const char *json_file)
{
int err = 0;
Expand Down Expand Up @@ -130,6 +138,7 @@ int re_trace_init(const char *json_file)

trace.start_time = tmr_jiffies_usec();
trace.init = true;
trace.new = true;

out:
if (err) {
Expand All @@ -142,6 +151,11 @@ int re_trace_init(const char *json_file)
}


/**
* Close and flush trace file
*
* @return 0 if success, otherwise errorcode
*/
int re_trace_close(void)
{
int err = 0;
Expand Down Expand Up @@ -170,14 +184,18 @@ int re_trace_close(void)
}


/**
* Flush trace buffer (can be called multiple times)
*
* @return 0 if success, otherwise errorcode
*/
int re_trace_flush(void)
{
int i, flush_count;
struct trace_event *event_tmp;
struct trace_event *e;
char json_arg[256];
char name[128];
static bool first = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice


#ifndef RE_TRACE_ENABLED
return 0;
Expand Down Expand Up @@ -227,10 +245,10 @@ int re_trace_flush(void)
(void)re_fprintf(trace.f,
"%s{\"cat\":\"%s\",\"pid\":%i,\"tid\":%lu,\"ts\":%llu,"
"\"ph\":\"%c\",%s%s}",
first ? "" : ",\n",
trace.new ? "" : ",\n",
e->cat, e->pid, e->tid, e->ts - trace.start_time,
e->ph, name, str_isset(json_arg) ? json_arg : "");
first = false;
trace.new = false;
}

(void)fflush(trace.f);
Expand Down