Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
profiling.c
Go to the documentation of this file.
1// Stolen from HackerSM64
2
3#include "profiling.h"
4#include "dx/utils.h"
5#include "game_modes.h"
6#include "PR/os_internal_reg.h"
7
8#ifdef USE_PROFILER
9
10#define RDP_CYCLE_CONV(x) ((10 * (x)) / 625) // 62.5 million cycles per frame
11
13
16// Holds either the start time if the task is running, or the amount of time the task has run for so far if yielded
27
28#ifdef GFX_PROFILING
31#endif
32#ifdef AUDIO_PROFILING
35#endif
36
37static void buffer_update(ProfileTimeData* data, u32 new, int buffer_index) {
38 u32 old = data->counts[buffer_index];
39 data->total -= old;
40 data->total += new;
41 data->counts[buffer_index] = new;
42}
43
44void profiler_update(enum ProfilerTime which, u32 delta) {
46 u32 diff;
48
49 diff = cur_time - prev_time - delta;
50
55 if (cur_preempted_time > 0) {
58 }
59
62}
63
66}
67
73
75 cur_index++;
77 cur_index = 0;
78 }
80}
81
84}
85
86// This ends up being the same math as resumed, so we just use resumed for both
87// void profiler_rsp_yielded() {
88// rsp_pending_times[PROFILER_RSP_GFX] = osGetCount() - rsp_pending_times[PROFILER_RSP_GFX];
89// }
90
93
94#ifdef GFX_PROFILING
95 for (s32 i = 0; i < GFX_SUBSET_SIZE; i++) {
96 gfx_subset_tallies[i] = 0;
97 }
98
100#endif
101}
102
105
106#ifdef AUDIO_PROFILING
107 for (s32 i = 0; i < AUDIO_SUBSET_SIZE; i++) {
109 }
110
112#endif
113}
114
115#ifdef PUPPYPRINT_DEBUG
116
118 collision_time = 0;
119}
120
122 collision_time += osGetCount() - time;
123}
124
128}
129
130#endif
131
134 return collision_time;
135 } else {
136 return 0;
137 }
138}
139
142 u32 time = osGetCount();
144
145 preempted_time = time - gfx_start;
147
148#ifdef GFX_PROFILING
150
151 for (s32 i = 0; i < GFX_SUBSET_SIZE; i++) {
154 }
155#endif
156
157 cur_index++;
159 cur_index = 0;
160 }
161
163}
164
165
168 u32 time = osGetCount();
170
173
174#ifdef AUDIO_PROFILING
176
177 for (s32 i = 0; i < AUDIO_SUBSET_SIZE; i++) {
180 }
181#endif
182
183 cur_index++;
185 cur_index = 0;
186 }
187
189}
190
191static void update_fps_timer() {
193
196}
197
198static void update_total_timer() {
201 preempted_time = 0;
203
206}
207
208#ifdef PUPPYPRINT_DEBUG
209extern u8 sPPDebugPage;
210extern u8 fDebug;
211#endif
212
213static void update_rdp_timers() {
217
218 if (gGameStatus.frameCounter > 5) {
220 }
221
225}
226
227float profiler_get_fps() {
229}
230
234 return cpu_normal_time + cpu_audio_time * 2;
235}
236
241}
242
247
249
251}
252
256 return cpu_normal_time + cpu_audio_time * 2;
257}
258
263}
264
269
271
273}
274
277 char text_buffer_labels[196];
278 char text_buffer_time[196];
279
283
284#ifndef PUPPYPRINT_DEBUG
285 static u8 show_profiler = 0;
287 show_profiler ^= 1;
288 }
289#endif
290
291#ifdef PUPPYPRINT_DEBUG
293#else
294 if (show_profiler) {
295#endif
296 for (int i = 0; i < PROFILER_TIME_COUNT; i++) {
297 if (i < PROFILER_TIME_TMEM) {
299 } else {
301 }
302 }
303
304 // audio time is removed from the main thread profiling, so add it back here
306#ifndef GFX_PROFILING
309#endif
310
313 " " // space for prepend
314 "FPS: %5.2f\n"
315 "CPU\t\t%lu (%lu%%)\n"
316 " Input\n"
317 " Workers\n"
318 " Triggers\n"
319 " EVT\n"
320 " Messages\n"
321 " HUD elements\n"
322 " Entities\n"
323 " Gfx\n"
324 " Audio\n",
325 1000000.0f / microseconds[PROFILER_TIME_FPS],
326 total_cpu, total_cpu / 333
327 );
330 " " // space for prepend
331 "\n"
332 "\n"
333 "%lu\n"
334 "%lu\n"
335 "%lu\n"
336 "%lu\n"
337 "%lu\n"
338 "%lu\n"
339 "%lu\n"
340 "%lu\n"
341 "%lu\n",
350 microseconds[PROFILER_TIME_AUDIO] * 2 // audio is 60Hz, so double the average
351 );
352
353 switch (get_game_mode()) {
354 case GAME_MODE_WORLD:
356 " Encounters\n"
357 " NPCs\n"
358 " Player\n"
359 " Item entities\n"
360 " Effects\n"
361 " Cameras\n"
362 );
364 "%lu\n"
365 "%lu\n"
366 "%lu\n"
367 "%lu\n"
368 "%lu\n"
369 "%lu\n",
376 );
377 break;
378 default:
380 " Game mode step\n"
381 );
383 "%lu\n",
385 );
386 break;
387 }
388
395 draw_msg((s32)&text_buffer_labels, 3, 0, 255, 0, 0);
396 draw_msg((s32)&text_buffer_time, 110, 0, 255, 0, 0);
397
398#ifdef GFX_PROFILING
399 s32 time_offset = 100;
400 sprintf(
402 " " // space for prepend
403 "\n"
404 "Gfx breakdown\n"
405 " Entities\n"
406 " Models\n"
407 " Player\n"
408 " Workers\n"
409 " NPCs\n"
410 " Effects\n"
411 " Render tasks\n"
412 " Hud elements\n"
413 " Back UI\n"
414 " Front UI\n"
415 );
416 sprintf(
418 " " // space for prepend
419 "\n"
420 "\n"
421 "%lu\n"
422 "%lu\n"
423 "%lu\n"
424 "%lu\n"
425 "%lu\n"
426 "%lu\n"
427 "%lu\n"
428 "%lu\n"
429 "%lu\n"
430 "%lu\n",
441 );
442#else
443 s32 time_offset = 50;
445 " " // space for prepend
446 "\n"
447 "RDP\t\t\t%lu (%lu%%)\n"
448 " Tmem\n"
449 " Cmd\n"
450 " Pipe\n"
451 "\n"
452 "RSP\t\t%lu (%lu%%)\n"
453 " Gfx\n"
454 " Audio\n",
455 max_rdp, max_rdp / 333,
456 total_rsp, total_rsp / 333
457 );
459 " " // space for prepend
460 "\n"
461 "\n"
462 "%lu\n"
463 "%lu\n"
464 "%lu\n"
465 "\n"
466 "\n"
467 "%lu\n"
468 "%lu\n",
474 );
475#endif
482 draw_msg((s32)&text_buffer_labels, SCREEN_WIDTH/2, 0, 255, 0, 0);
483 draw_msg((s32)&text_buffer_time, SCREEN_WIDTH/2 + time_offset, 0, 255, 0, 0);
484 }
485}
486
489 preempted_time = 0;
490
493 }
494
496}
497
498#endif
BSS s32 PopupMenu_SelectedIndex
#define draw_msg
@ MSG_READ_FUNC_SIZE
Definition enums.h:6094
@ MSG_CHAR_READ_FUNCTION
Definition enums.h:6057
s32 get_game_mode(void)
Definition game_modes.c:123
@ GAME_MODE_WORLD
Definition game_modes.h:12
#define profiler_get_cpu_microseconds()
Definition profiling.h:170
#define profiler_frame_setup()
Definition profiling.h:159
ProfilerRSPTime
Definition profiling.h:97
@ PROFILER_RSP_COUNT
Definition profiling.h:100
@ PROFILER_RSP_GFX
Definition profiling.h:98
#define PROFILING_BUFFER_SIZE
Definition profiling.h:21
#define profiler_update(which, delta)
Definition profiling.h:157
#define profiler_rsp_resumed()
Definition profiling.h:162
#define profiler_collision_completed()
Definition profiling.h:167
u32 gfx_subset_starts[PROFILER_TIME_SUB_GFX_END - PROFILER_TIME_SUB_GFX_START]
ProfilerDeltaTime
Definition profiling.h:103
@ PROFILER_DELTA_COLLISION
Definition profiling.h:104
#define profiler_get_rsp_microseconds()
Definition profiling.h:171
ProfilerTime
Definition profiling.h:52
@ PROFILER_TIME_CMD
Definition profiling.h:84
@ PROFILER_TIME_TMEM
Definition profiling.h:82
@ PROFILER_TIME_SUB_GFX_HUD_ELEMENTS
Definition profiling.h:67
@ PROFILER_TIME_TOTAL
Definition profiling.h:79
@ PROFILE_TIME_WORLD_PLAYER
Definition profiling.h:89
@ PROFILER_TIME_CONTROLLERS
Definition profiling.h:54
@ PROFILER_TIME_SUB_GFX_BACK_UI
Definition profiling.h:67
@ PROFILER_TIME_PIPE
Definition profiling.h:83
@ PROFILER_TIME_FPS
Definition profiling.h:53
@ PROFILER_TIME_ENTITIES
Definition profiling.h:61
@ PROFILE_TIME_WORLD_EFFECTS
Definition profiling.h:91
@ PROFILER_TIME_GFX
Definition profiling.h:68
@ PROFILER_TIME_SUB_GFX_START
Definition profiling.h:67
@ PROFILER_TIME_RSP_AUDIO
Definition profiling.h:81
@ PROFILER_TIME_SUB_GFX_ENTITIES
Definition profiling.h:67
@ PROFILER_TIME_MESSAGES
Definition profiling.h:58
@ PROFILE_TIME_WORLD_ENCOUNTERS
Definition profiling.h:87
@ PROFILER_TIME_SUB_GFX_FRONT_UI
Definition profiling.h:67
@ PROFILE_TIME_WORLD_ITEM_ENTITIES
Definition profiling.h:90
@ PROFILER_TIME_SUB_GFX_WORKERS
Definition profiling.h:67
@ PROFILER_TIME_SUB_GFX_PLAYER
Definition profiling.h:67
@ PROFILER_TIME_SUB_GFX_EFFECTS
Definition profiling.h:67
@ PROFILER_TIME_HUD_ELEMENTS
Definition profiling.h:59
@ PROFILE_TIME_WORLD_NPCS
Definition profiling.h:88
@ PROFILER_TIME_TRIGGERS
Definition profiling.h:56
@ PROFILER_TIME_COUNT
Definition profiling.h:94
@ PROFILER_TIME_RSP_GFX
Definition profiling.h:80
@ PROFILER_TIME_SUB_GFX_MODELS
Definition profiling.h:67
@ PROFILER_TIME_STEP_GAME_MODE
Definition profiling.h:60
@ PROFILER_TIME_SUB_GFX_RENDER_TASKS
Definition profiling.h:67
@ PROFILER_TIME_WORKERS
Definition profiling.h:55
@ PROFILER_TIME_EVT
Definition profiling.h:57
@ PROFILER_TIME_SUB_GFX_NPCS
Definition profiling.h:67
@ PROFILE_TIME_WORLD_CAMERAS
Definition profiling.h:92
@ PROFILER_TIME_AUDIO
Definition profiling.h:77
@ PROFILER_TIME_SUB_GFX_UPDATE
Definition profiling.h:67
#define profiler_collision_update(time)
Definition profiling.h:168
#define GFX_SUBSET_SIZE
Definition profiling.h:176
#define profiler_rsp_started(which)
Definition profiling.h:160
u32 gfx_subset_tallies[PROFILER_TIME_SUB_GFX_END - PROFILER_TIME_SUB_GFX_START]
#define profiler_print_times()
Definition profiling.h:158
#define profiler_rsp_completed(which)
Definition profiling.h:161
#define PROFILER_DELTA_PUPPYPRINT2
Definition profiling.h:115
#define profiler_get_delta(which)
Definition profiling.h:169
#define profiler_audio_completed()
Definition profiling.h:164
@ PROFILER_TIME_SUB_AUDIO_START
Definition profiling.h:276
@ PROFILER_TIME_SUB_AUDIO_UPDATE
Definition profiling.h:276
#define profiler_get_rdp_microseconds()
Definition profiling.h:172
#define profiler_collision_reset()
Definition profiling.h:166
#define profiler_audio_started()
Definition profiling.h:163
#define PROFILER_TIME_PUPPYPRINT1
Definition profiling.h:112
#define SCREEN_WIDTH
Definition macros.h:109
u8 * dx_string_to_msg(u8 *msg, const char *str)
Definition utils.c:16
GameStatus gGameStatus
Definition main_loop.c:21
PlayerStatus gPlayerStatus
Definition 77480.c:39