X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_profiler.h;h=c8db76dab3c7ad8bfcf3322eeec37e2e0659e3a3;hb=3b3420de0251e489082814e60dcc45e5e8842224;hp=784fc287ebf7ea0297dda48276f04a502f21c5ab;hpb=4c48fe01a5d1983be89b7dce6f08e6b708cfbb05;p=vg.git diff --git a/vg_profiler.h b/vg_profiler.h index 784fc28..c8db76d 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; + float samples[ VG_PROFILE_SAMPLE_COUNT ]; + u32 buffer_count, buffer_current; enum profile_mode { @@ -45,14 +46,12 @@ VG_STATIC void vg_profile_increment( struct vg_profile *profile ) VG_STATIC void vg_profile_end( struct vg_profile *profile ) { - u64 time_end; - - time_end = SDL_GetPerformanceCounter(); - u64 delta = profile->start - time_end; + u64 time_end = SDL_GetPerformanceCounter(), + delta = time_end - profile->start; if( profile->mode == k_profile_mode_frame ) { - profile->samples[ profile->buffer_current ] = delta; + profile->samples[ profile->buffer_current ] = (float)delta; vg_profile_increment( profile ); } else @@ -61,6 +60,12 @@ VG_STATIC void vg_profile_end( struct vg_profile *profile ) } } +VG_STATIC void vg_profile_graph_sample( struct vg_profile *profile, float s ) +{ + profile->samples[ profile->buffer_current ] = s; + vg_profile_increment( profile ); +} + VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, float budget, ui_rect panel, u32 colour_offset ) { @@ -91,7 +96,7 @@ 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(); + float rate_mul = 1000.0f / (float)SDL_GetPerformanceFrequency(); for( int i=0; isamples[ptrs[j]] * rate_mul, + float sample = profiles[j]->samples[ptrs[j]] * rate_mul, px = (total / (budget)) * sw, wx = (sample / (budget)) * sw; @@ -137,10 +142,10 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count, VG_STATIC void vg_profiler_init(void) { - vg_convar_push( (struct vg_convar){ + vg_var_push( (struct vg_var){ .name = "vg_profiler", .data = &vg_profiler, - .data_type = k_convar_dtype_i32, + .data_type = k_var_dtype_i32, .opt_i32 = { .min=0, .max=1, .clamp=1 }, .persistent = 1 });