Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
profiling.h
Go to the documentation of this file.
1// Stolen from HackerSM64
2
3#ifndef __PROFILING_H__
4#define __PROFILING_H__
5
6#include "common.h"
7#include "dx/config.h"
8
9#if defined(USE_PROFILER) && defined(PUPPYPRINT_DEBUG)
13#define AUDIO_PROFILING
14#endif
15
17#define GFX_PROFILING
18
19#define OS_GET_COUNT_INLINE(x) asm volatile("mfc0 %0, $9" : "=r"(x): )
20
21#define PROFILING_BUFFER_SIZE 64
22
23#define AUDIO_SUBSET_ENTRIES \
24 PROFILER_TIME_SUB_AUDIO_START, \
25 PROFILER_TIME_SUB_AUDIO_SEQUENCES = PROFILER_TIME_SUB_AUDIO_START, \
26 PROFILER_TIME_SUB_AUDIO_SEQUENCES_SCRIPT, \
27 PROFILER_TIME_SUB_AUDIO_SEQUENCES_RECLAIM, \
28 PROFILER_TIME_SUB_AUDIO_SEQUENCES_PROCESSING, \
29 PROFILER_TIME_SUB_AUDIO_SYNTHESIS, \
30 PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING, \
31 PROFILER_TIME_SUB_AUDIO_SYNTHESIS_ENVELOPE_REVERB, \
32 PROFILER_TIME_SUB_AUDIO_SYNTHESIS_DMA, \
33 PROFILER_TIME_SUB_AUDIO_UPDATE, \
34 PROFILER_TIME_SUB_AUDIO_END
35
36#define GFX_SUBSET_ENTRIES \
37 PROFILER_TIME_SUB_GFX_START, \
38 PROFILER_TIME_SUB_GFX_UPDATE, \
39 PROFILER_TIME_SUB_GFX__DUMMY, /* fixes entities for some reason */ \
40 PROFILER_TIME_SUB_GFX_ENTITIES, \
41 PROFILER_TIME_SUB_GFX_MODELS, \
42 PROFILER_TIME_SUB_GFX_PLAYER, \
43 PROFILER_TIME_SUB_GFX_NPCS, \
44 PROFILER_TIME_SUB_GFX_WORKERS, \
45 PROFILER_TIME_SUB_GFX_EFFECTS, \
46 PROFILER_TIME_SUB_GFX_RENDER_TASKS, \
47 PROFILER_TIME_SUB_GFX_HUD_ELEMENTS, \
48 PROFILER_TIME_SUB_GFX_BACK_UI, \
49 PROFILER_TIME_SUB_GFX_FRONT_UI, \
50 PROFILER_TIME_SUB_GFX_END
51
96
102
110
111#ifndef PUPPYPRINT_DEBUG
112#define PROFILER_TIME_PUPPYPRINT1 0
113#define PROFILER_TIME_PUPPYPRINT2 0
114#define PROFILER_DELTA_PUPPYPRINT1 0
115#define PROFILER_DELTA_PUPPYPRINT2 0
116#endif
117
118#ifdef USE_PROFILER
119typedef struct {
120 u32 counts[PROFILING_BUFFER_SIZE];
121 u32 total;
122} ProfileTimeData;
123extern ProfileTimeData all_profiling_data[PROFILER_TIME_COUNT];
124
125void profiler_update(enum ProfilerTime which, u32 delta);
131void profiler_gfx_started();
132void profiler_gfx_completed();
135#ifdef PUPPYPRINT_DEBUG
138void profiler_collision_update(u32 time);
139#else
140#define profiler_collision_reset()
141#define profiler_collision_completed()
142#define profiler_collision_update(time)
143#endif
148// See profiling.c to see why profiler_rsp_yielded isn't its own function
151#define PROFILER_GET_SNAPSHOT() u32 first = osGetCount()
152#define PROFILER_GET_SNAPSHOT_TYPE(type) u32 first = profiler_get_delta(type)
153}
154#else
155#define PROFILER_GET_SNAPSHOT()
156#define PROFILER_GET_SNAPSHOT_TYPE(type)
157#define profiler_update(which, delta)
158#define profiler_print_times()
159#define profiler_frame_setup()
160#define profiler_rsp_started(which)
161#define profiler_rsp_completed(which)
162#define profiler_rsp_resumed()
163#define profiler_audio_started()
164#define profiler_audio_completed()
165#define profiler_rsp_yielded()
166#define profiler_collision_reset()
167#define profiler_collision_completed()
168#define profiler_collision_update(time)
169#define profiler_get_delta(which) 0
170#define profiler_get_cpu_microseconds() 0
171#define profiler_get_rsp_microseconds() 0
172#define profiler_get_rdp_microseconds() 0
173#endif
174
175#ifdef GFX_PROFILING
176#define GFX_SUBSET_SIZE PROFILER_TIME_SUB_GFX_END - PROFILER_TIME_SUB_GFX_START
179
180static ALWAYS_INLINE void profiler_gfx_subset_switch_func(enum ProfilerTime complete, enum ProfilerTime start) {
181 u32 time;
183
184 gfx_subset_tallies[complete] += time - gfx_subset_starts[complete];
185 gfx_subset_starts[start] = time;
186}
187
188static ALWAYS_INLINE void profiler_gfx_subset_complete_and_switch_func(enum ProfilerTime complete1, enum ProfilerTime complete2, enum ProfilerTime start) {
189 u32 time;
191
192 gfx_subset_tallies[complete1] += time - gfx_subset_starts[complete1];
193 gfx_subset_tallies[complete2] += time - gfx_subset_starts[complete2];
194 gfx_subset_starts[start] = time;
195}
196
197static ALWAYS_INLINE void profiler_gfx_subset_start_shared_func(enum ProfilerTime first, enum ProfilerTime new) {
199}
200
201static ALWAYS_INLINE void profiler_gfx_subset_start_func(enum ProfilerTime index) {
203}
204
205static ALWAYS_INLINE void profiler_gfx_subset_complete_func(enum ProfilerTime index) {
206 u32 time;
208
209 gfx_subset_tallies[index] += time - gfx_subset_starts[index];
210}
211
212#define GFX_PROFILER_SWITCH(complete, begin) profiler_gfx_subset_switch_func(complete - PROFILER_TIME_SUB_GFX_START, begin - PROFILER_TIME_SUB_GFX_START)
213#define GFX_PROFILER_COMPLETE_AND_SWITCH(complete1, complete2, begin) profiler_gfx_subset_complete_and_switch_func(complete1 - PROFILER_TIME_SUB_GFX_START, \
214 complete2 - PROFILER_TIME_SUB_GFX_START, begin - PROFILER_TIME_SUB_GFX_START)
215#define GFX_PROFILER_START_SHARED(first, new) profiler_gfx_subset_start_shared_func(first - PROFILER_TIME_SUB_GFX_START, new - PROFILER_TIME_SUB_GFX_START)
216#define GFX_PROFILER_START(which) profiler_gfx_subset_start_func(which - PROFILER_TIME_SUB_GFX_START)
217#define GFX_PROFILER_COMPLETE(which) profiler_gfx_subset_complete_func(which - PROFILER_TIME_SUB_GFX_START)
218#else
219enum ProfilerTimeGFXUnused {
221};
222#define GFX_PROFILER_SWITCH(complete, begin)
223#define GFX_PROFILER_COMPLETE_AND_SWITCH(complete1, complete2, begin)
224#define GFX_PROFILER_START_SHARED(first, new)
225#define GFX_PROFILER_START(which)
226#define GFX_PROFILER_COMPLETE(which)
227#endif
228
229#ifdef AUDIO_PROFILING
230#define AUDIO_SUBSET_SIZE PROFILER_TIME_SUB_AUDIO_END - PROFILER_TIME_SUB_AUDIO_START
231extern u32 audio_subset_starts[AUDIO_SUBSET_SIZE];
232extern u32 audio_subset_tallies[AUDIO_SUBSET_SIZE];
233
234static ALWAYS_INLINE void profiler_audio_subset_switch_func(enum ProfilerTime complete, enum ProfilerTime start) {
235 u32 time;
237
238 audio_subset_tallies[complete] += time - audio_subset_starts[complete];
239 audio_subset_starts[start] = time;
240}
241
242static ALWAYS_INLINE void profiler_audio_subset_complete_and_switch_func(enum ProfilerTime complete1, enum ProfilerTime complete2, enum ProfilerTime start) {
243 u32 time;
245
246 audio_subset_tallies[complete1] += time - audio_subset_starts[complete1];
247 audio_subset_tallies[complete2] += time - audio_subset_starts[complete2];
248 audio_subset_starts[start] = time;
249}
250
251static ALWAYS_INLINE void profiler_audio_subset_start_shared_func(enum ProfilerTime first, enum ProfilerTime new) {
252 audio_subset_starts[new] = audio_subset_starts[first];
253}
254
255static ALWAYS_INLINE void profiler_audio_subset_start_func(enum ProfilerTime index) {
256 OS_GET_COUNT_INLINE(audio_subset_starts[index]);
257}
258
259static ALWAYS_INLINE void profiler_audio_subset_complete_func(enum ProfilerTime index) {
260 u32 time;
262
263 audio_subset_tallies[index] += time - audio_subset_starts[index];
264}
265
266#define AUDIO_PROFILER_SWITCH(complete, begin) profiler_audio_subset_switch_func(complete - PROFILER_TIME_SUB_AUDIO_START, begin - PROFILER_TIME_SUB_AUDIO_START)
267#define AUDIO_PROFILER_COMPLETE_AND_SWITCH(complete1, complete2, begin) profiler_audio_subset_complete_and_switch_func(complete1 - PROFILER_TIME_SUB_AUDIO_START, \
268 complete2 - PROFILER_TIME_SUB_AUDIO_START, begin - PROFILER_TIME_SUB_AUDIO_START)
269#define AUDIO_PROFILER_START_SHARED(first, new) profiler_audio_subset_start_shared_func(first - PROFILER_TIME_SUB_AUDIO_START, new - PROFILER_TIME_SUB_AUDIO_START)
270
271// These two are unused by the default audio profiler; left in for cases of manual profiling of smaller functions as needed
272#define AUDIO_PROFILER_START(which) profiler_audio_subset_start_func(which - PROFILER_TIME_SUB_AUDIO_START)
273#define AUDIO_PROFILER_COMPLETE(which) profiler_audio_subset_complete_func(which - PROFILER_TIME_SUB_AUDIO_START)
274#else // AUDIO_PROFILING
278#define AUDIO_PROFILER_SWITCH(complete, begin)
279#define AUDIO_PROFILER_COMPLETE_AND_SWITCH(complete1, complete2, begin)
280#define AUDIO_PROFILER_START_SHARED(first, new)
281
282// These two are unused by the default audio profiler; left in for cases of manual profiling of smaller functions as needed
283#define AUDIO_PROFILER_START(which)
284#define AUDIO_PROFILER_COMPLETE(which)
285#endif // AUDIO_PROFILING
286
287#endif
#define profiler_get_cpu_microseconds()
Definition profiling.h:170
#define AUDIO_SUBSET_ENTRIES
Definition profiling.h:23
#define profiler_frame_setup()
Definition profiling.h:159
ProfilerRSPTime
Definition profiling.h:97
@ PROFILER_RSP_COUNT
Definition profiling.h:100
@ PROFILER_RSP_AUDIO
Definition profiling.h:99
@ 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]
#define PROFILER_DELTA_PUPPYPRINT1
Definition profiling.h:114
ProfilerDeltaTime
Definition profiling.h:103
@ PROFILER_DELTA_COLLISION
Definition profiling.h:104
#define profiler_get_rsp_microseconds()
Definition profiling.h:171
#define PROFILER_TIME_PUPPYPRINT2
Definition profiling.h:113
ProfilerTime
Definition profiling.h:52
@ PROFILER_TIME_CMD
Definition profiling.h:84
@ PROFILER_TIME_TMEM
Definition profiling.h:82
@ PROFILER_TIME_TOTAL
Definition profiling.h:79
@ PROFILE_TIME_WORLD_PLAYER
Definition profiling.h:89
@ PROFILER_TIME_CONTROLLERS
Definition profiling.h:54
@ 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_RSP_AUDIO
Definition profiling.h:81
@ PROFILER_TIME_MESSAGES
Definition profiling.h:58
@ PROFILE_TIME_WORLD_ENCOUNTERS
Definition profiling.h:87
@ PROFILE_TIME_WORLD_ITEM_ENTITIES
Definition profiling.h:90
@ PROFILER_TIME_HUD_ELEMENTS
Definition profiling.h:59
@ PROFILE_TIME_WORLD_NPCS
Definition profiling.h:88
@ PROFILER_TIME_SUB_GFX_END
Definition profiling.h:67
@ PROFILER_TIME_TRIGGERS
Definition profiling.h:56
@ PROFILER_TIME_COUNT
Definition profiling.h:94
@ PROFILER_TIME_RSP_GFX
Definition profiling.h:80
@ PROFILER_TIME_STEP_GAME_MODE
Definition profiling.h:60
@ PROFILER_TIME_WORKERS
Definition profiling.h:55
@ PROFILER_TIME_EVT
Definition profiling.h:57
@ PROFILE_TIME_WORLD_CAMERAS
Definition profiling.h:92
@ PROFILER_TIME_AUDIO
Definition profiling.h:77
#define OS_GET_COUNT_INLINE(x)
Definition profiling.h:19
#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 GFX_SUBSET_ENTRIES
Definition profiling.h:36
#define profiler_get_delta(which)
Definition profiling.h:169
#define profiler_audio_completed()
Definition profiling.h:164
ProfilerTimeAudioUnused
Definition profiling.h:275
@ PROFILER_TIME_SUB_AUDIO_END
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 profiler_rsp_yielded()
Definition profiling.h:165
#define ALWAYS_INLINE
Definition macros.h:551