libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
Trace.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * Trace.h
5 *
6 * Stall diagnostics that don't disturb timing.
7 *
8 * Every thread records - in plain RAM, with no I/O and no locks - the name of
9 * the phase it is in right now, plus a short ring of the most recent phase
10 * changes across all threads. Nothing is written anywhere while things are
11 * healthy. A watchdog thread reports any thread that has sat in one phase for
12 * too long, together with the recent history and every other thread's phase;
13 * and a phase that finished but was slow is reported when it ends
14 * ("[main] 'LoadFile:fopen' took 6700 ms").
15 *
16 * TRACE_LOG() is the sparing exception: a handful of milestone lines that do
17 * go to the log, tagged with the calling thread.
18 *
19 * All of it compiles to nothing unless LOGGING_ENABLED is set, so it costs
20 * release builds nothing - no thread, no memory.
21 *
22 * Only pass string literals to TRACE_AT()/TRACE_THREAD(): the pointer itself
23 * is what gets stored. Threads that are just waiting for work mark themselves
24 * "idle" so they are never reported as stalled.
25 *
26 * Reports go through LOG_*(), which serializes on the Logger's mutex - and a
27 * file backend holds that mutex while it writes to the SD card. If the stall
28 * being chased is the SD card itself, a report may not get out; use the UDP
29 * backend for those runs.
30 ***************************************************************************/
31#pragma once
32
33#include "Logger.h"
34
35#if LOGGING_ENABLED
36
37#include <stddef.h>
38
40void TraceThread(const char * name);
42void TraceAt(const char * where);
44void TraceLog(const char * fmt, ...) __attribute__((format(printf, 1, 2)));
48void TraceSetStateFn(void (*fn)(char * out, size_t size));
50void TraceStartWatchdog();
51
52#define TRACE_THREAD(name) TraceThread(name)
53#define TRACE_AT(where) TraceAt(where)
54#define TRACE_LOG(...) TraceLog(__VA_ARGS__)
55#define TRACE_STATE_FN(fn) TraceSetStateFn(fn)
56#define TRACE_WATCHDOG() TraceStartWatchdog()
57
58#else
59
60#define TRACE_THREAD(name) ((void)0)
61#define TRACE_AT(where) ((void)0)
62#define TRACE_LOG(...) ((void)0)
63#define TRACE_STATE_FN(fn) ((void)0)
64#define TRACE_WATCHDOG() ((void)0)
65
66#endif