NLMISC::CHTimer Class Reference

Hierarchical timing system. More...

#include <hierarchical_timer.h>

List of all members.

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

Detailed Description

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 !

Warning:
Supports only single-threaded applications.
Supports only Intel processors.
Author:
Benjamin Legros
Nicolas Vizerie
Nevrax France
Date:
2001, 2002

Definition at line 185 of file hierarchical_timer.h.


Member Typedef Documentation

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.


Member Enumeration Documentation

Enumerator:
NoSort 
TotalTime 
TotalTimeWithoutSons 
MeanTime 
NumVisits 
MaxTime 
MinTime 
MaxSession 
SortCriterionsLast 

Definition at line 189 of file hierarchical_timer.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

References _Benching, and doAfter().

void NLMISC::CHTimer::after (  )  [inline]
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]
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.

Parameters:
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]
void NLMISC::CHTimer::displayHierarchicalByExecutionPath ( CLog log = InfoLog,
bool  displayEx = true,
uint  labelNumChar = 32,
uint  indentationStep = 2 
) [static]

Hierarchical display, no sorting is done.

Parameters:
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]
void NLMISC::CHTimer::displaySummary ( CLog log = InfoLog,
TSortCriterion  criterion = TotalTime,
bool  displayEx = true,
uint  labelNumChar = 32,
uint  indentationStep = 2,
uint  maxDepth = 3 
) [static]
void NLMISC::CHTimer::doAfter ( bool  displayAfter = false  )  [private]
void NLMISC::CHTimer::doBefore (  )  [private]
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]
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.

Parameters:
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]
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().


Member Data Documentation

Definition at line 490 of file hierarchical_timer.h.

Referenced by doAfter(), and estimateAfterStopTime().

Definition at line 491 of file hierarchical_timer.h.

Referenced by estimateAfterStopTime().

bool NLMISC::CHTimer::_Benching = false [static, private]
bool NLMISC::CHTimer::_BenchStartedOnce = false [static, private]

Definition at line 488 of file hierarchical_timer.h.

Referenced by doAfter(), and doBefore().

Definition at line 467 of file hierarchical_timer.h.

Referenced by walkTreeToCurrent().

const char* NLMISC::CHTimer::_Name [private]

Definition at line 463 of file hierarchical_timer.h.

Referenced by displayHierarchical(), doAfter(), and doBefore().

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().

Definition at line 465 of file hierarchical_timer.h.

Referenced by displayHierarchical(), and doBefore().

bool NLMISC::CHTimer::_WantStandardDeviation = false [static, private]

The documentation for this class was generated from the following files:

Generated on Thu Jan 7 08:30:18 2010 for NeL by  doxygen 1.6.1