15 #include "profileTimer.h"
29 ProfileTimer(
const char* name,
int maxEntries) :
36 init(name, maxEntries);
47 _maxEntries=other._maxEntries;
49 init(_name, _maxEntries);
53 _elapsedTime=other._elapsedTime;
54 _autoTimerCount=other._autoTimerCount;
55 _entryCount=other._entryCount;
57 memcpy(_entries, other._entries, _entryCount *
sizeof(TimerEntry));
63 PANDA_FREE_ARRAY(_entries);
82 init(
const char* name,
int maxEntries) {
84 _maxEntries=maxEntries;
85 _entries = (TimerEntry *)PANDA_MALLOC_ARRAY(_maxEntries *
sizeof(TimerEntry));
92 getTotalTime()
const {
95 for (i=0; i<_entryCount; ++i) {
96 TimerEntry& te=_entries[i];
103 consolidateAllTo(ostream &out) {
106 p->consolidateTo(out);
112 consolidateTo(ostream &out)
const {
115 for (i=0; i<_entryCount; ++i) {
116 TimerEntry& te=_entries[i];
117 entries[te._tag]+=te._time;
119 out <<
"-------------------------------------------------------------------\n"
120 <<
"Profile Timing of " << _name
125 for (;i!=entries.end(); ++i) {
126 out <<
" " << setw(50) << i->first <<
": "
127 << setiosflags(ios::fixed) << setprecision(6) << setw(10) << i->second <<
"\n";
131 out <<
"\n [Total Time: "
132 << setiosflags(ios::fixed) << setprecision(6) << total
134 <<
"-------------------------------------------------------------------\n";
139 printAllTo(ostream &out) {
148 printTo(ostream &out)
const {
149 out <<
"-------------------------------------------------------------------\n"
150 <<
"Profile Timing of " << _name
154 for (i=0; i<_entryCount; ++i) {
155 TimerEntry& te=_entries[i];
156 out <<
" " << setw(50) << te._tag <<
": "
157 << setiosflags(ios::fixed) << setprecision(6) << setw(10) << te._time <<
"\n";
160 out <<
"\n [Total Time: "
161 << setiosflags(ios::fixed) << setprecision(6) << total
163 <<
"-------------------------------------------------------------------\n";
167 ProfileTimer::AutoTimer::AutoTimer(
ProfileTimer& profile,
const char* tag) :
170 if (_profile._autoTimerCount) {
173 _profile.mark(_profile._entries[_profile._entryCount-1]._tag);
176 _profile.mark(
"other");
179 ++_profile._autoTimerCount;
This is our own Panda specialization on the default STL map.