summaryrefslogtreecommitdiff
path: root/src/util/profiler.cpp
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-03-10 01:35:50 +0100
committeraura <nw@moneybot.cc>2026-03-10 01:35:50 +0100
commit8329d42d3e592f4cd42cdfa586e2325ddc76c898 (patch)
treedec7e2a733bfc6b6384936c1f3ed067a42b59bb9 /src/util/profiler.cpp
parent8ae8c85e9d3806cdb726e07f37e1b49484c5c48e (diff)
perf profiler, simplify 2d render, string struct, many small things
Diffstat (limited to 'src/util/profiler.cpp')
-rw-r--r--src/util/profiler.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/util/profiler.cpp b/src/util/profiler.cpp
new file mode 100644
index 0000000..86c1810
--- /dev/null
+++ b/src/util/profiler.cpp
@@ -0,0 +1,55 @@
+#if defined(DEBUG) || defined(PROFILER)
+#include "profiler.h"
+#include "../render/gl_2d_font.h"
+#include "../game/vars.h"
+#include "string.h"
+
+CVAR* prof_overlay = var_new( "prof_overlay", 0 );
+PROFILER_GLOBAL gprof;
+
+void __profiler_intern_draw_tree( PROFILER_LIST_ENTRY* e, GL_FONT* font, I32* x, I32* y ) {
+ GL_DATA* gl = gl_instance();
+ static GL_SHADER_PROGRAM** gl2d = gl->programs.where( fn( GL_SHADER_PROGRAM** p ) {
+ return STR( (*p)->name ) == "2d" ;
+ } );
+
+ if( !gl2d )
+ return;
+
+ STR line;
+ if( e->parent ) {
+ U64 parent_dur = e->parent->duration;
+ U64 percent = (F64)parent_dur / e->duration * 100.f;
+ line = STR( "%s -> duration: %.2fms [%.0f%%]",
+ e->name,
+ (F32)e->duration / TICK_RESOLUTION * 1000.f,
+ percent
+ );
+ } else {
+ line = STR( "%s -> duration: %.2fms",
+ e->name,
+ (F32)e->duration / TICK_RESOLUTION * 1000.f
+ );
+ }
+
+ gl_font_draw( font, *gl2d, VEC2{ (F32)*x + 1, (F32)*y + 1 }, line, CLR::BLACK() );
+ gl_font_draw( font, *gl2d, VEC2{ (F32)*x, (F32)*y }, line, CLR::WHITE() );
+
+ *y += font->size + 1;
+ *x += 20;
+ for( auto& it : e->children )
+ __profiler_intern_draw_tree( &it, font, x, y );
+ *x -= 20;
+}
+
+void __profiler_intern_draw_overlay( struct GL_FONT* f ) {
+ if( !var_geti( prof_overlay ) )
+ return;
+
+ I32 x = 50, y = 50;
+ for( auto& it : gprof.frames )
+ __profiler_intern_draw_tree( &it, f, &x, &y );
+}
+
+
+#endif