1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 // stopwatch timer to measure short periods (like frame rendering phases)
17 // based on the code by Inoussa OUEDRAOGO, Copyright (c) 2012
18 {$INCLUDE a_modes.inc}
21 interface
23 uses
24 SysUtils,
25 {$IF DEFINED(LINUX)}
26 {$DEFINE STOPWATCH_IS_HERE}
27 unixtype, linux
28 {$ELSEIF DEFINED(WINDOWS)}
29 {$DEFINE STOPWATCH_IS_HERE}
30 Windows
31 {$ELSE}
32 {$IFDEF STOPWATCH_IS_HERE}
33 {$UNDEF STOPWATCH_IS_HERE}
34 {$ENDIF}
35 {$WARNING You suck!}
36 {$ENDIF}
37 ;
39 {$IF DEFINED(STOPWATCH_IS_HERE)}
40 type
42 private
43 {$IF DEFINED(LINUX)}
45 {$ELSE}
47 {$ENDIF}
49 strict private
53 strict private
58 strict private
67 public
74 public
83 {$ENDIF}
86 // call this on frame start
88 // call this on frame end
95 // don't fuckup pairing of there, 'cause they can be nested!
99 // iterator
101 function xprofItCount (): Integer; // from current item to eol (not including children, but including current item)
102 // current item info
112 function xprofItNext (): Boolean; // move to next sibling; false: no more siblings (and current item is unchanged)
115 implementation
117 const
123 // ////////////////////////////////////////////////////////////////////////// //
125 {$IF DEFINED(LINUX)}
126 var
128 {$ENDIF}
129 begin
131 begin
132 {$IF DEFINED(LINUX)}
136 {$ELSE}
138 {$ENDIF}
144 begin
151 begin
158 begin
161 {$IF DEFINED(LINUX)}
163 {$ELSE}
165 {$ENDIF}
170 begin
173 {$IF DEFINED(LINUX)}
175 {$ELSE}
177 {$ENDIF}
182 begin
185 {$IF DEFINED(LINUX)}
187 {$ELSE}
189 {$ENDIF}
194 begin
195 //if mRunning then exit;
198 {$IF DEFINED(LINUX)}
200 {$ELSE}
202 {$ENDIF}
207 var
209 {$IF DEFINED(LINUX)}
211 {$ENDIF}
212 begin
213 {$IF DEFINED(LINUX)}
216 begin
219 end
220 else
221 begin
226 {$ELSE}
229 {$ENDIF}
234 begin
241 // ////////////////////////////////////////////////////////////////////////// //
242 // high-level profiler
243 {$IF DEFINED(STOPWATCH_IS_HERE)}
244 type
254 var
263 // call this on frame start
265 begin
274 // call this on frame end
276 begin
279 begin
287 // don't fuckup pairing of there, 'cause they can be nested!
289 var
292 begin
302 // link to children
304 begin
307 begin
309 end
310 else
311 begin
312 //FIXME: rewrite without schlemiel's algo!
316 end
317 else
318 begin
326 var
328 begin
333 // go back to parent
339 begin
340 //SetLength(xpsecs, 1024); // 'cause why not? 'cause don't pay for something you may not need
344 // ////////////////////////////////////////////////////////////////////////// //
345 // iterator
349 // all items
351 begin
356 // false: no sections
358 begin
370 // from current item to eol (not including children, but including current item)
372 var
374 begin
378 begin
385 // current item info
386 function xprofItName (): AnsiString; begin if (xitcur = -1) then result := '' else result := xpsecs[xitcur].name; end;
387 function xprofItMicro (): Int64; begin if (xitcur = -1) then result := 0 else result := xpsecs[xitcur].timer.elapsedMicro; end;
388 function xprofItMilli (): Int64; begin if (xitcur = -1) then result := 0 else result := xpsecs[xitcur].timer.elapsedMilli; end;
389 function xprofItHasChildren (): Boolean; begin if (xitcur = -1) then result := false else result := (xpsecs[xitcur].firstChild <> -1); end;
390 function xprofItIsChild (): Boolean; begin if (xitcur = -1) then result := false else result := (xpsecs[xitcur].parent <> -1); end;
393 // dive into childrens
395 begin
397 begin
399 end
400 else
401 begin
408 // pop into parent
410 begin
412 begin
414 end
415 else
416 begin
423 // move to next sibling; false: no more siblings (and current item is unchanged)
425 begin
427 begin
429 end
430 else
431 begin
437 {$ELSE}
449 // current item info
461 {$ENDIF}
463 begin
464 {$IF DEFINED(STOPWATCH_IS_HERE)}
466 {$ENDIF}