00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef PROFILETIMER_H //[
00015 #define PROFILETIMER_H
00016
00017 #include "pandabase.h"
00018 #include "trueClock.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class EXPCL_PANDAEXPRESS ProfileTimer {
00042 enum { MaxEntriesDefault=4096 };
00043 PUBLISHED:
00044 ProfileTimer(const char* name=0, int maxEntries=MaxEntriesDefault);
00045 ProfileTimer(const ProfileTimer& other);
00046 ~ProfileTimer();
00047
00048 void init(const char* name, int maxEntries=MaxEntriesDefault);
00049
00050 void on();
00051 void mark(const char* tag);
00052 void off();
00053 void off(const char* tag);
00054
00055
00056
00057 double getTotalTime() const;
00058 static void consolidateAllTo(ostream &out=cout);
00059 void consolidateTo(ostream &out=cout) const;
00060 static void printAllTo(ostream &out=cout);
00061 void printTo(ostream &out=cout) const;
00062
00063 public:
00064
00065
00066
00067
00068
00069
00070
00071 class EXPCL_PANDAEXPRESS AutoTimer {
00072 public:
00073 AutoTimer(ProfileTimer& profile, const char* tag);
00074 ~AutoTimer();
00075
00076 protected:
00077 ProfileTimer& _profile;
00078 const char* _tag;
00079 };
00080
00081 protected:
00082 static ProfileTimer* _head;
00083 ProfileTimer* _next;
00084 class TimerEntry {
00085 public:
00086 const char* _tag;
00087 double _time;
00088 };
00089 double _on;
00090 double _elapsedTime;
00091 const char* _name;
00092 int _maxEntries;
00093 int _entryCount;
00094 TimerEntry* _entries;
00095 int _autoTimerCount;
00096
00097 double getTime();
00098
00099 friend class ProfileTimer::AutoTimer;
00100 };
00101
00102 #include "profileTimer.I"
00103
00104 #endif //]