From 5a5219b486fc6de57ae1f95c7a44cf4ed6eb1e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valts=20Liepi=C5=86=C5=A1?= Date: Sat, 7 Oct 2023 22:39:00 +0300 Subject: [PATCH] (core) Cleans up trace state on crash recovery --- src/engine/arcan_general.h | 5 +++++ src/engine/arcan_main.c | 8 ++++++++ src/engine/arcan_trace.c | 30 +++++++++++++++++------------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/engine/arcan_general.h b/src/engine/arcan_general.h index 5cef8c545..fa162fc91 100644 --- a/src/engine/arcan_general.h +++ b/src/engine/arcan_general.h @@ -175,6 +175,11 @@ void arcan_trace_setbuffer(uint8_t* buf, size_t buf_sz, bool* finish_flag); */ void arcan_trace_log(const char* message, size_t len); +/* + * cleans up trace buffer and tracy zones + */ +void arcan_trace_close(); + /* add a trace entry-point (though call through the TRACE_MARK macros), * sys returns to the main system group (graphics, video, 3d, ...) and * subsys for a group specific subsystem (where useful distinctions exist). diff --git a/src/engine/arcan_main.c b/src/engine/arcan_main.c index fa00bf7f5..e6aba1037 100644 --- a/src/engine/arcan_main.c +++ b/src/engine/arcan_main.c @@ -608,6 +608,10 @@ int MAIN_REDIR(int argc, char* argv[]) arcan_lua_cbdrop(); arcan_lua_shutdown(main_lua_context); + const char trace_msg[] = "Switching appls, resetting trace"; + arcan_trace_log(trace_msg, sizeof(trace_msg)); + arcan_trace_close(); + /* mask off errors so shutdowns etc. won't queue new events that enter * the event queue and gets exposed to the new appl */ arcan_event_maskall(evctx); @@ -676,6 +680,10 @@ int MAIN_REDIR(int argc, char* argv[]) if (strcmp(fallback, ":self") == 0) fallback = argv[optind]; + const char trace_msg[] = "Recovering from crash, resetting trace"; + arcan_trace_log(trace_msg, sizeof(trace_msg)); + arcan_trace_close(); + if (!arcan_verifyload_appl(fallback, &errmsg)){ arcan_warning("Lua VM error fallback, failure loading (%s), reason: %s\n", fallback, errmsg); diff --git a/src/engine/arcan_trace.c b/src/engine/arcan_trace.c index eb8030527..259b05a58 100644 --- a/src/engine/arcan_trace.c +++ b/src/engine/arcan_trace.c @@ -43,19 +43,6 @@ void arcan_trace_setbuffer(uint8_t* buf, size_t buf_sz, bool* finish_flag) arcan_trace_enabled = true; } -static bool append_string(const char* str) -{ - do { - buffer[buffer_pos++] = *str++; - - if (buffer_pos == buffer_sz) - return false; - - } while (*str); - - return true; -} - void arcan_trace_log(const char* message, size_t len) { if (!arcan_trace_enabled) @@ -344,3 +331,20 @@ void arcan_trace_mark( *buffer_flag = true; buffer[start_ofs] = 0xaa; } + +void arcan_trace_close() +{ + if (!arcan_trace_enabled) + return; + + #ifdef WITH_TRACY + for (int i=tracy_ctx.zone_stack_len-1; i>=0; --i) { + ___tracy_emit_zone_end(tracy_ctx.zone_stack[i].ctx); + } + tracy_ctx.zone_stack_len = 0; + tracy_ctx.mark_ids_len = 0; + #endif + + // Releases trace buffer if it exists + arcan_trace_setbuffer(buffer, 0, NULL); +}