aboutsummaryrefslogtreecommitdiffstats
path: root/src/profiling.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/profiling.c')
-rw-r--r--src/profiling.c95
1 files changed, 64 insertions, 31 deletions
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