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