summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/profiling.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/profiling.c b/src/profiling.c
index e1f4feb..5f5c871 100644
--- a/src/profiling.c
+++ b/src/profiling.c
@@ -3,8 +3,7 @@
3// 3//
4 4
5// NOTE: Profiling uses the last two timers to count cycles, and thus can't be 5// NOTE: Profiling uses the last two timers to count cycles, and thus can't be
6// used for measuring applications that 6// used for measuring applications that use them.
7
8 7
9static u32 frame_time = 0; 8static u32 frame_time = 0;
10 9
@@ -31,6 +30,7 @@ typedef enum ProfType {
31 PROF_TXTREND, 30 PROF_TXTREND,
32 PROF_TXTCLEAR, 31 PROF_TXTCLEAR,
33 PROF_NUM, 32 PROF_NUM,
33 PROF_END,
34} ProfType; 34} ProfType;
35 35
36char *prof_type_str[PROF_NUM] = { 36char *prof_type_str[PROF_NUM] = {
@@ -50,17 +50,18 @@ u32 prof_frame_time = 0;
50u32 prof_frame_count = 0; 50u32 prof_frame_count = 0;
51u32 prof_frame_avg = 0; 51u32 prof_frame_avg = 0;
52u32 prof_frame_time_max = 0; 52u32 prof_frame_time_max = 0;
53u32 prof_times[PROF_NUM] = {0}; 53u32 prof_times[PROF_END] = {0};
54u32 prof_count[PROF_NUM] = {0}; 54u32 prof_count[PROF_END] = {0};
55u32 prof_avg[PROF_NUM] = {0}; 55u32 prof_avg[PROF_END] = {0};
56u32 prof_max[PROF_NUM] = {0}; 56u32 prof_max[PROF_END] = {0};
57u32 prof_min[PROF_NUM] = {0}; 57u32 prof_min[PROF_END] = {0};
58 58
59bool prof_reset_minmax = PROF_RESET_MINMAX; 59bool prof_reset_minmax = PROF_RESET_MINMAX;
60bool prof_show = true; 60bool prof_show = true;
61u8 prof_detail_level = 2;
61 62
62#define PROF_INIT() do { \ 63#define PROF_INIT() do { \
63 for (size_t i = 0; i < PROF_NUM; i++) { \ 64 for (size_t i = 0; i < PROF_END; i++) { \
64 prof_min[i] = -1; \ 65 prof_min[i] = -1; \
65 } \ 66 } \
66} while(0); 67} while(0);
@@ -80,34 +81,46 @@ bool prof_show = true;
80 profile_start();\ 81 profile_start();\
81} while(0) 82} while(0)
82 83
83
84#define FRAME_END() do { \ 84#define FRAME_END() do { \
85 prof_frame_count++;\ 85 prof_frame_count++;\
86 frame_time = profile_measure();\ 86 frame_time = profile_measure();\
87 prof_frame_time_max = MAX(prof_frame_time_max, frame_time);\ 87 prof_frame_time_max = MAX(prof_frame_time_max, frame_time);\
88 prof_frame_time += profile_stop();\ 88 prof_frame_time += profile_stop();\
89 if (prof_show) { \ 89 if (prof_show) { \
90 draw_filled_rect(0, 0, SCREEN_WIDTH - 1, 8 * (PROF_NUM + 1), 2); \
91 u32 fps = (u64)280896 * 60 / (prof_frame_avg + 1); \ 90 u32 fps = (u64)280896 * 60 / (prof_frame_avg + 1); \
92 if (prof_frame_avg == 0) { \ 91 if (prof_frame_avg == 0) { \
93 fps = 0; \ 92 fps = 0; \
94 } \ 93 } \
95 txt_drawf_small("FRAME TIME/FPS: %.9l/%.2l", 0, 0, COL_FG, \ 94 if (prof_detail_level > 0) {\
96 prof_frame_avg, fps);\ 95 draw_filled_rect(0, 0, SCREEN_WIDTH - 1, 8, 2); \
97 txt_drawf_small("MAX: %.9l/%l", 8 * 19, 0, COL_FG, \ 96 txt_drawf_small("AVG/MAX/VDRAW: %.9l/%.9l/%l FPS: %.3l CPU: %.3l", 0, 0, COL_FG, \
98 prof_frame_time_max, 280896);\ 97 prof_frame_avg, prof_frame_time_max, 280896, fps, (u64)prof_frame_avg * 100 / 280896);\
98 } else { \
99 draw_filled_rect(8 * 25 + 4, 0, SCREEN_WIDTH - 1, 8, 2); \
100 txt_drawf_small("CPU: %.3l", 8 * 25 + 4, 0, COL_FG, \
101 (u64)prof_frame_avg * 100 / 280896);\
102 } \
103 if (prof_detail_level >= 3) {\
104 draw_filled_rect(0, 8, SCREEN_WIDTH - 1, 8 * (PROF_NUM + 1), 2); \
105 } else if (prof_detail_level >= 2) {\
106 draw_filled_rect(0, 8, 8 * 15, 8 * (PROF_NUM + 1), 2); \
107 } \
99 for (size_t idx = 0; idx < PROF_NUM; idx++) { \ 108 for (size_t idx = 0; idx < PROF_NUM; idx++) { \
100 txt_drawf_small("%s %.9l (%.9l %.9l) %08x:%08x", 0, 8 * (idx + 1), COL_FG, \ 109 if (prof_detail_level >= 3) {\
101 prof_type_str[idx], \ 110 txt_drawf_small("%s %.9l (%.9l %.9l) %08x:%08x", 0, 8 * (idx + 1), COL_FG, \
102 prof_avg[idx], \ 111 prof_type_str[idx], \
103 prof_min[idx], \ 112 prof_avg[idx], \
104 prof_max[idx], \ 113 prof_min[idx], \
105 prof_avg[idx], \ 114 prof_max[idx], \
106 prof_max[idx]);\ 115 prof_avg[idx], \
116 prof_max[idx]);\
117 } else if (prof_detail_level >= 2) {\
118 txt_drawf_small("%s %.9l/%.9l", 0, 8 * (idx + 1), COL_FG, \
119 prof_type_str[idx], \
120 prof_avg[idx], \
121 prof_max[idx]);\
122 }\
107 }; \ 123 }; \
108 draw_filled_rect(0, SCREEN_HEIGHT - 9, 58, SCREEN_HEIGHT - 1, 2); \
109 txt_drawf_small("CPU USAGE: %.3l", 0, SCREEN_HEIGHT - 9, COL_FG, \
110 (u64)prof_frame_avg * 100 / 280896);\
111 } \ 124 } \
112 if (prof_frame_count >= PROF_ENABLE) { \ 125 if (prof_frame_count >= PROF_ENABLE) { \
113 for (size_t idx = 0; idx < PROF_NUM; idx++) { \ 126 for (size_t idx = 0; idx < PROF_NUM; idx++) { \
@@ -129,6 +142,10 @@ bool prof_show = true;
129 prof_show ^= 1; \ 142 prof_show ^= 1; \
130} while(0) 143} while(0)
131 144
145#define PROF_DETAIL(N) do { \
146 prof_detail_level = (N); \
147} while(0)
148
132#else 149#else
133 150
134// No profiling. 151// No profiling.
@@ -141,4 +158,5 @@ bool prof_show = true;
141 frame_time = profile_stop();\ 158 frame_time = profile_stop();\
142} while(0) 159} while(0)
143#define PROF_SHOW() 160#define PROF_SHOW()
161#define PROF_DETAIL(N)
144#endif 162#endif