X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=blobdiff_plain;f=vg_profiler.h;h=5c0690c9186b6010a0ecee9515fc9528cc2397a0;hp=d0106af5d7eef89c6ffd3503d8715853aa1faf47;hb=HEAD;hpb=4bfaf318265027e52181b2447c7d9497d68d2b54 diff --git a/vg_profiler.h b/vg_profiler.h index d0106af..74190cb 100644 --- a/vg_profiler.h +++ b/vg_profiler.h @@ -1,13 +1,9 @@ -#ifndef VG_PROFILER_H -#define VG_PROFILER_H - -#define VG_GAME -#include "vg.h" +#pragma once #include "vg_platform.h" - +#include "vg_imgui.h" #define VG_PROFILE_SAMPLE_COUNT 128 -static int vg_profiler = 0; +extern int vg_profiler; struct vg_profile { @@ -26,127 +22,10 @@ struct vg_profile u64 start; }; -static void vg_profile_begin( struct vg_profile *profile ) -{ - profile->start = SDL_GetPerformanceCounter(); -} - -static void vg_profile_increment( struct vg_profile *profile ) -{ - profile->buffer_current ++; - - if( profile->buffer_count < VG_PROFILE_SAMPLE_COUNT ) - profile->buffer_count ++; - - if( profile->buffer_current >= VG_PROFILE_SAMPLE_COUNT ) - profile->buffer_current = 0; - - profile->samples[ profile->buffer_current ] = 0; -} - -static void vg_profile_end( struct vg_profile *profile ) -{ - u64 time_end = SDL_GetPerformanceCounter(), - delta = time_end - profile->start; - - if( profile->mode == k_profile_mode_frame ){ - profile->samples[ profile->buffer_current ] = delta; - vg_profile_increment( profile ); - } - else{ - profile->samples[ profile->buffer_current ] += delta; - } -} - -static void vg_profile_drawn( struct vg_profile **profiles, u32 count, - float budget, ui_rect panel, u32 colour_offset, - int dir ) -{ - if( panel[2] == 0 ) - panel[2] = 256; - - if( panel[3] == 0 ) - panel[3] = VG_PROFILE_SAMPLE_COUNT * 2; - - f32 sh = (f32)panel[3^dir] / (f32)VG_PROFILE_SAMPLE_COUNT, - sw = (f32)panel[2^dir]; - - ui_fill( panel, 0xa0000000 ); - - assert( count <= 8 ); - f64 avgs[8]; - int ptrs[8]; - - for( int i=0; ibuffer_current; -#else - ptrs[i] = 0; -#endif - avgs[i] = 0.0f; - } - - u32 colours[] = { 0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, - 0xffff00ff, 0xffffff00 }; - - f64 rate_mul = 1000.0 / (f64)SDL_GetPerformanceFrequency(); - - for( int i=0; isamples[ptrs[j]] * rate_mul, - px = (total / (budget)) * sw, - wx = (sample / (budget)) * sw; - - ui_rect block; - block[0^dir] = panel[0^dir] + px; - block[1^dir] = panel[1^dir] + (f32)i*sh; - block[2^dir] = wx; - block[3^dir] = ceilf(sh)-1; - - u32 colour = colours[ (j+colour_offset) % vg_list_size(colours) ]; - ui_fill( block, colour ); - - total += sample; - avgs[j] += sample; - } - } - - char infbuf[64]; - - snprintf( infbuf, 64, "accuracy: %.7fms", rate_mul ); - ui_text( (ui_rect){ panel[0] + 4, - panel[1] + panel[3] - 14, 500, 30 }, - infbuf, - 1, - k_ui_align_left, 0 ); - - for( int i=0; iname ); - - ui_text( (ui_rect){ panel[0] + panel[2] + 4, - panel[1] + i * 14, 0, 0 }, - infbuf, - 1, - k_ui_align_left, 0 ); - } -} - -static void vg_profiler_init(void) -{ - VG_VAR_I32( vg_profiler, flags=VG_VAR_PERSISTENT ); -} - -#endif /* VG_PROFILER_H */ +void vg_profile_begin( struct vg_profile *profile ); +void vg_profile_increment( struct vg_profile *profile ); +void vg_profile_end( struct vg_profile *profile ); +void vg_profile_drawn( struct vg_profile **profiles, u32 count, + f64 budget, ui_rect panel, + int dir, i32 normalize ); +void vg_profiler_init(void);