From 20921d5a47e2b0336a03cf881cdd857201177607 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Tue, 26 Sep 2023 02:23:23 +0200 Subject: profiler --- source/saw/_exe.c | 1 + source/saw/main.c | 29 ++--------------------------- source/saw/profiler.c | 30 ++++++++++++++++++++++++++++++ source/saw/profiler.h | 8 ++++++++ 4 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 source/saw/profiler.c create mode 100644 source/saw/profiler.h (limited to 'source') diff --git a/source/saw/_exe.c b/source/saw/_exe.c index 721afb9..7b6c1f7 100644 --- a/source/saw/_exe.c +++ b/source/saw/_exe.c @@ -1,2 +1,3 @@ #include "_lib.c" #include "main.c" +#include "profiler.c" diff --git a/source/saw/main.c b/source/saw/main.c index 89e899e..298eb2a 100644 --- a/source/saw/main.c +++ b/source/saw/main.c @@ -3,6 +3,8 @@ // - Custom OpenGL loader. // +#include "profiler.h" + #include "../kit/math.h" #include "../kit/time.h" @@ -34,8 +36,6 @@ enum { static struct NVGcontext *saw_nvg; static ma_device saw_ma; -static i64 saw_time = 0; - static i32 saw_mouse_x = 0; static i32 saw_mouse_y = 0; static i8 saw_lbutton_click = 0; @@ -57,21 +57,6 @@ static i8 saw_pianoroll_turned_off[PIANOROLL_SIZE] = { 0 }; # pragma GCC optimize("O3") #endif -static i64 time_(void) { - struct timespec t; - timespec_get(&t, TIME_UTC); - return ((i64) t.tv_sec) * 1000 + ((i64) t.tv_nsec) / 1000000; -} - -static void time_frame_(char const *s) { - i64 t = time_(); - if (saw_time == 0) - printf("%-20s %lld\n", s, t); - else - printf("%-20s+%lld\n", s, t - saw_time); - saw_time = t; -} - static f64 saw_envelope(f64 t, f64 attack, f64 decay, f64 sustain, f64 duration, f64 release) { // FIXME @@ -129,8 +114,6 @@ static void saw_audio(ma_device *device, void *void_out_, #endif static void saw_init(void) { - time_frame_("saw_init"); - sapp_set_window_title("saw"); #ifdef SOKOL_GLCORE33 @@ -139,8 +122,6 @@ static void saw_init(void) { saw_nvg = nvgCreateGLES3(NVG_ANTIALIAS | NVG_STENCIL_STROKES); #endif - time_frame_(" ma device config"); - ma_device_config config = ma_device_config_init( ma_device_type_playback); @@ -150,17 +131,12 @@ static void saw_init(void) { config.dataCallback = saw_audio; config.pUserData = NULL; - time_frame_(" ma device init"); - if (ma_device_init(NULL, &config, &saw_ma) != MA_SUCCESS) { printf("ma_device_init failed.\n"); return; } - time_frame_(" ma start"); ma_device_start(&saw_ma); - - time_frame_(" done"); } static void saw_frame(void) { @@ -293,7 +269,6 @@ char const *__lsan_default_suppressions() { } sapp_desc sokol_main(int argc, char **argv) { - time_frame_("sokol_main"); return (sapp_desc) { .width = 1280, .height = 720, diff --git a/source/saw/profiler.c b/source/saw/profiler.c new file mode 100644 index 0000000..14e6b41 --- /dev/null +++ b/source/saw/profiler.c @@ -0,0 +1,30 @@ +#include "../kit/time.h" + +#include + +long long profiler_time_; + +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunknown-pragmas" +# pragma GCC push_options +# pragma GCC optimize("O3") +#endif + +void profile_frame(char const *s) { + struct timespec ts; + timespec_get(&ts, TIME_UTC); + long long t = ((long long) ts.tv_sec) * 1000 + + ((long long) ts.tv_nsec) / 1000000; + if (profiler_time_ == 0) + printf("%s\n", s); + else + printf("%-19s+%lld\n", s, t - profiler_time_); + profiler_time_ = t; +} + +#ifdef __GNUC__ +# pragma GCC pop_options +# pragma GCC diagnostic pop +#endif diff --git a/source/saw/profiler.h b/source/saw/profiler.h new file mode 100644 index 0000000..a4e0f9f --- /dev/null +++ b/source/saw/profiler.h @@ -0,0 +1,8 @@ +#ifndef SAW_PROFILER_H +#define SAW_PROFILER_H + +extern long long profiler_time_; + +void profile_frame(char const *s); + +#endif -- cgit v1.2.3