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