From a7d9baeeb8dd1ed788889a4e71be051c3dc532be Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 10 Mar 2019 19:20:43 +0100 Subject: [PATCH] Remove unused ProfileTimer class It doesn't seem to be used by anything, but it does take up 64+ KiB of memory in every Panda process. --- makepanda/makepanda.vcproj | 3 - panda/src/express/p3express_composite1.cxx | 1 - panda/src/express/profileTimer.I | 67 -------- panda/src/express/profileTimer.cxx | 179 --------------------- panda/src/express/profileTimer.h | 103 ------------ panda/src/putil/datagramInputFile.cxx | 1 - 6 files changed, 354 deletions(-) delete mode 100644 panda/src/express/profileTimer.I delete mode 100644 panda/src/express/profileTimer.cxx delete mode 100644 panda/src/express/profileTimer.h diff --git a/makepanda/makepanda.vcproj b/makepanda/makepanda.vcproj index 2fee06a963..785061eea8 100644 --- a/makepanda/makepanda.vcproj +++ b/makepanda/makepanda.vcproj @@ -2206,7 +2206,6 @@ - @@ -2215,10 +2214,8 @@ - - diff --git a/panda/src/express/p3express_composite1.cxx b/panda/src/express/p3express_composite1.cxx index 6bfb55de8e..7f071921e7 100644 --- a/panda/src/express/p3express_composite1.cxx +++ b/panda/src/express/p3express_composite1.cxx @@ -30,5 +30,4 @@ #include "pointerToArray.cxx" #include "pointerToBase.cxx" #include "pointerToVoid.cxx" -#include "profileTimer.cxx" #include "pStatCollectorForwardBase.cxx" diff --git a/panda/src/express/profileTimer.I b/panda/src/express/profileTimer.I deleted file mode 100644 index bd5102e6de..0000000000 --- a/panda/src/express/profileTimer.I +++ /dev/null @@ -1,67 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file profileTimer.I - */ - -INLINE void ProfileTimer:: -on() { - _on = TrueClock::get_global_ptr()->get_short_time(); -} - - -INLINE double ProfileTimer:: -getTime() { - double time = TrueClock::get_global_ptr()->get_short_time(); - double et=_elapsedTime+=time-_on; - _on=time; - _elapsedTime=0.0; - return et; -} - - -INLINE void ProfileTimer:: -mark(const char* tag) { - if (!_entries) { - std::cerr << "ProfileTimer::mark !_entries" << std::endl; - exit(1); - } - if (_entryCount < _maxEntries-1) { - TimerEntry& p=_entries[_entryCount]; - p._tag=tag; - p._time=getTime(); - ++_entryCount; - } else { - _entries[_entryCount]._tag="*** Overflow ***"; - } -} - - -INLINE void ProfileTimer:: -off() { - double time = TrueClock::get_global_ptr()->get_short_time(); - _elapsedTime+=time-_on; -} - - -INLINE void ProfileTimer:: -off(const char* tag) { - double time = TrueClock::get_global_ptr()->get_short_time(); - _elapsedTime+=time-_on; - mark(tag); -} - - -INLINE ProfileTimer::AutoTimer:: -~AutoTimer() { - // If the AutoTimer is the first auto ctor, then it will be the last auto - // dtor, for that block. Therefore, now is the time to mark the time for - // the blockfunction: - _profile.mark(_tag); - --_profile._autoTimerCount; -} diff --git a/panda/src/express/profileTimer.cxx b/panda/src/express/profileTimer.cxx deleted file mode 100644 index dfad4b03b4..0000000000 --- a/panda/src/express/profileTimer.cxx +++ /dev/null @@ -1,179 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file profileTimer.cxx - */ - -#include "profileTimer.h" - -#include "pmap.h" - -using std::ostream; -using std::string; - -// See ProfileTimer.h for documentation. - - -EXPCL_PANDA_EXPRESS ProfileTimer Skyler_timer_global=ProfileTimer("startup"); - -ProfileTimer* ProfileTimer::_head; - -ProfileTimer:: -ProfileTimer(const char* name, int maxEntries) : - _entries(nullptr), - _autoTimerCount(0) { - // Keep a list of the ProfileTimers, so we can print them: - _next=_head; - _head=this; - if (name) { - init(name, maxEntries); - } -} - -ProfileTimer:: -ProfileTimer(const ProfileTimer& other) { - // Add to list: - _next=_head; - _head=this; - // init it: - _name=other._name; - _maxEntries=other._maxEntries; - if (_name) { - init(_name, _maxEntries); - } - // Copy other entries: - _on=other._on; - _elapsedTime=other._elapsedTime; - _autoTimerCount=other._autoTimerCount; - _entryCount=other._entryCount; - if (other._entries) { - memcpy(_entries, other._entries, _entryCount * sizeof(TimerEntry)); - } -} - -ProfileTimer:: -~ProfileTimer() { - PANDA_FREE_ARRAY(_entries); - // Remove this from the list: - if (_head==this) { - _head=_next; - } else { - ProfileTimer* p=_head; - ProfileTimer* prior=p; - while (p) { - if (p==this) { - prior->_next=_next; - break; - } - prior=p; - p=p->_next; - } - } -} - -void ProfileTimer:: -init(const char* name, int maxEntries) { - _name=name; - _maxEntries=maxEntries; - _entries = (TimerEntry *)PANDA_MALLOC_ARRAY(_maxEntries * sizeof(TimerEntry)); - _entryCount=0; - _elapsedTime=0.0; - _on=0.0; -} - -double ProfileTimer:: -getTotalTime() const { - double total=0; - int i; - for (i=0; i<_entryCount; ++i) { - TimerEntry& te=_entries[i]; - total+=te._time; - } - return total; -} - -void ProfileTimer:: -consolidateAllTo(ostream &out) { - ProfileTimer* p=_head; - while (p) { - p->consolidateTo(out); - p=p->_next; - } -} - -void ProfileTimer:: -consolidateTo(ostream &out) const { - pmap entries; - int i; - for (i=0; i<_entryCount; ++i) { - TimerEntry& te=_entries[i]; - entries[te._tag]+=te._time; - } - out << "-------------------------------------------------------------------\n" - << "Profile Timing of " << _name - << "\n\n"; // ...should print data and time too. - double total=0; - { - pmap::const_iterator i=entries.begin(); - for (;i!=entries.end(); ++i) { - out << " " << std::setw(50) << i->first << ": " - << std::setiosflags(std::ios::fixed) << std::setprecision(6) << std::setw(10) << i->second << "\n"; - total+=i->second; - } - } - out << "\n [Total Time: " - << std::setiosflags(std::ios::fixed) << std::setprecision(6) << total - << " seconds]\n" - << "-------------------------------------------------------------------\n"; - out << std::endl; -} - -void ProfileTimer:: -printAllTo(ostream &out) { - ProfileTimer* p=_head; - while (p) { - p->printTo(out); - p=p->_next; - } -} - -void ProfileTimer:: -printTo(ostream &out) const { - out << "-------------------------------------------------------------------\n" - << "Profile Timing of " << _name - << "\n\n"; // ...should print data and time too. - double total=0; - int i; - for (i=0; i<_entryCount; ++i) { - TimerEntry& te=_entries[i]; - out << " " << std::setw(50) << te._tag << ": " - << std::setiosflags(std::ios::fixed) << std::setprecision(6) << std::setw(10) << te._time << "\n"; - total+=te._time; - } - out << "\n [Total Time: " - << std::setiosflags(std::ios::fixed) << std::setprecision(6) << total - << " seconds]\n" - << "-------------------------------------------------------------------\n"; - out << std::endl; -} - -ProfileTimer::AutoTimer::AutoTimer(ProfileTimer& profile, const char* tag) : - _profile(profile) { - _tag=tag; - if (_profile._autoTimerCount) { - // ...this is a nested call to another AutoTimer. Assign the time to the - // prior AutoTimer: - _profile.mark(_profile._entries[_profile._entryCount-1]._tag); - } else { - // ...this is not a nested call. - _profile.mark("other"); - } - // Tell the profile that it's in an AutoTimer: - ++_profile._autoTimerCount; - _profile.mark(_tag); -} diff --git a/panda/src/express/profileTimer.h b/panda/src/express/profileTimer.h deleted file mode 100644 index 39ab65c588..0000000000 --- a/panda/src/express/profileTimer.h +++ /dev/null @@ -1,103 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file profileTimer.h - * @author skyler - */ - -#ifndef PROFILETIMER_H -#define PROFILETIMER_H - -#include "pandabase.h" -#include "trueClock.h" - -/* - ProfileTimer - - HowTo: - Create a ProfileTimer and hold onto it. - Call init() whenever you like (the timer doesn't - start yet). - Call on() to start the timer. - While the timer is on, call mark() at each point of interest, - in the code you are timing. - You can turn the timer off() and on() to skip things you - don't want to time. - When your timing is finished, call printTo() to see the - results (e.g. myTimer.printTo(cerr)). - - Notes: - You should be able to time things down to the millisecond - well enough, but if you call on() and off() within micro- - seconds of each other, I don't think you'll get very good - results. -*/ -class EXPCL_PANDA_EXPRESS ProfileTimer { - enum { MaxEntriesDefault=4096 }; -PUBLISHED: - explicit ProfileTimer(const char* name=0, int maxEntries=MaxEntriesDefault); - ProfileTimer(const ProfileTimer& other); - ~ProfileTimer(); - - void init(const char* name, int maxEntries=MaxEntriesDefault); - - void on(); - void mark(const char* tag); - void off(); - void off(const char* tag); - - // Don't call any of the following during timing: (Because they are slow, - // not because anything will break). - double getTotalTime() const; - static void consolidateAllTo(std::ostream &out=std::cout); - void consolidateTo(std::ostream &out=std::cout) const; - static void printAllTo(std::ostream &out=std::cout); - void printTo(std::ostream &out=std::cout) const; - -public: - /* - e.g. - void Foo() { - ProfileTimer::AutoTimer(myProfiler, "Foo()"); - ... - } - */ - class EXPCL_PANDA_EXPRESS AutoTimer { - public: - AutoTimer(ProfileTimer& profile, const char* tag); - ~AutoTimer(); - - protected: - ProfileTimer& _profile; - const char* _tag; - }; - -protected: - static ProfileTimer* _head; - ProfileTimer* _next; - class TimerEntry { - public: - const char* _tag; // not owned by this. - double _time; - }; - double _on; - double _elapsedTime; - const char* _name; // not owned by this. - int _maxEntries; - int _entryCount; - TimerEntry* _entries; - int _autoTimerCount; // see class AutoTimer - - double getTime(); - - friend class ProfileTimer::AutoTimer; -}; - -#include "profileTimer.I" - -#endif //] diff --git a/panda/src/putil/datagramInputFile.cxx b/panda/src/putil/datagramInputFile.cxx index 600f699635..3c7da5d320 100644 --- a/panda/src/putil/datagramInputFile.cxx +++ b/panda/src/putil/datagramInputFile.cxx @@ -15,7 +15,6 @@ #include "temporaryFile.h" #include "numeric_types.h" #include "datagramIterator.h" -#include "profileTimer.h" #include "config_putil.h" #include "config_express.h" #include "virtualFileSystem.h"