medfall

A super great game engine
Log | Files | Refs

profiler.h (1084B)


      1 #pragma once
      2 
      3 #include "intrinsics.h"
      4 #include "platform_io.h"
      5 
      6 void profiler_init();
      7 void profiler_term();
      8 
      9 u32 profiler_new_timer( const char * name, const char * file, int line );
     10 void profiler_push( u32 timer_idx );
     11 void profiler_pop( const char * name = NULL );
     12 void profiler_write_summary();
     13 
     14 #define PROFILE_BLOCK_NAME_LENGTH 128
     15 
     16 struct ScopedTimer {
     17 	ScopedTimer( u32 timer_idx, const char * n );
     18 	~ScopedTimer();
     19 
     20 	char name[ PROFILE_BLOCK_NAME_LENGTH ];
     21 };
     22 
     23 #define PROFILE_BLOCK( fmt, ... ) \
     24 	static u32 LINE_NAME( scoped_timer_idx ) = profiler_new_timer( fmt, __FILE__, __LINE__ ); \
     25 	char LINE_NAME( scoped_timer_name )[ PROFILE_BLOCK_NAME_LENGTH ]; \
     26 	snprintf( LINE_NAME( scoped_timer_name ), PROFILE_BLOCK_NAME_LENGTH, fmt, ##__VA_ARGS__ ); \
     27 	ScopedTimer LINE_NAME( scoped_timer )( LINE_NAME( scoped_timer_idx ), LINE_NAME( scoped_timer_name ) );
     28 #define PROFILE_FUNCTION() \
     29 	static u32 LINE_NAME( scoped_timer_idx ) = profiler_new_timer( __FUNCTION__, __FILE__, __LINE__ ); \
     30 	ScopedTimer LINE_NAME( scoped_timer )( LINE_NAME( scoped_timer_idx ), __FUNCTION__ );