Debian Codegraph @

rtperformance/rtperformance.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef RUN_TIME_PROFILING_
20 #define RUN_TIME_PROFILING_cxx . . $ `rtperformance/rtperformance.h:20:9`!
21
22 #include <cstdint>
23
24 // uncomment the following if you want to enable Run-time Profiling
25 #ifndef RELEASE
26 #define USE_RTPcxx . . $ `rtperformance/rtperformance.h:26:9`!
27 #endif
28
29 #if defined(POSIXcxx . . $ `<built-in>:477:9`!)
30 // #if defined(POSIX)
31 #ifdef USE_RTPcxx . . $ `rtperformance/rtperformance.h:26:9`!
32 #undef USE_RTPcxx . . $ `rtperformance/rtperformance.h:26:9`! // no rtp for now
33 #endif
34 #endif
35
36 // use INT64 for 64bit integers
37 #ifdef USE_RTP
38 #if defined(POSIX)
39 #define INT64 int64_t
40 #else
41 #define INT64 signed __int64
42 #endif
43 #else
44 #define INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! uint8_t
45 #endif
46
47
48 // struct of information to be saved per frame (note: use INT64 for timer info)
49 // -----------------------------------------------------------------------------------
50 struct tRTFrameInfocxx . . $ tRTFrameInfo# {
51 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! frame_numcxx . . $ tRTFrameInfo#frame_num.; // the frame number, used internally
52 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! renderframe_timecxx . . $ tRTFrameInfo#renderframe_time.;
53 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! multiframe_timecxx . . $ tRTFrameInfo#multiframe_time.;
54 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! musicframe_timecxx . . $ tRTFrameInfo#musicframe_time.;
55 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! ambsound_frame_timecxx . . $ tRTFrameInfo#ambsound_frame_time.;
56 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! weatherframe_timecxx . . $ tRTFrameInfo#weatherframe_time.;
57 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! playerframe_timecxx . . $ tRTFrameInfo#playerframe_time.;
58 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! doorframe_timecxx . . $ tRTFrameInfo#doorframe_time.;
59 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! levelgoal_timecxx . . $ tRTFrameInfo#levelgoal_time.;
60 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! matcenframe_timecxx . . $ tRTFrameInfo#matcenframe_time.;
61 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! objframe_timecxx . . $ tRTFrameInfo#objframe_time.;
62 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! aiframeall_timecxx . . $ tRTFrameInfo#aiframeall_time.;
63 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! processkeys_timecxx . . $ tRTFrameInfo#processkeys_time.;
64 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! normalevent_timecxx . . $ tRTFrameInfo#normalevent_time.;
65 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! ct_flying_timecxx . . $ tRTFrameInfo#ct_flying_time.;
66 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! ct_aidoframe_timecxx . . $ tRTFrameInfo#ct_aidoframe_time.;
67 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! ct_weaponframe_timecxx . . $ tRTFrameInfo#ct_weaponframe_time.;
68 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! ct_explosionframe_timecxx . . $ tRTFrameInfo#ct_explosionframe_time.;
69 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! ct_debrisframe_timecxx . . $ tRTFrameInfo#ct_debrisframe_time.;
70 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! ct_splinterframe_timecxx . . $ tRTFrameInfo#ct_splinterframe_time.;
71 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! mt_physicsframe_timecxx . . $ tRTFrameInfo#mt_physicsframe_time.;
72 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! mt_walkingframe_timecxx . . $ tRTFrameInfo#mt_walkingframe_time.;
73 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! mt_shockwave_timecxx . . $ tRTFrameInfo#mt_shockwave_time.;
74 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! obj_doeffect_timecxx . . $ tRTFrameInfo#obj_doeffect_time.;
75 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! obj_move_player_timecxx . . $ tRTFrameInfo#obj_move_player_time.;
76 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! obj_d3xint_timecxx . . $ tRTFrameInfo#obj_d3xint_time.;
77 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! obj_objlight_timecxx . . $ tRTFrameInfo#obj_objlight_time.;
78 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! cycle_animcxx . . $ tRTFrameInfo#cycle_anim.;
79 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! vis_eff_movecxx . . $ tRTFrameInfo#vis_eff_move.;
80 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! phys_linkcxx . . $ tRTFrameInfo#phys_link.;
81 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! obj_do_frmcxx . . $ tRTFrameInfo#obj_do_frm.;
82 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! fvi_timecxx . . $ tRTFrameInfo#fvi_time.;
83
84 int texture_uploadscxx . . $ tRTFrameInfo#texture_uploads.;
85 int polys_drawncxx . . $ tRTFrameInfo#polys_drawn.;
86 int fvi_callscxx . . $ tRTFrameInfo#fvi_calls.;
87 float frame_timecxx . . $ tRTFrameInfo#frame_time.; // how long the frame took. A float because it's already calc'd so we might as well save it
88 };
89
90 // Flags for Runtime Performance Counters (these are 64 bit)
91 // --------------------------------------------------------------------
92 #define RTI_FRAMETIMEcxx . . $ `rtperformance/rtperformance.h:92:9`! 0x00000001
93 #define RTI_RENDERFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:93:9`! 0x00000002
94 #define RTI_MULTIFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:94:9`! 0x00000004
95 #define RTI_MUSICFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:95:9`! 0x00000008
96 #define RTI_AMBSOUNDFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:96:9`! 0x00000010
97 #define RTI_WEATHERFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:97:9`! 0x00000020
98 #define RTI_PLAYERFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:98:9`! 0x00000040
99 #define RTI_DOORFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:99:9`! 0x00000080
100 #define RTI_LEVELGOALTIMEcxx . . $ `rtperformance/rtperformance.h:100:9`! 0x00000100
101 #define RTI_MATCENFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:101:9`! 0x00000200
102 #define RTI_OBJFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:102:9`! 0x00000400
103 #define RTI_AIFRAMETIMEcxx . . $ `rtperformance/rtperformance.h:103:9`! 0x00000800
104 #define RTI_PROCESSKEYTIMEcxx . . $ `rtperformance/rtperformance.h:104:9`! 0x00001000
105 #define RTI_TEXTUREUPLOADScxx . . $ `rtperformance/rtperformance.h:105:9`! 0x00002000
106 #define RTI_POLYSDRAWNcxx . . $ `rtperformance/rtperformance.h:106:9`! 0x00004000
107
108 // Macros to be used internally and externally
109 // --------------------------------------------------
110
111 #ifndef USE_RTP
112
113 #define RTP_CLOCKTOSECONDScxx . . $ `rtperformance/rtperformance.h:113:9`!(c1, c2, t)
114 #define RTP_CLOCKSECONDScxx . . $ `rtperformance/rtperformance.h:114:9`!(c, t)
115 #define RTP_RECORDVALUEcxx . . $ `rtperformance/rtperformance.h:115:9`!(member, value)
116 #define RTP_INCRVALUEcxx . . $ `rtperformance/rtperformance.h:116:9`!(member, amount)
117 #define RTP_DECRVALUEcxx . . $ `rtperformance/rtperformance.h:117:9`!(member, amount)
118 #define RTP_GETVALUEcxx . . $ `rtperformance/rtperformance.h:118:9`!(member, value)
119 #define RTP_STARTTIMEcxx . . $ `rtperformance/rtperformance.h:119:9`!(member)
120 #define RTP_tSTARTTIMEcxx . . $ `rtperformance/rtperformance.h:120:9`!(member, time)
121 #define RTP_ENDTIMEcxx . . $ `rtperformance/rtperformance.h:121:9`!(member)
122 #define RTP_tENDTIMEcxx . . $ `rtperformance/rtperformance.h:122:9`!(member, time)
123 #define RTP_GETCLOCKcxx . . $ `rtperformance/rtperformance.h:123:9`!(time)
124 #define RTP_STARTINCTIMEcxx . . $ `rtperformance/rtperformance.h:124:9`!(member)
125 #define RTP_ENDINCTIMEcxx . . $ `rtperformance/rtperformance.h:125:9`!(member)
126 #define RTP_ENABLEFLAGScxx . . $ `rtperformance/rtperformance.h:126:9`!(flags)
127 #define RTP_DISABLEFLAGScxx . . $ `rtperformance/rtperformance.h:127:9`!(flags)
128
129 #else
130
131 #define RTP_ENABLEFLAGS(flags) rtp_EnableFlags(flags)
132
133 #define RTP_DISABLEFLAGS(flags) rtp_EnableFlags(flags)
134
135 // given 2 clocks (INT64's) it will return the time in seconds between them (double)
136 // (internal use)
137 // c1 = start time
138 // c2 = end time
139 // t = time in seconds
140 #define RTP_CLOCKTOSECONDS(c1, c2, t) \
141 do { \
142 if (Runtime_performance_enabled) { \
143 INT64 diff = (c2) - (c1); \
144 t = ((double)diff) / ((double)Runtime_performance_clockfreq); \
145 } \
146 } while (0)
147
148 // given a clock time, it will convert it to seconds
149 #define RTP_CLOCKSECONDS(c, t) \
150 do { \
151 if (Runtime_performance_enabled) { \
152 t = ((double)c) / ((double)Runtime_performance_clockfreq); \
153 } \
154 } while (0)
155
156 // sets a value of a member of the current tRTFrameInfo frame
157 // (external use)
158 // member = the member of the tRTFrameInfo to set
159 // value = the value to set it to
160 #define RTP_RECORDVALUE(member, value) \
161 do { \
162 if (Runtime_performance_enabled) { \
163 RTP_SingleFrame.member = (value); \
164 } \
165 } while (0)
166
167 // increments a value of a member of the current tRTFrameInfo frame
168 // (external use)
169 // member = the member of the tRTFrameInfo to increment
170 // amount = how much to increment it
171 #define RTP_INCRVALUE(member, amount) \
172 do { \
173 if (Runtime_performance_enabled) { \
174 RTP_SingleFrame.member += (amount); \
175 } \
176 } while (0)
177
178 // decrements a value of a member of the current tRTFrameInfo frame
179 // (external use)
180 // member = the member of the tRTFrameInfo to decrement
181 // amount = how much to decrement it
182 #define RTP_DECRVALUE(member, amount) \
183 do { \
184 if (Runtime_performance_enabled) { \
185 RTP_SingleFrame.member -= (amount); \
186 } \
187 } while (0)
188
189 // returns the value of a member of the current tRTFrameInfo frame
190 // (external use)
191 // member = the member to retrieve
192 // value = where to store the value
193 #define RTP_GETVALUE(member, value) \
194 do { \
195 if (Runtime_performance_enabled) { \
196 value = RTP_SingleFrame.member; \
197 } \
198 } while (0)
199
200 // starts a frame time calculation for a time member of the tRTFrameInfo frame
201 // this version calls the clock to get the current time
202 // member = member to start recording time on
203 #define RTP_STARTTIME(member) \
204 do { \
205 if (Runtime_performance_enabled) { \
206 RTP_SingleFrame.member = rtp_GetClock(); \
207 } \
208 } while (0)
209
210 // starts a frame time calculation given a time to start it with (similar to the above
211 // except you give it the starting time). This should be used (along with
212 // RTP_tENDTIME(member,time)) in places where you do a bunch of frame times in a row
213 // to reduce the number of calls to rtp_GetClock(), however, this way will give
214 // a few cycles off, compared to the RTP_STARTTIME(member)/RTP_ENDTIME(member) way
215 // member = member to start recording time on
216 #define RTP_tSTARTTIME(member, time) \
217 do { \
218 if (Runtime_performance_enabled) { \
219 RTP_SingleFrame.member = time; \
220 } \
221 } while (0)
222
223 // ends a frame time calculation for a member of tRTFrameInfo frame
224 // member = member to stop recording time for
225 #define RTP_ENDTIME(member) \
226 do { \
227 if (Runtime_performance_enabled) { \
228 RTP_SingleFrame.member = rtp_GetClock() - RTP_SingleFrame.member; \
229 } \
230 } while (0)
231
232 // same as above, but will return the time that it stopped the recording time
233 #define RTP_tENDTIME(member, time) \
234 do { \
235 if (Runtime_performance_enabled) { \
236 time = rtp_GetClock(); \
237 RTP_SingleFrame.member = time - RTP_SingleFrame.member; \
238 } \
239 } while (0)
240
241 // returns the current clock time
242 #define RTP_GETCLOCK(time) \
243 do { \
244 if (Runtime_performance_enabled) { \
245 time = rtp_GetClock(); \
246 } \
247 } while (0)
248
249 // Starts a frame time calculation, but when ending the frame, it will increment the time by
250 // the difference instead of just setting it
251 // RTP_STARTINCTIME and RTP_ENDINCTIME must be in the same scope
252 #define RTP_STARTINCTIME(member) \
253 INT64 __start_time_; \
254 do { \
255 if (Runtime_performance_enabled) { \
256 __start_time_ = rtp_GetClock(); \
257 } \
258 } while (0)
259
260 // Ends a frame time calculation and increments the member by the time for that frame
261 #define RTP_ENDINCTIME(member) \
262 do { \
263 if (Runtime_performance_enabled) { \
264 RTP_SingleFrame.member += (rtp_GetClock() - __start_time_); \
265 } \
266 } while (0)
267
268 #endif
269
270 // Internal Global Vars
271 // ------------------------------
272 extern tRTFrameInfocxx . . $ tRTFrameInfo# RTP_SingleFramecxx . . $ RTP_SingleFrame.;
273 extern INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! Runtime_performance_clockfreqcxx . . $ Runtime_performance_clockfreq.;
274 extern uint8_tcxx . . $ uint8_t# Runtime_performance_enabledcxx . . $ Runtime_performance_enabled.;
275
276 /*
277 void rtp_Init
278 This function initilizes the runtime performance system so it's ready to be used
279 */
280 void rtp_Initcxx . . $ rtp_Init(49f6e7a06ebc5aa8).();
281
282 /*
283 void rtp_EnableFlags
284 This function enables the performance profiling of whatever flags you pass in
285 */
286 void rtp_EnableFlagscxx . . $ rtp_EnableFlags(ac50b47256ae7414).(INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! flags);
287
288 /*
289 void rtp_DisableFlags
290 This function disables the performance profiling of whatever flags you pass in
291 */
292 void rtp_DisableFlagscxx . . $ rtp_DisableFlags(ac50b47256ae7414).(INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! flags);
293
294 /*
295 void rtp_StartLog
296 Calling this function will reset the log and start a new log, recording immediatly
297 */
298 void rtp_StartLogcxx . . $ rtp_StartLog(49f6e7a06ebc5aa8).();
299
300 /*
301 void rtp_StopLog
302 Calling this function will stop the currently processing log and write it out to
303 file.
304 */
305 void rtp_StopLogcxx . . $ rtp_StopLog(49f6e7a06ebc5aa8).();
306
307 /*
308 void rtp_PauseLog
309 Calling this function will pause the log recording until rtp_ResumeLog is called
310 */
311 void rtp_PauseLogcxx . . $ rtp_PauseLog(49f6e7a06ebc5aa8).();
312
313 /*
314 void rtp_ResumeLog
315 Calling this will resume a paused log, starting at where it left off
316 */
317 void rtp_ResumeLogcxx . . $ rtp_ResumeLog(49f6e7a06ebc5aa8).();
318
319 /*
320 void rtp_RecordFrame
321 Calling this will record the data of the frame into the internal log, and prepare for
322 the next frame
323 */
324 void rtp_RecordFramecxx . . $ rtp_RecordFrame(49f6e7a06ebc5aa8).();
325
326 /*
327 INT64 rtp_GetClock
328 Returns the current hi-resolution clock value...no checking for overflow
329 */
330 INT64cxx . . $ `rtperformance/rtperformance.h:44:9`! rtp_GetClockcxx . . $ rtp_GetClock(7c4be072098b358f).();
331
332 /*
333 void rtp_WriteBufferLog
334 Writes the buffer of frames to file...
335 */
336 void rtp_WriteBufferLogcxx . . $ rtp_WriteBufferLog(49f6e7a06ebc5aa8).();
337
338 #endif