From 7ac944b5f1ded5e48e26120b5565aa689dd279ff Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 27 Sep 2023 17:12:13 +0200 Subject: [PATCH] trace: use global trace log (#965) * main: add global trace log * trace: fix test trace * jbuf: remove re_trace_init/close * aubuf: remove re_trace_init/close * trace: check for already initialized trace * git: ignore re_trace.json --- .gitignore | 1 + rem/aubuf/ajb.c | 6 ------ src/jbuf/jbuf.c | 7 ------- src/main/init.c | 9 +++++++++ src/trace/trace.c | 3 +++ test/trace.c | 15 --------------- 6 files changed, 13 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 5510c59c4..773dcf20a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ libre.*dylib libre.pc libre.so* *.gcov +re_trace.json # Windows build folder Win32/* diff --git a/rem/aubuf/ajb.c b/rem/aubuf/ajb.c index 13166607f..b367ae6c2 100644 --- a/rem/aubuf/ajb.c +++ b/rem/aubuf/ajb.c @@ -186,9 +186,6 @@ static void destructor(void *arg) struct ajb *ajb = arg; mem_deref(ajb->lock); -#if DEBUG_LEVEL >= 6 - (void)re_trace_close(); -#endif } @@ -274,9 +271,6 @@ struct ajb *ajb_alloc(double silence, size_t wish_sz) ajb->as = AJB_GOOD; ajb->silence = silence; ajb->wish_sz = wish_sz; -#if DEBUG_LEVEL >= 6 - (void)re_trace_init("ajb.json"); -#endif out: if (err) diff --git a/src/jbuf/jbuf.c b/src/jbuf/jbuf.c index 516f39c53..d2a32dc56 100644 --- a/src/jbuf/jbuf.c +++ b/src/jbuf/jbuf.c @@ -205,9 +205,6 @@ static void jbuf_destructor(void *data) /* Free all packets in the pool list */ list_flush(&jb->pooll); mem_deref(jb->lock); -#ifdef RE_JBUF_TRACE - (void)re_trace_close(); -#endif } @@ -269,10 +266,6 @@ int jbuf_alloc(struct jbuf **jbp, uint32_t min, uint32_t max) DEBUG_INFO("alloc: adding to pool list %u\n", i); } -#ifdef RE_JBUF_TRACE - (void)re_trace_init("jbuf.json"); -#endif - out: if (err) mem_deref(jb); diff --git a/src/main/init.c b/src/main/init.c index f62049514..0265b7f6a 100644 --- a/src/main/init.c +++ b/src/main/init.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "main.h" @@ -167,6 +168,10 @@ int libre_init(void) return err; } +#if RE_TRACE_ENABLED + re_trace_init("re_trace.json"); +#endif + err = re_thread_init(); return err; @@ -178,6 +183,10 @@ int libre_init(void) */ void libre_close(void) { + +#if RE_TRACE_ENABLED + re_trace_close(); +#endif (void)fd_setsize(0); net_sock_close(); re_thread_close(); diff --git a/src/trace/trace.c b/src/trace/trace.c index 884af188b..472aeeea7 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -108,6 +108,9 @@ int re_trace_init(const char *json_file) if (!json_file) return EINVAL; + if (trace.init) + return EALREADY; + trace.event_buffer = mem_zalloc( TRACE_BUFFER_SIZE * sizeof(struct trace_event), NULL); if (!trace.event_buffer) diff --git a/test/trace.c b/test/trace.c index be85c828e..f92bac75a 100644 --- a/test/trace.c +++ b/test/trace.c @@ -28,9 +28,6 @@ int test_trace(void) if (test_mode == TEST_THREAD) return ESKIPPED; - err = re_trace_init("test_trace.json"); - TEST_ERR(err); - RE_TRACE_PROCESS_NAME("retest"); RE_TRACE_THREAD_NAME("test_trace"); RE_TRACE_BEGIN("test", "Test Loop Start"); @@ -54,18 +51,6 @@ int test_trace(void) RE_TRACE_END("test", "Test Loop End"); - err = re_trace_close(); - TEST_ERR(err); - - /* Test TRACE after close - should do nothing */ - RE_TRACE_BEGIN("test", "test after close"); - -#ifdef WIN32 - (void)_unlink("test_trace.json"); -#else - (void)unlink("test_trace.json"); -#endif - out: return err; }