aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-01-25 13:39:32 +0100
committerBad Diode <bd@badd10de.dev>2024-01-25 13:39:32 +0100
commite181b0e2209fd7a2e843bbb7cfe2151497450325 (patch)
tree59c86b8e25ee367378e1d9f0b3eff0f7db0c172d
parent3c54d94191b0888af3712f7c330943068604cab8 (diff)
downloadstepper-e181b0e2209fd7a2e843bbb7cfe2151497450325.tar.gz
stepper-e181b0e2209fd7a2e843bbb7cfe2151497450325.zip
Update profiling macros
-rw-r--r--src/main.c54
-rw-r--r--src/profiling.c95
-rw-r--r--src/sequencer.c12
3 files changed, 112 insertions, 49 deletions
diff --git a/src/main.c b/src/main.c
index 6f1d0e6..cec540e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,6 +48,9 @@ WITH REGARD TO THIS SOFTWARE.
48 48
49#include "gba/gba.h" 49#include "gba/gba.h"
50 50
51#define PROF_ENABLE 0
52#include "profiling.c"
53
51#include "renderer_m0.c" 54#include "renderer_m0.c"
52#include "globals.c" 55#include "globals.c"
53#include "assets.c" 56#include "assets.c"
@@ -57,9 +60,6 @@ WITH REGARD TO THIS SOFTWARE.
57#include "scale.c" 60#include "scale.c"
58#include "sequencer.c" 61#include "sequencer.c"
59 62
60#define PROF_ENABLE 0
61#include "profiling.c"
62
63static int frames = 0; 63static int frames = 0;
64 64
65void 65void
@@ -191,10 +191,52 @@ render(void) {
191 191
192void 192void
193handle_input(void) { 193handle_input(void) {
194 if (key_tap(KEY_SELECT) && key_hold(KEY_START)) { 194#if PROF_ENABLE > 0
195 PROF_SHOW(); 195 if (key_hold(KEY_SELECT)) {
196 clear_screen = true; 196 if (key_tap(KEY_DOWN)) {
197 PROF_SHOW();
198 clear_screen = true;
199 redraw_trigs = true;
200 redraw_channels = true;
201 redraw_pattern_buttons = true;
202 redraw_bank_buttons = true;
203 redraw_bpm = true;
204 redraw_play_pause = true;
205 redraw_params = true;
206 redraw_scale = true;
207 return;
208 }
209 static int prof_detail = 0;
210 if (key_tap(KEY_RIGHT)) {
211 prof_detail = CLAMP(prof_detail + 1, 0, 3);
212 PROF_DETAIL(prof_detail);
213 clear_screen = true;
214 redraw_trigs = true;
215 redraw_channels = true;
216 redraw_pattern_buttons = true;
217 redraw_bank_buttons = true;
218 redraw_bpm = true;
219 redraw_play_pause = true;
220 redraw_params = true;
221 redraw_scale = true;
222 return;
223 }
224 if (key_tap(KEY_LEFT)) {
225 prof_detail = CLAMP(prof_detail - 1, 0, 3);
226 PROF_DETAIL(prof_detail);
227 clear_screen = true;
228 redraw_trigs = true;
229 redraw_channels = true;
230 redraw_pattern_buttons = true;
231 redraw_bank_buttons = true;
232 redraw_bpm = true;
233 redraw_play_pause = true;
234 redraw_params = true;
235 redraw_scale = true;
236 return;
237 }
197 } 238 }
239#endif
198 switch (scene) { 240 switch (scene) {
199 case SCENE_SETTINGS: { 241 case SCENE_SETTINGS: {
200 handle_settings_input(); 242 handle_settings_input();
diff --git a/src/profiling.c b/src/profiling.c
index 07f4bbf..44e12fd 100644
--- a/src/profiling.c
+++ b/src/profiling.c
@@ -2,6 +2,9 @@
2// Profiling macros. 2// Profiling macros.
3// 3//
4 4
5// NOTE: Profiling uses the last two timers to count cycles, and thus can't be
6// used for measuring applications that use them.
7
5#ifndef PROF_ENABLE 8#ifndef PROF_ENABLE
6#define PROF_ENABLE 0 9#define PROF_ENABLE 0
7#endif 10#endif
@@ -9,7 +12,7 @@
9#if PROF_ENABLE > 0 12#if PROF_ENABLE > 0
10 13
11#ifndef PROF_RESET_MINMAX 14#ifndef PROF_RESET_MINMAX
12#define PROF_RESET_MINMAX true 15#define PROF_RESET_MINMAX false
13#endif 16#endif
14 17
15// Maximum number of profiling to monitor. 18// Maximum number of profiling to monitor.
@@ -20,31 +23,33 @@ typedef enum ProfType {
20 PROF_FLIP, 23 PROF_FLIP,
21 PROF_FILL, 24 PROF_FILL,
22 PROF_NUM, 25 PROF_NUM,
26 PROF_END,
23} ProfType; 27} ProfType;
24 28
25char *prof_type_str[PROF_NUM] = { 29char *prof_type_str[PROF_END] = {
26 "INPUT ", 30 "INPUT ",
27 "UPDATE ", 31 "UPDATE ",
28 "RENDER ", 32 "RENDER ",
29 "FLIPBUF", 33 "FLIPBUF ",
30 "SCRFILL", 34 "SCRFILL ",
31}; 35};
32 36
33u32 prof_frame_time = 0; 37u32 prof_frame_time = 0;
34u32 prof_frame_count = 0; 38u32 prof_frame_count = 0;
35u32 prof_frame_avg = -1; 39u32 prof_frame_avg = 0;
36u32 prof_frame_time_max = 0; 40u32 prof_frame_time_max = 0;
37u32 prof_times[PROF_NUM] = {0}; 41u32 prof_times[PROF_END] = {0};
38u32 prof_count[PROF_NUM] = {0}; 42u32 prof_count[PROF_END] = {0};
39u32 prof_avg[PROF_NUM] = {0}; 43u32 prof_avg[PROF_END] = {0};
40u32 prof_max[PROF_NUM] = {0}; 44u32 prof_max[PROF_END] = {0};
41u32 prof_min[PROF_NUM] = {0}; 45u32 prof_min[PROF_END] = {0};
42 46
43bool prof_reset_minmax = PROF_RESET_MINMAX; 47bool prof_reset_minmax = PROF_RESET_MINMAX;
44bool prof_show = true; 48bool prof_show = true;
49u8 prof_detail_level = 2;
45 50
46#define PROF_INIT() do { \ 51#define PROF_INIT() do { \
47 for (size_t i = 0; i < PROF_NUM; i++) { \ 52 for (size_t i = 0; i < PROF_END; i++) { \
48 prof_min[i] = -1; \ 53 prof_min[i] = -1; \
49 } \ 54 } \
50} while(0); 55} while(0);
@@ -66,23 +71,43 @@ bool prof_show = true;
66 71
67#define FRAME_END() do { \ 72#define FRAME_END() do { \
68 prof_frame_count++;\ 73 prof_frame_count++;\
69 prof_frame_time_max = MAX(prof_frame_time_max, profile_measure());\ 74 u32 frame_time = profile_measure();\
75 prof_frame_time_max = MAX(prof_frame_time_max, frame_time);\
70 prof_frame_time += profile_stop();\ 76 prof_frame_time += profile_stop();\
71 if (prof_show) { \ 77 if (prof_show) { \
72 draw_filled_rect(0, 0, SCREEN_WIDTH - 1, 8 * (PROF_NUM + 1), 0); \ 78 u32 fps = (u64)280896 * 60 / (prof_frame_avg + 1); \
73 txt_drawf_small("FRAME TIME/FPS: %.9l/%.2l", 0, 0, COL_FG, \ 79 if (prof_frame_avg == 0) { \
74 prof_frame_avg, \ 80 fps = 0; \
75 (u32)((u64)280896 * 60 / (prof_frame_avg + 1)));\ 81 } \
76 txt_drawf_small("MAX: %.9l/%l", 8 * 19, 0, COL_FG, \ 82 if (prof_detail_level > 0) {\
77 prof_frame_time_max, 280896);\ 83 draw_filled_rect(0, 0, SCREEN_WIDTH - 1, 8, 2); \
84 txt_drawf_small("AVG/MAX/VDRAW: %.9l/%.9l/%l FPS: %.3l CPU: %.3l", 0, 0, COL_FG, \
85 prof_frame_avg, prof_frame_time_max, 280896, fps, (u64)prof_frame_avg * 100 / 280896);\
86 } else { \
87 draw_filled_rect(8 * 25 + 4, 0, SCREEN_WIDTH - 1, 8, 2); \
88 txt_drawf_small("CPU: %.3l", 8 * 25 + 4, 0, COL_FG, \
89 (u64)prof_frame_avg * 100 / 280896);\
90 } \
91 if (prof_detail_level >= 3) {\
92 draw_filled_rect(0, 8, SCREEN_WIDTH - 1, 8 * (PROF_NUM + 1), 2); \
93 } else if (prof_detail_level >= 2) {\
94 draw_filled_rect(0, 8, 8 * 15, 8 * (PROF_NUM + 1), 2); \
95 } \
78 for (size_t idx = 0; idx < PROF_NUM; idx++) { \ 96 for (size_t idx = 0; idx < PROF_NUM; idx++) { \
79 txt_drawf_small("%s %.9l (%.9l %.9l) %08x:%08x", 0, 8 * (idx + 1), COL_FG, \ 97 if (prof_detail_level >= 3) {\
80 prof_type_str[idx], \ 98 txt_drawf_small("%s %.9l (%.9l %.9l) %08x:%08x", 0, 8 * (idx + 1), COL_FG, \
81 prof_avg[idx], \ 99 prof_type_str[idx], \
82 prof_min[idx], \ 100 prof_avg[idx], \
83 prof_max[idx], \ 101 prof_min[idx], \
84 prof_avg[idx], \ 102 prof_max[idx], \
85 prof_max[idx]);\ 103 prof_avg[idx], \
104 prof_max[idx]);\
105 } else if (prof_detail_level >= 2) {\
106 txt_drawf_small("%s %.9l/%.9l", 0, 8 * (idx + 1), COL_FG, \
107 prof_type_str[idx], \
108 prof_avg[idx], \
109 prof_max[idx]);\
110 }\
86 }; \ 111 }; \
87 } \ 112 } \
88 if (prof_frame_count >= PROF_ENABLE) { \ 113 if (prof_frame_count >= PROF_ENABLE) { \
@@ -91,7 +116,6 @@ bool prof_show = true;
91 if (prof_reset_minmax) { \ 116 if (prof_reset_minmax) { \
92 prof_min[idx] = -1; \ 117 prof_min[idx] = -1; \
93 prof_max[idx] = 0; \ 118 prof_max[idx] = 0; \
94 prof_frame_time_max = 0; \
95 } \ 119 } \
96 prof_times[idx] = 0; \ 120 prof_times[idx] = 0; \
97 prof_count[idx] = 0; \ 121 prof_count[idx] = 0; \
@@ -106,12 +130,21 @@ bool prof_show = true;
106 prof_show ^= 1; \ 130 prof_show ^= 1; \
107} while(0) 131} while(0)
108 132
133#define PROF_DETAIL(N) do { \
134 prof_detail_level = (N); \
135} while(0)
136
109#else 137#else
110 138
111// No profiling. 139// No profiling.
112#define PROF_INIT() 140#define PROF_INIT()
113#define PROF(F,VAR) do {F;} while(0) 141#define PROF(F,VAR) do {F;} while(0)
114#define FRAME_START() 142#define FRAME_START() do { \
115#define FRAME_END() 143 profile_start();\
144} while(0)
145#define FRAME_END() do { \
146 frame_time = profile_stop();\
147} while(0)
116#define PROF_SHOW() 148#define PROF_SHOW()
149#define PROF_DETAIL(N)
117#endif 150#endif
diff --git a/src/sequencer.c b/src/sequencer.c
index 4f46e1f..7570a7a 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -387,18 +387,6 @@ env_start:
387 } 387 }
388 current_wave[k][j] = next; 388 current_wave[k][j] = next;
389 } 389 }
390 // DEBUG:
391 // if (k < 4) {
392 // int x = 0;
393 // int y = 18 * k;
394 // draw_filled_rect(x, y, 100 + x, 16 + y, COL_BG);
395 // draw_wave_pattern(&current_wave[k], 0 + x, 0 + y, 1);
396 // } else {
397 // int x = 100;
398 // int y = 18 * (k - 4);
399 // draw_filled_rect(x, y, 100 + x, 16 + y, COL_BG);
400 // draw_wave_pattern(&current_wave[k], 0 + x, 0 + y, 1);
401 // }
402 } 390 }
403 wave_env_ticks = 0; 391 wave_env_ticks = 0;
404 wave_env_prog = 0; 392 wave_env_prog = 0;