From 3045f7c95bf6c6f6935ef9a274a8176abb11ac4a Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 18 Jan 2023 09:43:32 +0100 Subject: [PATCH 1/2] trace: fix new json start --- src/trace/trace.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/trace/trace.c b/src/trace/trace.c index fa3571ab1..5760d7795 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -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 @@ -130,6 +131,7 @@ int re_trace_init(const char *json_file) trace.start_time = tmr_jiffies_usec(); trace.init = true; + trace.new = true; out: if (err) { @@ -177,7 +179,6 @@ int re_trace_flush(void) struct trace_event *e; char json_arg[256]; char name[128]; - static bool first = true; #ifndef RE_TRACE_ENABLED return 0; @@ -227,10 +228,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); From 6920326a5995e2122291fc593cd108a08ec8563a Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 18 Jan 2023 09:46:45 +0100 Subject: [PATCH 2/2] trace: add doxygen comments --- src/trace/trace.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/trace/trace.c b/src/trace/trace.c index 5760d7795..d8d61d8f3 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -93,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; @@ -144,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; @@ -172,6 +184,11 @@ 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;