6#include "PR/os_internal_reg.h"
10#define RDP_CYCLE_CONV(x) ((10 * (x)) / 625)
14int profile_buffer_index = -1;
24u32 audio_buffer_index;
26u32 collision_time = 0;
33u32 audio_subset_starts[AUDIO_SUBSET_SIZE];
34u32 audio_subset_tallies[AUDIO_SUBSET_SIZE];
37static void buffer_update(ProfileTimeData* data, u32
new,
int buffer_index) {
38 u32 old = data->counts[buffer_index];
41 data->counts[buffer_index] =
new;
45 u32 cur_time = osGetCount();
47 ProfileTimeData* cur_data = &all_profiling_data[which];
49 diff = cur_time - prev_time - delta;
51 u32 saved = __osDisableInt();
52 u32 cur_preempted_time = preempted_time;
54 __osRestoreInt(saved);
55 if (cur_preempted_time > 0) {
56 diff -= cur_preempted_time;
57 cur_start += cur_preempted_time;
60 buffer_update(cur_data, diff, profile_buffer_index);
65 rsp_pending_times[which] = osGetCount();
70 int cur_index = rsp_buffer_indices[which];
71 u32 time = osGetCount() - rsp_pending_times[which];
72 rsp_pending_times[which] = 0;
74 buffer_update(cur_data, time, cur_index);
79 rsp_buffer_indices[which] = cur_index;
91void profiler_gfx_started() {
92 gfx_start = osGetCount();
104 audio_start = osGetCount();
106#ifdef AUDIO_PROFILING
107 for (s32 i = 0; i < AUDIO_SUBSET_SIZE; i++) {
108 audio_subset_tallies[i] = 0;
115#ifdef PUPPYPRINT_DEBUG
122 collision_time += osGetCount() - time;
126 ProfileTimeData* cur_data = &all_profiling_data[PROFILER_TIME_COLLISION];
127 buffer_update(cur_data, collision_time, profile_buffer_index);
134 return collision_time;
140void profiler_gfx_completed() {
142 u32 time = osGetCount();
143 u32 cur_index = gfx_buffer_index;
145 preempted_time = time - gfx_start;
146 buffer_update(cur_data, time - gfx_start, cur_index);
162 gfx_buffer_index = cur_index;
168 u32 time = osGetCount();
169 u32 cur_index = audio_buffer_index;
171 preempted_time = time - audio_start;
172 buffer_update(cur_data, time - audio_start, cur_index);
174#ifdef AUDIO_PROFILING
177 for (s32 i = 0; i < AUDIO_SUBSET_SIZE; i++) {
179 buffer_update(cur_data, audio_subset_tallies[i], cur_index);
188 audio_buffer_index = cur_index;
191static void update_fps_timer() {
192 u32 diff = cur_start - prev_start;
194 buffer_update(&all_profiling_data[
PROFILER_TIME_FPS], diff, profile_buffer_index);
195 prev_start = cur_start;
198static void update_total_timer() {
199 u32 saved = __osDisableInt();
200 u32 cur_preempted_time = preempted_time;
202 __osRestoreInt(saved);
204 prev_time = cur_start + cur_preempted_time;
208#ifdef PUPPYPRINT_DEBUG
209extern u8 sPPDebugPage;
213static void update_rdp_timers() {
214 u32 tmem = IO_READ(DPC_TMEM_REG);
215 u32 cmd = IO_READ(DPC_BUFBUSY_REG);
216 u32 pipe = IO_READ(DPC_PIPEBUSY_REG);
219 IO_WRITE(DPC_STATUS_REG, (DPC_CLR_CLOCK_CTR | DPC_CLR_CMD_CTR | DPC_CLR_PIPE_CTR | DPC_CLR_TMEM_CTR));
223 buffer_update(&all_profiling_data[
PROFILER_TIME_CMD], cmd, profile_buffer_index);
227float profiler_get_fps() {
231u32 profiler_get_cpu_cycles() {
234 return cpu_normal_time + cpu_audio_time * 2;
237u32 profiler_get_rsp_cycles() {
240 return rsp_graphics_time + rsp_audio_time;
243u32 profiler_get_rdp_cycles() {
248 u32 rdp_max_cycles = MAX(MAX(rdp_pipe_cycles, rdp_tmem_cycles), rdp_cmd_cycles);
256 return cpu_normal_time + cpu_audio_time * 2;
262 return rsp_graphics_time + rsp_audio_time;
270 u32 rdp_max_cycles = MAX(MAX(rdp_pipe_cycles, rdp_tmem_cycles), rdp_cmd_cycles);
277 char text_buffer_labels[196];
278 char text_buffer_time[196];
281 update_total_timer();
284#ifndef PUPPYPRINT_DEBUG
285 static u8 show_profiler = 0;
291#ifdef PUPPYPRINT_DEBUG
292 if (fDebug && sPPDebugPage == PUPPYPRINT_PAGE_PROFILER) {
311 s32 text_buffer_labels_len = sprintf(
315 "CPU\t\t%lu (%lu%%)\n"
326 total_cpu, total_cpu / 333
328 s32 text_buffer_time_len = sprintf(
355 sprintf(&text_buffer_labels[text_buffer_labels_len],
363 sprintf(&text_buffer_time[text_buffer_time_len],
379 sprintf(&text_buffer_labels[text_buffer_labels_len],
382 sprintf(&text_buffer_time[text_buffer_time_len],
393 text_buffer_labels[2] = text_buffer_time[2] = 14;
394 text_buffer_labels[3] = text_buffer_time[3] = 14;
395 draw_msg((s32)&text_buffer_labels, 3, 0, 255, 0, 0);
396 draw_msg((s32)&text_buffer_time, 110, 0, 255, 0, 0);
399 s32 time_offset = 100;
443 s32 time_offset = 50;
444 sprintf(text_buffer_labels,
447 "RDP\t\t\t%lu (%lu%%)\n"
452 "RSP\t\t%lu (%lu%%)\n"
455 max_rdp, max_rdp / 333,
456 total_rsp, total_rsp / 333
458 sprintf(text_buffer_time,
480 text_buffer_labels[2] = text_buffer_time[2] = 14;
481 text_buffer_labels[3] = text_buffer_time[3] = 14;
488 profile_buffer_index++;
492 profile_buffer_index = 0;
495 prev_time = cur_start = osGetCount();
#define profiler_get_cpu_microseconds()
#define profiler_frame_setup()
#define PROFILING_BUFFER_SIZE
#define profiler_update(which, delta)
#define profiler_rsp_resumed()
#define profiler_collision_completed()
u32 gfx_subset_starts[PROFILER_TIME_SUB_GFX_END - PROFILER_TIME_SUB_GFX_START]
@ PROFILER_DELTA_COLLISION
#define profiler_get_rsp_microseconds()
@ PROFILER_TIME_SUB_GFX_HUD_ELEMENTS
@ PROFILE_TIME_WORLD_PLAYER
@ PROFILER_TIME_CONTROLLERS
@ PROFILER_TIME_SUB_GFX_BACK_UI
@ PROFILE_TIME_WORLD_EFFECTS
@ PROFILER_TIME_SUB_GFX_START
@ PROFILER_TIME_RSP_AUDIO
@ PROFILER_TIME_SUB_GFX_ENTITIES
@ PROFILE_TIME_WORLD_ENCOUNTERS
@ PROFILER_TIME_SUB_GFX_FRONT_UI
@ PROFILE_TIME_WORLD_ITEM_ENTITIES
@ PROFILER_TIME_SUB_GFX_WORKERS
@ PROFILER_TIME_SUB_GFX_PLAYER
@ PROFILER_TIME_SUB_GFX_EFFECTS
@ PROFILER_TIME_HUD_ELEMENTS
@ PROFILE_TIME_WORLD_NPCS
@ PROFILER_TIME_SUB_GFX_MODELS
@ PROFILER_TIME_STEP_GAME_MODE
@ PROFILER_TIME_SUB_GFX_RENDER_TASKS
@ PROFILER_TIME_SUB_GFX_NPCS
@ PROFILE_TIME_WORLD_CAMERAS
@ PROFILER_TIME_SUB_GFX_UPDATE
#define profiler_collision_update(time)
#define profiler_rsp_started(which)
u32 gfx_subset_tallies[PROFILER_TIME_SUB_GFX_END - PROFILER_TIME_SUB_GFX_START]
#define profiler_print_times()
#define profiler_rsp_completed(which)
#define PROFILER_DELTA_PUPPYPRINT2
#define profiler_get_delta(which)
#define profiler_audio_completed()
@ PROFILER_TIME_SUB_AUDIO_START
@ PROFILER_TIME_SUB_AUDIO_UPDATE
#define profiler_get_rdp_microseconds()
#define profiler_collision_reset()
#define profiler_audio_started()
#define PROFILER_TIME_PUPPYPRINT1
u8 * dx_string_to_msg(u8 *msg, const u8 *str)
PlayerStatus gPlayerStatus