Panda3D
profileTimer.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file profileTimer.I
10  */
11 
12 INLINE void ProfileTimer::
13 on() {
14  _on = TrueClock::get_global_ptr()->get_short_time();
15 }
16 
17 
18 INLINE double ProfileTimer::
19 getTime() {
20  double time = TrueClock::get_global_ptr()->get_short_time();
21  double et=_elapsedTime+=time-_on;
22  _on=time;
23  _elapsedTime=0.0;
24  return et;
25 }
26 
27 
28 INLINE void ProfileTimer::
29 mark(const char* tag) {
30  if (!_entries) {
31  std::cerr << "ProfileTimer::mark !_entries" << std::endl;
32  exit(1);
33  }
34  if (_entryCount < _maxEntries-1) {
35  TimerEntry& p=_entries[_entryCount];
36  p._tag=tag;
37  p._time=getTime();
38  ++_entryCount;
39  } else {
40  _entries[_entryCount]._tag="*** Overflow ***";
41  }
42 }
43 
44 
45 INLINE void ProfileTimer::
46 off() {
47  double time = TrueClock::get_global_ptr()->get_short_time();
48  _elapsedTime+=time-_on;
49 }
50 
51 
52 INLINE void ProfileTimer::
53 off(const char* tag) {
54  double time = TrueClock::get_global_ptr()->get_short_time();
55  _elapsedTime+=time-_on;
56  mark(tag);
57 }
58 
59 
60 INLINE ProfileTimer::AutoTimer::
61 ~AutoTimer() {
62  // If the AutoTimer is the first auto ctor, then it will be the last auto
63  // dtor, for that block. Therefore, now is the time to mark the time for
64  // the blockfunction:
65  _profile.mark(_tag);
66  --_profile._autoTimerCount;
67 }
static TrueClock * get_global_ptr()
Returns a pointer to the one TrueClock object in the world.
Definition: trueClock.I:68