Panda3D

profileTimer.I

00001 // Filename: profileTimer.I
00002 // Created by:  
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 INLINE void ProfileTimer::
00016 on() {
00017   _on = TrueClock::get_global_ptr()->get_short_time();
00018 }
00019 
00020 
00021 INLINE double ProfileTimer::
00022 getTime() {
00023   double time = TrueClock::get_global_ptr()->get_short_time();
00024   double et=_elapsedTime+=time-_on;
00025   _on=time;
00026   _elapsedTime=0.0;
00027   return et;
00028 }
00029 
00030 
00031 INLINE void ProfileTimer::
00032 mark(const char* tag) {
00033   if (!_entries) {
00034     cerr << "ProfileTimer::mark !_entries" << endl;
00035     exit(1);
00036   }
00037   if (_entryCount < _maxEntries-1) {
00038     TimerEntry& p=_entries[_entryCount];
00039     p._tag=tag;
00040     p._time=getTime();
00041     ++_entryCount;
00042   } else {
00043     _entries[_entryCount]._tag="*** Overflow ***";
00044   }
00045 }
00046 
00047 
00048 INLINE void ProfileTimer::
00049 off() {
00050   double time = TrueClock::get_global_ptr()->get_short_time();
00051   _elapsedTime+=time-_on;
00052 }
00053 
00054 
00055 INLINE void ProfileTimer::
00056 off(const char* tag) {
00057   double time = TrueClock::get_global_ptr()->get_short_time();
00058   _elapsedTime+=time-_on;
00059   mark(tag);
00060 }
00061 
00062 
00063 INLINE ProfileTimer::AutoTimer::
00064 ~AutoTimer() {
00065   // If the AutoTimer is the first auto ctor, then it will
00066   // be the last auto dtor, for that block.  Therefore, now
00067   // is the time to mark the time for the block/function:
00068   _profile.mark(_tag);
00069   --_profile._autoTimerCount;
00070 }
 All Classes Functions Variables Enumerations