summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mem.h6
-rw-r--r--src/util/profiler.h18
2 files changed, 22 insertions, 2 deletions
diff --git a/src/util/mem.h b/src/util/mem.h
new file mode 100644
index 0000000..852e844
--- /dev/null
+++ b/src/util/mem.h
@@ -0,0 +1,6 @@
+#include "typedef.h"
+
+[[maybe_unused, clang::noinline]]
+static void* __cur_retaddr() {
+ return __builtin_extract_return_addr( __builtin_return_address(0) );
+}
diff --git a/src/util/profiler.h b/src/util/profiler.h
index 7caac96..334ad62 100644
--- a/src/util/profiler.h
+++ b/src/util/profiler.h
@@ -4,6 +4,7 @@
#include "allocator.h"
#include "time.h"
#include "thread.h"
+#include "mem.h"
#include "fnv.h"
static THREAD_MUTEX __profiler_intern_mutex;
@@ -13,7 +14,7 @@ static THREAD_MUTEX __profiler_intern_mutex;
#endif
#define PROFILE( x ) \
- PROFILER_LIST_ENTRY* __profiler_intern_id = __profiler_intern_start( x ); \
+ PROFILER_LIST_ENTRY* __profiler_intern_id = __profiler_intern_start( x, (U64)__cur_retaddr() ); \
defer( { __profiler_intern_end( __profiler_intern_id ); } )
#define _profiled PROFILE( __func__ );
@@ -24,6 +25,7 @@ struct PROFILER_LIST_ENTRY {
const char* name;
U64 duration;
U64 start;
+ U64 ptr;
FNV1A hash;
PROFILER_LIST_ENTRY* parent;
@@ -76,7 +78,7 @@ inline void __profiler_intern_new_frame( PROFILER_LIST_ENTRY* entry ) {
}
}
-inline PROFILER_LIST_ENTRY* __profiler_intern_start( const char* name ) {
+inline PROFILER_LIST_ENTRY* __profiler_intern_start( const char* name, U64 ptr ) {
PROFILER_LIST_ENTRY e;
FNV1A fnv = fnv1a( name );
U64 tick = u_tick();
@@ -100,6 +102,7 @@ inline PROFILER_LIST_ENTRY* __profiler_intern_start( const char* name ) {
e.children = {};
e.parent = gprof.current;
e.hash = fnv;
+ e.ptr = ptr;
if( gprof.current )
ep = gprof.current->children.push( e );
@@ -124,14 +127,25 @@ inline void __profiler_intern_init() {
thread_mutex_init( &__profiler_intern_mutex );
}
+inline void __profiler_intern_trace() {
+ thread_mutex_lock( &__profiler_intern_mutex );
+ PROFILER_LIST_ENTRY* entry = gprof.current;
+ dlog( "======== [ profiler trace ] ==========\n" );
+ while( entry ) {
+ dlog( "%s [0x%llx]\n", entry->name, entry->ptr );
+ }
+}
+
extern void __profiler_intern_draw_overlay( struct GL_FONT* font );
#define profiler_init() __profiler_intern_init()
#define profiler_draw_tree( font ) __profiler_intern_draw_overlay( font )
+#define profiler_trace() __profiler_intern_trace()
#else
#define PROFILE( x )
#define _profiled
+#define profiler_trace()
#define profiler_init()
#define profiler_draw_tree( x )
#endif