Main MRPT website > C++ reference for MRPT 1.5.6
List of all members | Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes
mrpt::utils::CTimeLogger Class Reference

Detailed Description

A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.

The results can be dumped to cout or to Visual Studio's output panel. Recursive methods are supported with no problems, that is, calling "enter(X) enter(X) ... leave(X) leave(X)". enter()/leave() are thread-safe.

This class can be also used to monitorize min/mean/max/total stats of any user-provided parameters via the method CTimeLogger::registerUserMeasure()

Cost of the profiler itself (measured on MSVC2015, Windows 10, Intel i5-2310 2.9GHz):

See Also
CTimeLoggerEntry
Note
The default behavior is dumping all the information at destruction.

Definition at line 41 of file CTimeLogger.h.

#include <mrpt/utils/CTimeLogger.h>

Inheritance diagram for mrpt::utils::CTimeLogger:
Inheritance graph

Classes

struct  TCallData
 Data of all the calls: More...
 
struct  TCallStats
 Data of each call section: # of calls, minimum, maximum, average and overall execution time (in seconds) More...
 

Public Member Functions

 CTimeLogger (bool enabled=true, const std::string &name="")
 
virtual ~CTimeLogger ()
 Default constructor. More...
 
 CTimeLogger (const CTimeLogger &o)
 
CTimeLoggeroperator= (const CTimeLogger &o)
 
std::string getStatsAsText (const size_t column_width=80) const
 Dump all stats to a multi-line text string. More...
 
void getStats (std::map< std::string, TCallStats > &out_stats) const
 Returns all the current stats as a map: section_name => stats. More...
 
void dumpAllStats (const size_t column_width=80) const
 Dump all stats through the COutputLogger interface. More...
 
void clear (bool deep_clear=false)
 Resets all stats. By default (deep_clear=false), all section names are remembered (not freed) so the cost of creating upon the first next call is avoided. More...
 
void enable (bool enabled=true)
 
void disable ()
 
bool isEnabled () const
 
void saveToCSVFile (const std::string &csv_file) const
 Dump all stats to a Comma Separated Values (CSV) file. More...
 
void registerUserMeasure (const char *event_name, const double value)
 
void setName (const std::string &name)
 
void enter (const char *func_name)
 Start of a named section. More...
 
double leave (const char *func_name)
 End of a named section. More...
 
double getMeanTime (const std::string &name) const
 Return the mean execution time of the given "section", or 0 if it hasn't ever been called "enter" with that section name. More...
 
double getLastTime (const std::string &name) const
 Return the last execution time of the given "section", or 0 if it hasn't ever been called "enter" with that section name. More...
 

Protected Types

typedef
mrpt::utils::ts_hash_map
< std::string, TCallData, 1, 10 > 
TDataMap
 

Protected Member Functions

void do_enter (const char *func_name)
 
double do_leave (const char *func_name)
 

Protected Attributes

TDataMap m_data
 

Private Attributes

CTicTac m_tictac
 
bool m_enabled
 
std::string m_name
 

Member Typedef Documentation

Definition at line 59 of file CTimeLogger.h.

Constructor & Destructor Documentation

CTimeLogger::CTimeLogger ( bool  enabled = true,
const std::string name = "" 
)

Definition at line 57 of file CTimeLogger.cpp.

References m_tictac, and mrpt::utils::CTicTac::Tic().

CTimeLogger::~CTimeLogger ( )
virtual

Default constructor.

Destructor

Definition at line 66 of file CTimeLogger.cpp.

References dumpAllStats(), and m_data.

CTimeLogger::CTimeLogger ( const CTimeLogger o)

Definition at line 73 of file CTimeLogger.cpp.

Member Function Documentation

void CTimeLogger::clear ( bool  deep_clear = false)

Resets all stats. By default (deep_clear=false), all section names are remembered (not freed) so the cost of creating upon the first next call is avoided.

Definition at line 107 of file CTimeLogger.cpp.

References m_data.

void mrpt::utils::CTimeLogger::disable ( )
inline
void CTimeLogger::do_enter ( const char *  func_name)
protected
double CTimeLogger::do_leave ( const char *  func_name)
protected
void CTimeLogger::dumpAllStats ( const size_t  column_width = 80) const

Dump all stats through the COutputLogger interface.

See Also
getStatsAsText, saveToCVSFile

Definition at line 212 of file CTimeLogger.cpp.

References getStatsAsText(), and MRPT_LOG_INFO_STREAM.

Referenced by ~CTimeLogger().

void mrpt::utils::CTimeLogger::enable ( bool  enabled = true)
inline
void mrpt::utils::CTimeLogger::enter ( const char *  func_name)
inline
double CTimeLogger::getLastTime ( const std::string name) const

Return the last execution time of the given "section", or 0 if it hasn't ever been called "enter" with that section name.

Definition at line 294 of file CTimeLogger.cpp.

References m_data.

Referenced by mrpt::nav::CAbstractPTGBasedReactive::performNavigationStep(), and mrpt::nav::CAbstractPTGBasedReactive::STEP8_GenerateLogRecord().

double CTimeLogger::getMeanTime ( const std::string name) const

Return the mean execution time of the given "section", or 0 if it hasn't ever been called "enter" with that section name.

Definition at line 287 of file CTimeLogger.cpp.

References m_data.

void CTimeLogger::getStats ( std::map< std::string, TCallStats > &  out_stats) const
std::string CTimeLogger::getStatsAsText ( const size_t  column_width = 80) const
bool mrpt::utils::CTimeLogger::isEnabled ( ) const
inline
double mrpt::utils::CTimeLogger::leave ( const char *  func_name)
inline
CTimeLogger & CTimeLogger::operator= ( const CTimeLogger o)

Definition at line 80 of file CTimeLogger.cpp.

References m_data, m_enabled, and m_name.

void CTimeLogger::registerUserMeasure ( const char *  event_name,
const double  value 
)
void CTimeLogger::saveToCSVFile ( const std::string csv_file) const

Dump all stats to a Comma Separated Values (CSV) file.

See Also
dumpAllStats

Definition at line 194 of file CTimeLogger.cpp.

References mrpt::format(), m_data, and mrpt::utils::CStream::printf().

void mrpt::utils::CTimeLogger::setName ( const std::string name)
inline

Definition at line 94 of file CTimeLogger.h.

Member Data Documentation

TDataMap mrpt::utils::CTimeLogger::m_data
protected
bool mrpt::utils::CTimeLogger::m_enabled
private

Definition at line 45 of file CTimeLogger.h.

Referenced by operator=(), and registerUserMeasure().

std::string mrpt::utils::CTimeLogger::m_name
private

Definition at line 46 of file CTimeLogger.h.

Referenced by getStatsAsText(), and operator=().

CTicTac mrpt::utils::CTimeLogger::m_tictac
private

Definition at line 44 of file CTimeLogger.h.

Referenced by CTimeLogger(), do_enter(), and do_leave().




Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018