From 59e1991f7ba8bcd6bc4aab611b904c7419b719a9 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 28 May 2021 22:42:41 +0200 Subject: Add macros for easy cycle profiling --- src/main.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 2aa744c..255c790 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,34 @@ WITH REGARD TO THIS SOFTWARE. #define CONTROL_METHODS CONTROL_CONTROLLER,CONTROL_MOUSE,CONTROL_KEYBOARD #endif +#ifdef PROF_ENABLE +#if PROF_ENABLE == 0 +#define PROF(F,VAR) (profile_start(),(F),(VAR) = profile_stop()) +#else +#define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR))) +#endif +#define PROF_SHOW(X,Y) \ + do { \ + txt_position((X), (Y));\ + txt_printf("INPUT: %lu ", input_cycles);\ + txt_position((X), (Y)+1);\ + txt_printf("EVAL: %lu ", eval_cycles);\ + txt_position((X), (Y)+2);\ + txt_printf("FLIP: %lu ", flip_cycles);\ + txt_position((X), (Y)+3);\ + txt_printf("MIX: %lu ", mix_cycles);\ + } while (0) +#define PROF_INIT() \ + u32 flip_cycles = 0;\ + u32 eval_cycles = 0;\ + u32 input_cycles = 0;\ + u32 mix_cycles = 0; +#else +#define PROF(F,VAR) (F) +#define PROF_SHOW(X,Y) +#define PROF_INIT() +#endif + typedef enum { CONTROL_CONTROLLER, CONTROL_MOUSE, @@ -392,12 +420,14 @@ int main(void) { // Main loop. evaluxn(&u, 0x0100); + PROF_INIT(); while(true) { bios_vblank_wait(); - handle_input(&u); - evaluxn(&u, mempeek16(devscreen->dat, 0)); - sound_mix(); - flipbuf(&ppu); + PROF(handle_input(&u), input_cycles); + PROF(evaluxn(&u, mempeek16(devscreen->dat, 0)), eval_cycles); + PROF(sound_mix(), mix_cycles); + PROF_SHOW(9, 8); + PROF(flipbuf(&ppu), flip_cycles); } return 0; -- cgit v1.2.1