X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_profiler.h;h=67808a7a6d42d898f42e747d0be49f0a4528b8aa;hb=76d234b7dc5e6500e8a54009b367e7620f11ef97;hp=784fc287ebf7ea0297dda48276f04a502f21c5ab;hpb=4c48fe01a5d1983be89b7dce6f08e6b708cfbb05;p=vg.git diff --git a/vg_profiler.h b/vg_profiler.h index 784fc28..67808a7 100644 --- a/vg_profiler.h +++ b/vg_profiler.h @@ -1,6 +1,7 @@ #ifndef VG_PROFILER_H #define VG_PROFILER_H +#define VG_GAME #include "vg.h" #include "vg_platform.h" @@ -12,8 +13,8 @@ struct vg_profile { const char *name; - u32 samples[ VG_PROFILE_SAMPLE_COUNT ]; - u32 buffer_count, buffer_current; + u64 samples[ VG_PROFILE_SAMPLE_COUNT ]; + u32 buffer_count, buffer_current; enum profile_mode { @@ -25,12 +26,12 @@ struct vg_profile u64 start; }; -VG_STATIC void vg_profile_begin( struct vg_profile *profile ) +static void vg_profile_begin( struct vg_profile *profile ) { profile->start = SDL_GetPerformanceCounter(); } -VG_STATIC void vg_profile_increment( struct vg_profile *profile ) +static void vg_profile_increment( struct vg_profile *profile ) { profile->buffer_current ++; @@ -40,28 +41,24 @@ VG_STATIC void vg_profile_increment( struct vg_profile *profile ) if( profile->buffer_current >= VG_PROFILE_SAMPLE_COUNT ) profile->buffer_current = 0; - profile->samples[ profile->buffer_current ] = 0.0f; + profile->samples[ profile->buffer_current ] = 0; } -VG_STATIC void vg_profile_end( struct vg_profile *profile ) +static void vg_profile_end( struct vg_profile *profile ) { - u64 time_end; + u64 time_end = SDL_GetPerformanceCounter(), + delta = time_end - profile->start; - time_end = SDL_GetPerformanceCounter(); - u64 delta = profile->start - time_end; - - if( profile->mode == k_profile_mode_frame ) - { + if( profile->mode == k_profile_mode_frame ){ profile->samples[ profile->buffer_current ] = delta; vg_profile_increment( profile ); } - else - { + else{ profile->samples[ profile->buffer_current ] += delta; } } -VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, +static void vg_profile_drawn( struct vg_profile **profiles, u32 count, float budget, ui_rect panel, u32 colour_offset ) { if( !vg_profiler ) @@ -76,14 +73,13 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, float sh = panel[3] / VG_PROFILE_SAMPLE_COUNT, sw = panel[2]; - ui_fill_rect( panel, 0xa0000000 ); + ui_fill( panel, 0xa0000000 ); assert( count <= 8 ); - float avgs[8]; - int ptrs[8]; + double avgs[8]; + int ptrs[8]; - for( int i=0; ibuffer_current; avgs[i] = 0.0f; } @@ -91,28 +87,26 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, u32 colours[] = { 0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00 }; - float rate_mul = 1.0f / (float)SDL_GetPerformanceFrequency(); + double rate_mul = 1000.0 / (double)SDL_GetPerformanceFrequency(); - for( int i=0; isamples[ptrs[j]] * rate_mul, - px = (total / (budget)) * sw, - wx = (sample / (budget)) * sw; + double sample = (double)profiles[j]->samples[ptrs[j]] * rate_mul, + px = (total / (budget)) * sw, + wx = (sample / (budget)) * sw; ui_rect block = { panel[0] + px, panel[1] + (float)i*sh, wx, sh }; u32 colour = colours[ (j+colour_offset) % vg_list_size(colours) ]; - ui_fill_rect( block, colour ); + ui_fill( block, colour ); total += sample; avgs[j] += sample; @@ -121,8 +115,14 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, char infbuf[64]; - for( int i=0; iname ); @@ -131,19 +131,13 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, panel[1] + i * 14, 0, 0 }, infbuf, 1, - k_text_align_left ); + k_ui_align_left, 0 ); } } -VG_STATIC void vg_profiler_init(void) +static void vg_profiler_init(void) { - vg_convar_push( (struct vg_convar){ - .name = "vg_profiler", - .data = &vg_profiler, - .data_type = k_convar_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 1 - }); + VG_VAR_I32( vg_profiler, flags=VG_VAR_PERSISTENT ); } #endif /* VG_PROFILER_H */