DUtils::Profiler Class Reference

Measures execution time of code. More...

#include <Profiler.h>

List of all members.

Public Member Functions

 Profiler (const float scale=Profiler::SECONDS)
void profile (const std::string &name="")
void stopAndScale (double scale, const std::string &name="")
void stop (const std::string &name="")
void add (double v, const std::string &name="")
double back (const std::string &name="") const
void reset (const std::string &name="")
void resetAll ()
void getEntryNames (std::vector< std::string > &names) const
float getDefaultScale () const
void setDefaultScale (float scale)
double getMeanTime (const std::string &name="") const
double getStdevTime (const std::string &name="") const
double getMinTime (const std::string &name="") const
double getMaxTime (const std::string &name="") const
double getTotalTime (const std::string &name="") const
void getTime (std::vector< double > &time, const std::string &name="") const
void getStatistics (double &mean, double &stdev, double &min, double &max, const std::string &name="") const
void showStatistics (const std::string &name="", const std::string &suffix="s", double scale=1., ostream &out=std::cout) const

Static Public Attributes

static const float MS = 1e3
static const float SECONDS = 1

Protected Attributes

std::map< std::string,
std::vector< double > > 
m_profiles
 Profile data.
std::map< std::string, Timestampm_start_points
 Starting points.
std::string m_last_profile
 Last used entry.
float m_scale
 Default scale.

Detailed Description

Measures execution time of code.


Member Function Documentation

void Profiler::add ( double  v,
const std::string &  name = "" 
)

Adds a value to the given entry

Parameters:
v value (already scaled) to add
name entry name. If not given, an empty string is used.
double Profiler::back ( const std::string &  name = ""  )  const

Returns the last measured time for an item

Parameters:
name item name. If not given, an empty string is used.
float DUtils::Profiler::getDefaultScale (  )  const [inline]

Returns the default scale of time to use with stop

Returns:
scale
void Profiler::getEntryNames ( std::vector< std::string > &  names  )  const

Returns the names of all the entries in the profiler

Parameters:
names (out) names
double Profiler::getMaxTime ( const std::string &  name = ""  )  const

Returns the max time of the given entry

Parameters:
name entry name
double Profiler::getMeanTime ( const std::string &  name = ""  )  const

Returns the mean of the time of the given entry

Parameters:
name entry name
double Profiler::getMinTime ( const std::string &  name = ""  )  const

Returns the min time of the given entry

Parameters:
name entry name
void Profiler::getStatistics ( double &  mean,
double &  stdev,
double &  min,
double &  max,
const std::string &  name = "" 
) const

Returns all the statistics of the given entry

Parameters:
mean (out) mean
stdev (out) standard deviation
min (out) min value
max (out) max value
name entry name
double Profiler::getStdevTime ( const std::string &  name = ""  )  const

Returns the standard deviation of the time of the given entry

Parameters:
name entry name
void Profiler::getTime ( std::vector< double > &  time,
const std::string &  name = "" 
) const

Returns all the time measurements of the given entry

Parameters:
time (out) measurements
name entry name
double Profiler::getTotalTime ( const std::string &  name = ""  )  const

Returns the sum of the times of the given entry

Parameters:
name entry name
void Profiler::profile ( const std::string &  name = ""  ) 

Starts profiling the given item. If a profile on this item is already active, that previous call with this item is overriden.

Parameters:
name name of item to profile. If not given, an empty string is used.
void Profiler::reset ( const std::string &  name = ""  ) 

Removes all the measurements of the given item

Parameters:
name item name. If not given, an empty string is used.
void DUtils::Profiler::resetAll (  )  [inline]

Removes the measurements of all the items

void DUtils::Profiler::setDefaultScale ( float  scale  )  [inline]

Sets the default scale of time to use with stop

Parameters:
scale 
void Profiler::showStatistics ( const std::string &  name = "",
const std::string &  suffix = "s",
double  scale = 1.,
ostream &  out = std::cout 
) const

Prints all the statistics of the given entry

Parameters:
name entry name
suffix unit suffix to print with the measurements
scale scale to multiply the measurements before printing
out stream to print to
void DUtils::Profiler::stop ( const std::string &  name = ""  )  [inline]

Stops profiling the given item or the last one if this is not provided. Adds the elapsed time (in the default scale of time) to the sum of this item profile time

Parameters:
name item name. If not given, last entry used in profile is used.
void Profiler::stopAndScale ( double  scale,
const std::string &  name = "" 
)

Does the same as Profiler::stop, but overrides the default scale of time (i.e it multiplies the elapsed time in seconds by the given scale factor)

Parameters:
scale stored_duration = actual_duration (s) * scale
name item name. If not given, last entry used in profile is used.
Note:
use scale 1e3 to store the time in milliseconds

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Enumerations Friends
Generated on Thu Feb 7 19:16:00 2013 by  doxygen 1.6.3