From 758b3e4704de534ac7230eeb53b7bd19dd2b3e41 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 28 May 2025 13:16:08 -0500 Subject: [PATCH] remove tracy if not specified on cmd line --- source/prosperon.c | 2 +- source/prosperon.h | 2 ++ source/qjs_macros.h | 17 ----------------- source/qjs_os.c | 3 +++ tests/moth.js | 2 -- 5 files changed, 6 insertions(+), 20 deletions(-) diff --git a/source/prosperon.c b/source/prosperon.c index e6c5e5bf..acdd4754 100644 --- a/source/prosperon.c +++ b/source/prosperon.c @@ -38,7 +38,7 @@ #define unlikely(x) __builtin_expect(!!(x), 0) #endif -static int tracy_profiling_enabled = 0; +int tracy_profiling_enabled = 0; #define ENGINE "scripts/core/engine.js" diff --git a/source/prosperon.h b/source/prosperon.h index e89a3af7..ba702c08 100644 --- a/source/prosperon.h +++ b/source/prosperon.h @@ -16,6 +16,8 @@ typedef JSValue (*MODULEFN)(JSContext *js); +extern int tracy_profiling_enabled; + typedef struct tagMTRand { uint32_t mt[STATE_VECTOR_LENGTH]; int32_t index; diff --git a/source/qjs_macros.h b/source/qjs_macros.h index c7940cc4..a6d32645 100644 --- a/source/qjs_macros.h +++ b/source/qjs_macros.h @@ -1,14 +1,3 @@ -#ifdef TRACY_ENABLE - #include -#else - /* Provide harmless stubs when Tracy is not in use so the rest of the code - can still call the hooks unconditionally. */ - #define TracyCAllocN(ptr, size, name) ((void)0) - #define TracyCFreeN(ptr, name) ((void)0) - #define TracyCFiberEnter(name) ((void)0) - #define TracyCFiberLeave(name) ((void)0) -#endif - #define MIST_CFUNC_DEF(name, length, func1, props) { name, props, JS_DEF_CFUNC, 0, .u = { .func = { length, JS_CFUNC_generic, { .generic = func1 } } } } #define MIST_FUNC_DEF(TYPE, FN, LEN) MIST_CFUNC_DEF(#FN, LEN, js_##TYPE##_##FN, JS_PROP_C_W_E) @@ -102,7 +91,6 @@ JSValue js_##ID##_get_##ENTRY (JSContext *js, JSValue self) { \ JSClassID js_##TYPE##_id;\ static void js_##TYPE##_finalizer(JSRuntime *rt, JSValue val){\ TYPE *n = JS_GetOpaque(val, js_##TYPE##_id);\ -TracyCFreeN(n, #TYPE); \ TYPE##_free(rt,n);}\ static JSClassDef js_##TYPE##_class = {\ .class_name = #TYPE,\ @@ -116,14 +104,12 @@ JSValue TYPE##2js(JSContext *js, TYPE *n) { \ JSValue j = JS_NewObjectClass(js,js_##TYPE##_id);\ JS_SetOpaque(j,n);\ __VA_ARGS__ \ - TracyCAllocN(n, 1, #TYPE); \ return j; }\ \ #define QJSCLASSMARK(TYPE, ...)\ static void js_##TYPE##_finalizer(JSRuntime *rt, JSValue val){\ TYPE *n = JS_GetOpaque(val, js_##TYPE##_id);\ -TracyCFreeN(n, #TYPE); \ TYPE##_free(rt,n);}\ static JSClassDef js_##TYPE##_class = {\ .class_name = #TYPE,\ @@ -138,14 +124,12 @@ JSValue TYPE##2js(JSContext *js, TYPE *n) { \ JSValue j = JS_NewObjectClass(js,js_##TYPE##_id);\ JS_SetOpaque(j,n);\ __VA_ARGS__ \ - TracyCAllocN(n, 1, #TYPE); \ return j; }\ \ #define QJSCLASSMARK_EXTERN(TYPE, ...)\ static void js_##TYPE##_finalizer(JSRuntime *rt, JSValue val){\ TYPE *n = JS_GetOpaque(val, js_##TYPE##_id);\ -TracyCFreeN(n, #TYPE); \ TYPE##_free(rt,n);}\ static JSClassDef js_##TYPE##_class = {\ .class_name = #TYPE,\ @@ -161,7 +145,6 @@ JSValue TYPE##2js(JSContext *js, TYPE *n) { \ JSValue j = JS_NewObjectClass(js,js_##TYPE##_id);\ JS_SetOpaque(j,n);\ __VA_ARGS__ \ - TracyCAllocN(n, 1, #TYPE); \ return j; }\ \ diff --git a/source/qjs_os.c b/source/qjs_os.c index 4eb362da..7589cc73 100644 --- a/source/qjs_os.c +++ b/source/qjs_os.c @@ -263,10 +263,12 @@ static JSValue js_os_rusage(JSContext *js, JSValue self, int argc, JSValue *argv #ifdef TRACY_ENABLE #include JSC_CCALL(os_frame, + if (!tracy_profiling_enabled) return JS_UNDEFINED; TracyCFrameMark ) JSC_CCALL(os_trace_img, + if (!tracy_profiling_enabled) return JS_UNDEFINED; size_t len; double width, height; JS_ToFloat64(js,&width,argv[1]); @@ -275,6 +277,7 @@ JSC_CCALL(os_trace_img, ) JSC_CCALL(os_trace_message, + if (!tracy_profiling_enabled) return JS_UNDEFINED; size_t len; const char *str = JS_ToCStringLen(js, &len, argv[0]); TracyCMessage(str,len); diff --git a/tests/moth.js b/tests/moth.js index bb3c99b2..a9b6502f 100644 --- a/tests/moth.js +++ b/tests/moth.js @@ -66,7 +66,6 @@ var camera = { var images = {} - // Convert high-level draw commands to low-level renderer commands function translate_draw_commands(commands) { if (!graphics) return @@ -250,7 +249,6 @@ function loop() // Calculate average FPS var avg_fps = fps_sum / fps_samples.length - console.log(`FPS: ${avg_fps.toFixed(1)}`) } loop()