![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
#include <Stopwatch.h>
Public Member Functions | |
| Stopwatch (const std::string &name) | |
| ~Stopwatch () | |
Static Public Member Functions | |
| static void | PrintAccumulatedTimes () |
| static __inline void | PrintAccumulatedTimesConditional () |
Static Protected Member Functions | |
| static void | AccumulateTime (const std::string &name, double timeElapsed) |
Protected Attributes | |
| std::string | _name |
| tbb::tick_count | _timeAtConstruction |
Static Protected Attributes | |
| static ManagedDictionary < std::string, StopwatchAccumulator > | _Accumulators |
| static boost::mutex | _AccumulatorsMutex |
This class is used to determine the inclusive time of a function (its execution time, plus the time of any it calls) Simply construct an instance at the top of the function and it will be saved into static memory upon destruction Typically, this class should be used in special builds that allow for timing and release candidates should not be compiled with instances of this class This uses the high precision wall clock time functionality of Thread Building Blocks
#ifdef PERF_CLOCKS Support::Stopwatch(""); #endif
#ifdef PERF_CLOCKS Stopwatch::PrintAccumulatedTimes(); ##endif
Definition at line 48 of file Stopwatch.h.
| Support::Stopwatch::Stopwatch | ( | const std::string & | name | ) |
Constructor This captures the start time and assigns a name
Definition at line 52 of file Stopwatch.cpp.
: _name(name), _timeAtConstruction(tbb::tick_count::now()) { }
| Support::Stopwatch::~Stopwatch | ( | ) |
Destructor This measure the time since construction then accumulates that time into the static functions on this class
Definition at line 61 of file Stopwatch.cpp.
References _name, _timeAtConstruction, AccumulateTime(), and tbb::tick_count::now().
{
tbb::tick_count t1 = tbb::tick_count::now();
double seconds = (t1-_timeAtConstruction).seconds();
AccumulateTime(_name, seconds);
}
| void Support::Stopwatch::AccumulateTime | ( | const std::string & | name, |
| double | timeElapsed | ||
| ) | [static, protected] |
Definition at line 8 of file Stopwatch.cpp.
References _Accumulators, _AccumulatorsMutex, and Dictionary< Key, Value >::getSafe().
Referenced by ~Stopwatch().
{
//lock so only one thread can manipulator _Accumulators at a time
boost::lock_guard<boost::mutex> guard(_AccumulatorsMutex);
//save the time amongst the accumulators
StopwatchAccumulator* accumulator = _Accumulators.getSafe(name);
if(accumulator == NULL)
{
//make a new accumulator and save it
//its memory will be deallocated when the managed dictionary leaves scope
accumulator = new StopwatchAccumulator();
(*accumulator)(timeElapsed);
_Accumulators[name] = accumulator;
}
else
(*accumulator)(timeElapsed);
}
| void Support::Stopwatch::PrintAccumulatedTimes | ( | ) | [static] |
Prints out statistics for all timers instantiated and destroyed thus far in the program
Definition at line 30 of file Stopwatch.cpp.
References _Accumulators.
Referenced by PrintAccumulatedTimesConditional().
{
ManagedDictionary<std::string, StopwatchAccumulator>::const_iterator iter;
ManagedDictionary<std::string, StopwatchAccumulator>::const_iterator end;
printf("\r\n Count| Min| Max| Mean| Total\r\n");
for(iter = _Accumulators.begin(), end = _Accumulators.end(); iter != end; ++iter)
{
StopwatchAccumulator* curAcc = iter->second;
printf("%s:\r\n%10d| %6.4g| %6.4g| %6.4g| %6.4g\r\n", iter->first.data(),
boost::accumulators::extract::count(*curAcc),
(boost::accumulators::extract::min)(*curAcc),
(boost::accumulators::extract::max)(*curAcc),
boost::accumulators::extract::mean(*curAcc),
boost::accumulators::extract::sum(*curAcc));
}
}
| static __inline void Support::Stopwatch::PrintAccumulatedTimesConditional | ( | ) | [inline, static] |
Definition at line 62 of file Stopwatch.h.
References PrintAccumulatedTimes().
{
#ifdef PERF_CLOCKS
Stopwatch::PrintAccumulatedTimes();
#endif
}
ManagedDictionary< std::string, StopwatchAccumulator > Support::Stopwatch::_Accumulators [static, protected] |
Definition at line 53 of file Stopwatch.h.
Referenced by AccumulateTime(), and PrintAccumulatedTimes().
boost::mutex Support::Stopwatch::_AccumulatorsMutex [static, protected] |
Definition at line 54 of file Stopwatch.h.
Referenced by AccumulateTime().
std::string Support::Stopwatch::_name [protected] |
Definition at line 52 of file Stopwatch.h.
Referenced by ~Stopwatch().
Definition at line 51 of file Stopwatch.h.
Referenced by ~Stopwatch().
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.