Hierarchical timing system. More...
#include <hierarchical_timer.h>
Classes | |
| struct | CExamStackEntry |
| For Hierarchical + sorted display. More... | |
| struct | CNode |
| a node in an execution path More... | |
| struct | CNodeStat |
| struct | CStats |
| Some statistics They can be build from a set of nodes. More... | |
| struct | CStatSorter |
| A statistics sorter, based on some criterion. More... | |
| struct | CTimerStat |
Public Types | |
| enum | TSortCriterion { NoSort, TotalTime, TotalTimeWithoutSons, MeanTime, NumVisits, MaxTime, MinTime, MaxSession, SortCriterionsLast } |
Public Member Functions | |
| CHTimer () | |
| ctor | |
| CHTimer (const char *name, bool isRoot=false) | |
| void | before () |
| Starts a measuring session. | |
| void | after () |
| void | after (bool displayAfter) |
| const char * | getName () const |
| void | setName (const char *name) |
Static Public Member Functions | |
| static void | startBench (bool wantStandardDeviation=false, bool quick=false, bool reset=true) |
| Starts a bench session. | |
| static void | bench () |
| For backward compatibility. | |
| static void | adjust () |
| For backward compatibility. | |
| static void | endBench () |
| Ends a bench session. | |
| static bool | benching () |
| static void | display (CLog *log=InfoLog, TSortCriterion criterion=TotalTime, bool displayInline=true, bool displayEx=true) |
| Display results. | |
| static void | displayByExecutionPath (CLog *log=InfoLog, TSortCriterion criterion=TotalTime, bool displayInline=true, bool alignPaths=true, bool displayEx=true) |
| Display results by execution paths. | |
| static void | displayHierarchical (CLog *log=InfoLog, bool displayEx=true, uint labelNumChar=32, uint indentationStep=2) |
| Hierarchical display, no sorting is done. | |
| static void | displayHierarchicalByExecutionPath (CLog *log=InfoLog, bool displayEx=true, uint labelNumChar=32, uint indentationStep=2) |
| Hierarchical display, no sorting is done. | |
| static void | displayHierarchicalByExecutionPathSorted (CLog *log=InfoLog, TSortCriterion criterion=TotalTime, bool displayEx=true, uint labelNumChar=32, uint indentationStep=2) |
| Hierarchical display, sorting is done in branches. | |
| static void | displaySummary (CLog *log=InfoLog, TSortCriterion criterion=TotalTime, bool displayEx=true, uint labelNumChar=32, uint indentationStep=2, uint maxDepth=3) |
| Hierarchical display, sorting is done in branches. | |
| static void | clear () |
| Clears stats, and re initializes all timer structure. | |
| static void | clearSessionCurrent () |
| Clears SessionMax current stats (only current value). | |
| static void | clearSessionStats () |
| Clears all SessionMax stats (max and current values). | |
| static void | updateSessionStats () |
| Update session stats. | |
Private Types | |
| typedef std::vector< CNode * > | TNodeVect |
| typedef std::vector< CHTimer * > | TTimerVect |
Private Member Functions | |
| void | doBefore () |
| void | doAfter (bool displayAfter=false) |
| void | walkTreeToCurrent () |
Static Private Member Functions | |
| static void | estimateAfterStopTime () |
Private Attributes | |
| const char * | _Name |
| CHTimer * | _Parent |
| TTimerVect | _Sons |
| bool | _IsRoot |
Static Private Attributes | |
| static CNode | _RootNode |
| static CNode * | _CurrNode = &_RootNode |
| static CHTimer | _RootTimer |
| static CSimpleClock | _PreambuleClock |
| This clock is used to measure the preamble of methods such as CHTimer::before() This is static, but the Hierarchical Timer doesn't support multi threading anyway. | |
| static double | _MsPerTick |
| static bool | _Benching = false |
| static bool | _BenchStartedOnce = false |
| static bool | _WantStandardDeviation = false |
| static CHTimer * | _CurrTimer = &_RootTimer |
| static sint64 | _AfterStopEstimateTime = 0 |
| static bool | _AfterStopEstimateTimeDone = false |
Hierarchical timing system.
Allows to accurately measure performance of routines, and displays results hierarchically. To time a piece of code, just declare a static CHTimer object and encapsulate code between calls to before() and after() methods. ex:
void myFunction() { static CHTimer myTimer("myFunction"); myTimer.before(); // some code here myTimer.after(); } *
Don't forget to call after() to avoid timing wrongness or assertion crashes !
Definition at line 185 of file hierarchical_timer.h.
typedef std::vector<CNode *> NLMISC::CHTimer::TNodeVect [private] |
Definition at line 289 of file hierarchical_timer.h.
typedef std::vector<CHTimer *> NLMISC::CHTimer::TTimerVect [private] |
Definition at line 291 of file hierarchical_timer.h.
| NoSort | |
| TotalTime | |
| TotalTimeWithoutSons | |
| MeanTime | |
| NumVisits | |
| MaxTime | |
| MinTime | |
| MaxSession | |
| SortCriterionsLast |
Definition at line 189 of file hierarchical_timer.h.
| NLMISC::CHTimer::CHTimer | ( | ) | [inline] |
ctor
Definition at line 201 of file hierarchical_timer.h.
| NLMISC::CHTimer::CHTimer | ( | const char * | name, | |
| bool | isRoot = false | |||
| ) | [inline] |
Definition at line 202 of file hierarchical_timer.h.
| static void NLMISC::CHTimer::adjust | ( | ) | [inline, static] |
For backward compatibility.
Definition at line 233 of file hierarchical_timer.h.
| void NLMISC::CHTimer::after | ( | bool | displayAfter | ) | [inline] |
Definition at line 215 of file hierarchical_timer.h.
| void NLMISC::CHTimer::after | ( | ) | [inline] |
Definition at line 210 of file hierarchical_timer.h.
References _Benching, and doAfter().
Referenced by endBench(), estimateAfterStopTime(), NLMISC::CAutoTimer::~CAutoTimer(), and NLMISC::CAutoTimerInst::~CAutoTimerInst().
| void NLMISC::CHTimer::before | ( | ) | [inline] |
Starts a measuring session.
Definition at line 204 of file hierarchical_timer.h.
References _Benching, and doBefore().
Referenced by NLMISC::CAutoTimer::CAutoTimer(), NLMISC::CAutoTimerInst::CAutoTimerInst(), estimateAfterStopTime(), and startBench().
| static void NLMISC::CHTimer::bench | ( | ) | [inline, static] |
For backward compatibility.
Definition at line 230 of file hierarchical_timer.h.
References startBench().
| static bool NLMISC::CHTimer::benching | ( | ) | [inline, static] |
Definition at line 237 of file hierarchical_timer.h.
References _Benching.
| void NLMISC::CHTimer::clear | ( | void | ) | [static] |
Clears stats, and re initializes all timer structure.
Definition at line 805 of file hierarchical_timer.cpp.
References _CurrNode, _RootNode, nlassert, NLMISC::CHTimer::CNode::releaseSons(), and NLMISC::CHTimer::CNode::reset().
Referenced by estimateAfterStopTime(), startBench(), and CEGUI::NeLRenderer::~NeLRenderer().
| void NLMISC::CHTimer::clearSessionCurrent | ( | ) | [static] |
Clears SessionMax current stats (only current value).
Definition at line 1040 of file hierarchical_timer.cpp.
References _RootNode, and NLMISC::CHTimer::CNode::resetSessionCurrent().
Referenced by startBench().
| void NLMISC::CHTimer::clearSessionStats | ( | ) | [static] |
Clears all SessionMax stats (max and current values).
Definition at line 1048 of file hierarchical_timer.cpp.
References _RootNode, and NLMISC::CHTimer::CNode::resetSessionStats().
Referenced by startBench().
| void NLMISC::CHTimer::display | ( | CLog * | log = InfoLog, |
|
| TSortCriterion | criterion = TotalTime, |
|||
| bool | displayInline = true, |
|||
| bool | displayEx = true | |||
| ) | [static] |
Display results.
| displayEx | true to display more detailed infos |
1 ) walk the tree to build the node map (well, in a not very optimal way..)
Definition at line 296 of file hierarchical_timer.cpp.
References _BenchStartedOnce, _CurrNode, _MsPerTick, _RootNode, _WantStandardDeviation, NLMISC::CHTimer::CStats::buildFromNode(), NLMISC::CLog::displayNL(), NLMISC::CLog::displayRawNL(), NLMISC::CSimpleClock::getNumTicks(), NoSort, NLMISC::CHTimer::CNode::Owner, NLMISC::smprintf(), NLMISC::CHTimer::CNode::Sons, NLMISC::CHTimer::CNode::SonsPreambule, NLMISC::CSimpleClock::start(), NLMISC::CSimpleClock::stop(), NLMISC::toString(), and NLMISC::CHTimer::CStats::TotalTime.
Referenced by NLSOUND::CSoundDriverXAudio2::displayBench(), NLSOUND::CSoundDriverFMod::displayBench(), NLSOUND::CSoundDriverDSound::displayBench(), NL3D::CDriverGL::displayBench(), NL3D::CDriverD3D::displayBench(), and NLMISC::NLMISC_CATEGORISED_COMMAND().
| void NLMISC::CHTimer::displayByExecutionPath | ( | CLog * | log = InfoLog, |
|
| TSortCriterion | criterion = TotalTime, |
|||
| bool | displayInline = true, |
|||
| bool | alignPaths = true, |
|||
| bool | displayEx = true | |||
| ) | [static] |
Display results by execution paths.
| displayInline | true to display each result on a single line. | |
| alignPaths | true to display all execution paths aligned. | |
| displayEx | true to display more detailed infos. |
1 ) walk the tree to build the node map (well, in a not very optimal way..)
2 ) sort statistics
Definition at line 384 of file hierarchical_timer.cpp.
References _BenchStartedOnce, _CurrNode, _MsPerTick, _RootNode, _WantStandardDeviation, NLMISC::CHTimer::CStats::buildFromNode(), NLMISC::CLog::displayRawNL(), NLMISC::CHTimer::CNode::getNumNodes(), NLMISC::CSimpleClock::getNumTicks(), nlassert, NoSort, NLMISC::smprintf(), NLMISC::CHTimer::CNode::Sons, NLMISC::CHTimer::CNode::SonsPreambule, NLMISC::CSimpleClock::start(), NLMISC::CSimpleClock::stop(), NLMISC::toString(), and NLMISC::CHTimer::CStats::TotalTime.
Referenced by NLSOUND::CSoundDriverXAudio2::displayBench(), NLSOUND::CSoundDriverFMod::displayBench(), NLSOUND::CSoundDriverDSound::displayBench(), NL3D::CDriverGL::displayBench(), and NL3D::CDriverD3D::displayBench().
| void NLMISC::CHTimer::displayHierarchical | ( | CLog * | log = InfoLog, |
|
| bool | displayEx = true, |
|||
| uint | labelNumChar = 32, |
|||
| uint | indentationStep = 2 | |||
| ) | [static] |
Hierarchical display, no sorting is done.
| displayEx | true to display more detailed infos. | |
| labelNumChar |
1 ) walk the execution tree to build the node map (well, in a not very optimal way..)
2 ) get root total time.
3 ) walk the timers tree and display infos (cumulate infos of nodes of each execution path)
Definition at line 481 of file hierarchical_timer.cpp.
References _BenchStartedOnce, _CurrNode, _MsPerTick, _Name, _Parent, _RootNode, _RootTimer, _Sons, _WantStandardDeviation, NLMISC::CHTimer::CStats::buildFromNode(), NLMISC::CHTimer::CStats::buildFromNodes(), NLMISC::CLog::displayNL(), NLMISC::CLog::displayRawNL(), NLMISC::CSimpleClock::getNumTicks(), NLMISC::CHTimer::CStats::getStats(), min, nlassert, NLMISC::CHTimer::CNode::Owner, NLMISC::CHTimer::CNode::Sons, NLMISC::CHTimer::CNode::SonsPreambule, NLMISC::CSimpleClock::start(), NLMISC::CSimpleClock::stop(), and NLMISC::CHTimer::CStats::TotalTime.
Referenced by NLSOUND::CSoundDriverXAudio2::displayBench(), NLSOUND::CSoundDriverFMod::displayBench(), NLSOUND::CSoundDriverDSound::displayBench(), NL3D::CDriverGL::displayBench(), and NL3D::CDriverD3D::displayBench().
| void NLMISC::CHTimer::displayHierarchicalByExecutionPath | ( | CLog * | log = InfoLog, |
|
| bool | displayEx = true, |
|||
| uint | labelNumChar = 32, |
|||
| uint | indentationStep = 2 | |||
| ) | [static] |
Hierarchical display, no sorting is done.
| displayEx | true to display more detailed infos. | |
| labelNumChar |
Definition at line 558 of file hierarchical_timer.cpp.
References displayHierarchicalByExecutionPathSorted(), and NoSort.
| void NLMISC::CHTimer::displayHierarchicalByExecutionPathSorted | ( | CLog * | log = InfoLog, |
|
| TSortCriterion | criterion = TotalTime, |
|||
| bool | displayEx = true, |
|||
| uint | labelNumChar = 32, |
|||
| uint | indentationStep = 2 | |||
| ) | [static] |
Hierarchical display, sorting is done in branches.
| displayEx | true to display more detailed infos. | |
| labelNumChar |
Definition at line 565 of file hierarchical_timer.cpp.
References _BenchStartedOnce, _CurrNode, _MsPerTick, _Name, _RootNode, _WantStandardDeviation, NLMISC::CHTimer::CStats::buildFromNode(), NLMISC::CHTimer::CStatSorter::Criterion, NLMISC::CLog::displayRawNL(), NLMISC::CSimpleClock::getNumTicks(), NLMISC::CHTimer::CStats::getStats(), min, nlassert, NoSort, NLMISC::CHTimer::CNode::Owner, NLMISC::CHTimer::CNode::Sons, NLMISC::CHTimer::CNode::SonsPreambule, NLMISC::CSimpleClock::start(), NLMISC::CSimpleClock::stop(), and NLMISC::CHTimer::CStats::TotalTime.
Referenced by NLSOUND::CSoundDriverXAudio2::displayBench(), NLSOUND::CSoundDriverFMod::displayBench(), NLSOUND::CSoundDriverDSound::displayBench(), NL3D::CDriverGL::displayBench(), NL3D::CDriverD3D::displayBench(), displayHierarchicalByExecutionPath(), and NLMISC::NLMISC_CATEGORISED_COMMAND().
| void NLMISC::CHTimer::displaySummary | ( | CLog * | log = InfoLog, |
|
| TSortCriterion | criterion = TotalTime, |
|||
| bool | displayEx = true, |
|||
| uint | labelNumChar = 32, |
|||
| uint | indentationStep = 2, |
|||
| uint | maxDepth = 3 | |||
| ) | [static] |
Hierarchical display, sorting is done in branches.
| displayEx | true to display more detailed infos. | |
| labelNumChar |
Definition at line 684 of file hierarchical_timer.cpp.
References _BenchStartedOnce, _CurrNode, _MsPerTick, _Name, _RootNode, _WantStandardDeviation, NLMISC::CHTimer::CStats::buildFromNode(), NLMISC::CHTimer::CStatSorter::Criterion, NLMISC::CLog::displayRawNL(), NLMISC::CSimpleClock::getNumTicks(), NLMISC::CHTimer::CStats::getStats(), min, nlassert, NoSort, NLMISC::CHTimer::CNode::Owner, NLMISC::CHTimer::CNode::Sons, NLMISC::CHTimer::CNode::SonsPreambule, NLMISC::CSimpleClock::start(), NLMISC::CSimpleClock::stop(), and NLMISC::CHTimer::CStats::TotalTime.
Referenced by CEGUI::NeLRenderer::doRender(), and NLMISC::NLMISC_CATEGORISED_COMMAND().
| void NLMISC::CHTimer::doAfter | ( | bool | displayAfter = false |
) | [private] |
Definition at line 974 of file hierarchical_timer.cpp.
References _AfterStopEstimateTime, _CurrNode, _CurrTimer, _MsPerTick, _Name, _Parent, _PreambuleClock, _WantStandardDeviation, NLMISC::CHTimer::CNode::Clock, NLMISC::CSimpleClock::getNumTicks(), NLMISC::CSimpleClock::getStartStopNumTicks(), NLMISC::CHTimer::CNode::LastSonsTotalTime, NLMISC::CHTimer::CNode::MaxTime, NLMISC::CHTimer::CNode::Measures, min, NLMISC::CHTimer::CNode::MinTime, nlinfo, NLMISC::CHTimer::CNode::NumVisits, NLMISC::CHTimer::CNode::Parent, NLMISC::CHTimer::CNode::SessionCurrent, NLMISC::CHTimer::CNode::SonsPreambule, NLMISC::CHTimer::CNode::SonsTotalTime, NLMISC::CSimpleClock::start(), NLMISC::CSimpleClock::stop(), and NLMISC::CHTimer::CNode::TotalTime.
Referenced by after().
| void NLMISC::CHTimer::doBefore | ( | ) | [private] |
Definition at line 952 of file hierarchical_timer.cpp.
References _CurrNode, _CurrTimer, _Parent, _PreambuleClock, _Sons, NLMISC::CHTimer::CNode::Clock, NLMISC::CSimpleClock::getNumTicks(), NLMISC::CHTimer::CNode::NumVisits, NLMISC::CHTimer::CNode::Parent, NLMISC::CHTimer::CNode::SonsPreambule, NLMISC::CSimpleClock::start(), NLMISC::CSimpleClock::stop(), and walkTreeToCurrent().
Referenced by before().
| void NLMISC::CHTimer::endBench | ( | ) | [static] |
Ends a bench session.
Definition at line 276 of file hierarchical_timer.cpp.
References _Benching, _CurrNode, _RootNode, _RootTimer, after(), nlwarning, and updateSessionStats().
| void NLMISC::CHTimer::estimateAfterStopTime | ( | ) | [static, private] |
Definition at line 192 of file hierarchical_timer.cpp.
References _AfterStopEstimateTime, _AfterStopEstimateTimeDone, _Benching, _BenchStartedOnce, _MsPerTick, _RootNode, _RootTimer, _WantStandardDeviation, after(), before(), clear(), NLMISC::CSystemInfo::getProcessorFrequency(), NLMISC::CSimpleClock::init(), NLMISC::CHTimer::CNode::Owner, NLMISC::CHTimer::CNode::SonsTotalTime, NLMISC::CTime::ticksToSecond(), and NLMISC::CHTimer::CNode::TotalTime.
Referenced by startBench().
| const char* NLMISC::CHTimer::getName | ( | void | ) | const [inline] |
Definition at line 221 of file hierarchical_timer.h.
References _Name.
Referenced by NLMISC::CHTimer::CNode::getPath().
| void NLMISC::CHTimer::setName | ( | const char * | name | ) | [inline] |
Definition at line 222 of file hierarchical_timer.h.
References _Name.
| void NLMISC::CHTimer::startBench | ( | bool | wantStandardDeviation = false, |
|
| bool | quick = false, |
|||
| bool | reset = true | |||
| ) | [static] |
Starts a bench session.
| wantStandardDeviation | When true, benchmarks will report the standard deviation of values. This require more memory, however, because each samples must be kept. | |
| quick | if true, quick compute the frequency of the processor |
Definition at line 239 of file hierarchical_timer.cpp.
References _Benching, _BenchStartedOnce, _MsPerTick, _RootNode, _RootTimer, _WantStandardDeviation, before(), clear(), clearSessionCurrent(), clearSessionStats(), estimateAfterStopTime(), NLMISC::CSystemInfo::getProcessorFrequency(), NLMISC::CSimpleClock::init(), nlassert, NLMISC::CHTimer::CNode::Owner, and NLMISC::CTime::ticksToSecond().
Referenced by bench(), and CEGUI::NeLRenderer::NeLRenderer().
| void NLMISC::CHTimer::updateSessionStats | ( | ) | [static] |
Update session stats.
Definition at line 1056 of file hierarchical_timer.cpp.
References _RootNode, NLMISC::CHTimer::CNode::SessionCurrent, NLMISC::CHTimer::CNode::SessionMax, and NLMISC::CHTimer::CNode::spreadSession().
Referenced by endBench().
| void NLMISC::CHTimer::walkTreeToCurrent | ( | ) | [private] |
Definition at line 167 of file hierarchical_timer.cpp.
References _CurrNode, _IsRoot, and NLMISC::CHTimer::CNode::Sons.
Referenced by doBefore().
sint64 NLMISC::CHTimer::_AfterStopEstimateTime = 0 [static, private] |
Definition at line 490 of file hierarchical_timer.h.
Referenced by doAfter(), and estimateAfterStopTime().
bool NLMISC::CHTimer::_AfterStopEstimateTimeDone = false [static, private] |
Definition at line 491 of file hierarchical_timer.h.
Referenced by estimateAfterStopTime().
bool NLMISC::CHTimer::_Benching = false [static, private] |
Definition at line 482 of file hierarchical_timer.h.
Referenced by after(), before(), benching(), endBench(), estimateAfterStopTime(), and startBench().
bool NLMISC::CHTimer::_BenchStartedOnce = false [static, private] |
Definition at line 484 of file hierarchical_timer.h.
Referenced by display(), displayByExecutionPath(), displayHierarchical(), displayHierarchicalByExecutionPathSorted(), displaySummary(), estimateAfterStopTime(), and startBench().
CHTimer::CNode * NLMISC::CHTimer::_CurrNode = &_RootNode [static, private] |
Definition at line 472 of file hierarchical_timer.h.
Referenced by clear(), display(), displayByExecutionPath(), displayHierarchical(), displayHierarchicalByExecutionPathSorted(), displaySummary(), doAfter(), doBefore(), endBench(), and walkTreeToCurrent().
CHTimer * NLMISC::CHTimer::_CurrTimer = &_RootTimer [static, private] |
Definition at line 488 of file hierarchical_timer.h.
Referenced by doAfter(), and doBefore().
bool NLMISC::CHTimer::_IsRoot [private] |
Definition at line 467 of file hierarchical_timer.h.
Referenced by walkTreeToCurrent().
double NLMISC::CHTimer::_MsPerTick [static, private] |
Definition at line 480 of file hierarchical_timer.h.
Referenced by display(), displayByExecutionPath(), displayHierarchical(), displayHierarchicalByExecutionPathSorted(), displaySummary(), doAfter(), estimateAfterStopTime(), and startBench().
const char* NLMISC::CHTimer::_Name [private] |
Definition at line 461 of file hierarchical_timer.h.
Referenced by displayHierarchical(), displayHierarchicalByExecutionPathSorted(), displaySummary(), doAfter(), getName(), and setName().
CHTimer* NLMISC::CHTimer::_Parent [private] |
Definition at line 463 of file hierarchical_timer.h.
Referenced by displayHierarchical(), doAfter(), and doBefore().
CSimpleClock NLMISC::CHTimer::_PreambuleClock [static, private] |
This clock is used to measure the preamble of methods such as CHTimer::before() This is static, but the Hierarchical Timer doesn't support multi threading anyway.
Definition at line 478 of file hierarchical_timer.h.
Referenced by doAfter(), and doBefore().
CHTimer::CNode NLMISC::CHTimer::_RootNode [static, private] |
Definition at line 470 of file hierarchical_timer.h.
Referenced by clear(), clearSessionCurrent(), clearSessionStats(), display(), displayByExecutionPath(), displayHierarchical(), displayHierarchicalByExecutionPathSorted(), displaySummary(), endBench(), estimateAfterStopTime(), startBench(), and updateSessionStats().
CHTimer NLMISC::CHTimer::_RootTimer [static, private] |
Definition at line 474 of file hierarchical_timer.h.
Referenced by displayHierarchical(), endBench(), estimateAfterStopTime(), and startBench().
TTimerVect NLMISC::CHTimer::_Sons [private] |
Definition at line 465 of file hierarchical_timer.h.
Referenced by displayHierarchical(), and doBefore().
bool NLMISC::CHTimer::_WantStandardDeviation = false [static, private] |
Definition at line 486 of file hierarchical_timer.h.
Referenced by display(), displayByExecutionPath(), displayHierarchical(), displayHierarchicalByExecutionPathSorted(), displaySummary(), doAfter(), estimateAfterStopTime(), and startBench().
1.6.1