Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
Profiler Class Reference#include <Profiler.h>
Detailed DescriptionManages a hierarchy of timers for profiling time spent in code, gives microsecond resolution.
Doesn't use any pointers so it's safe to put this in shared memory regions. Example usage:
ProfilerOfSize<2> prof; //A global manager for all the sections void f() { static unsigned int id=prof.getNewID("f"); // <== Get the ID number Profiler::Timer timer(id,&prof.prof); // <== start the timer //... if(rand()>RAND_MAX/2) return; // destruction of timer occurs automatically! //... } // if we didn't hit the return, timer will otherwise destruct here! However, there's a macro that makes this a one liner:
void g() { PROFSECTION("g",prof); // <== Most of the time, this is all you need //... // (unless you're doing something fancy like conditional timers) f(); // will note f's time as g's child time, as well as g's own time //... } The idea is similar to that used by MMAccessor. If you want to profile a section at smaller resolution than a function, you can use tricks shown in MMAccessor's documentation to limit the timer's scope.
For convenience, there are three global profilers predefined: mainProfiler, motionProfiler, and soundProfiler. These are what are polled by the ProfilerCheckControl -- if you instantiate a new profiler, you will have to call its report() function yourself to get the results. (If it's simply a matter of running out of sections in mainProfiler, increase the template parameter at the end of Profiler.h) Keep in mind however, that these global profilers are pointers, and need to be dereferenced to use with the macro, e.g. Here were the constraints I set for myself:
Consessions made:
Global readability is first priority since generating reports is the primary usage, thus we have to be able to handle being in shared memory space. This means no virtual functions and no pointer storage. Unfortunately, this makes the second constraint rather difficult.
Definition at line 96 of file Profiler.h.
Constructor & Destructor Documentation
constructor, but you don't want to construct one of these! Use ProfilerOfSize<x> instead!
Definition at line 118 of file Profiler.cc.
Member Function Documentation
call this to get a new ID number
Definition at line 61 of file Profiler.cc. Referenced by ProfilerOfSize< MaxSections >::getNewID().
called during process init (before any profiled sections)
Definition at line 55 of file Profiler.cc. Referenced by Profiler::AutoInit::AutoInit().
outputs profiling information
Definition at line 74 of file Profiler.cc. Referenced by ProfilerOfSize< MaxSections >::report().
gets the actual storage area of the SectionInfo's
Definition at line 172 of file Profiler.h. Referenced by finished(), getNewID(), report(), reset(), and setCurrent().
called automatically by Timer() - sets the current timer
Definition at line 134 of file Profiler.cc. Referenced by Profiler::Timer::setID(), and Profiler::Timer::Timer().
called automatically by ~Timer() - notes the specified timer as finished (doesn't check if the timer is actually the current one - don't screw up!)
Definition at line 155 of file Profiler.cc. Referenced by Profiler::Timer::~Timer().
returns which bucket a time should go in, does a binary search over buckets (unless someone things a log() call would be faster...)
Definition at line 183 of file Profiler.h. Referenced by finished(), and setCurrent().
Friends And Related Function Documentation
Only the Timer's should be calling setCurrent() and finished() upon the Timer's construction and destruction.
Definition at line 176 of file Profiler.h.
Member Data Documentation
maximum length of names of timers
Definition at line 102 of file Profiler.h. Referenced by getNewID().
number of slots in the histograms
Definition at line 104 of file Profiler.h. Referenced by finished(), getBucket(), initBuckets(), report(), Profiler::SectionInfo::reset(), Profiler::SectionInfo::SectionInfo(), and setCurrent().
the upper bound (exclusive) of the histograms, in milliseconds.
Definition at line 106 of file Profiler.h. Referenced by finished(), initBuckets(), and setCurrent().
affects how linearly the buckets are distributed - 1 means linear, >1 causes higher resolution for short times
Definition at line 108 of file Profiler.h. Referenced by initBuckets().
the current timer
Definition at line 165 of file Profiler.h. Referenced by finished(), and setCurrent().
gamma to use with exponential averages (1 to freeze, 0 to set to last)
Definition at line 167 of file Profiler.h. Referenced by finished(), and setCurrent().
so we can read the size of the infos array back again at runtime
Definition at line 168 of file Profiler.h. Referenced by getNewID().
the number of timer IDs which have been assigned
Definition at line 169 of file Profiler.h. Referenced by getNewID(), report(), and reset().
holds boundaries for each bucket
Definition at line 198 of file Profiler.h. Referenced by getBucket(), getBuckets(), initBuckets(), and report().
NASTY HACK - this is how we get around using virtual functions.
Definition at line 200 of file Profiler.h. Referenced by getInfos().
The documentation for this class was generated from the following files: |
Tekkotsu v4.0 |
Generated Thu Nov 22 00:58:37 2007 by Doxygen 1.5.4 |