Main MRPT website > C++ reference
MRPT logo
List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | 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)".

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

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

Definition at line 60 of file CTimeLogger.h.

#include <mrpt/utils/CTimeLogger.h>

Inheritance diagram for mrpt::utils::CTimeLogger:
Inheritance graph
[legend]

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)
 
virtual ~CTimeLogger ()
 Default constructor. More...
 
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 CDebugOutputCapable 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 ()
 
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 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...
 

Static Public Member Functions

static void printf_debug (const char *frmt,...)
 Sends a formated text to "debugOut" if not NULL, or to cout otherwise. More...
 

Private Member Functions

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

Private Attributes

CTicTac m_tictac
 
bool m_enabled
 
map< string, TCallDatam_data
 

Constructor & Destructor Documentation

◆ CTimeLogger()

mrpt::utils::CTimeLogger::CTimeLogger ( bool  enabled = true)

◆ ~CTimeLogger()

virtual mrpt::utils::CTimeLogger::~CTimeLogger ( )
virtual

Default constructor.

Destructor

Member Function Documentation

◆ clear()

void mrpt::utils::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.

◆ disable()

void mrpt::utils::CTimeLogger::disable ( )
inline

Definition at line 97 of file CTimeLogger.h.

◆ do_enter()

void mrpt::utils::CTimeLogger::do_enter ( const char *  func_name)
private

◆ do_leave()

double mrpt::utils::CTimeLogger::do_leave ( const char *  func_name)
private

◆ dumpAllStats()

void mrpt::utils::CTimeLogger::dumpAllStats ( const size_t  column_width = 80) const

Dump all stats through the CDebugOutputCapable interface.

See also
getStatsAsText, saveToCVSFile

◆ enable()

void mrpt::utils::CTimeLogger::enable ( bool  enabled = true)
inline

◆ enter()

void mrpt::utils::CTimeLogger::enter ( const char *  func_name)
inline

◆ getMeanTime()

double mrpt::utils::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.

◆ getStats()

void mrpt::utils::CTimeLogger::getStats ( std::map< std::string, TCallStats > &  out_stats) const

Returns all the current stats as a map: section_name => stats.

See also
getStatsAsText, dumpAllStats, saveToCVSFile

◆ getStatsAsText()

std::string mrpt::utils::CTimeLogger::getStatsAsText ( const size_t  column_width = 80) const

Dump all stats to a multi-line text string.

See also
dumpAllStats, saveToCVSFile

◆ leave()

double mrpt::utils::CTimeLogger::leave ( const char *  func_name)
inline

End of a named section.

Returns
The ellapsed time, in seconds or 0 if disabled.
See also
enter

Definition at line 107 of file CTimeLogger.h.

Referenced by mrpt::graphslam::optimize_graph_spa_levmarq(), and mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration().

◆ printf_debug()

static void mrpt::utils::CDebugOutputCapable::printf_debug ( const char *  frmt,
  ... 
)
staticinherited

Sends a formated text to "debugOut" if not NULL, or to cout otherwise.

Referenced by mrpt::math::CLevenbergMarquardtTempl< VECTORTYPE, USERPARAM >::execute().

◆ registerUserMeasure()

void mrpt::utils::CTimeLogger::registerUserMeasure ( const char *  event_name,
const double  value 
)

◆ saveToCSVFile()

void mrpt::utils::CTimeLogger::saveToCSVFile ( const std::string &  csv_file) const

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

See also
dumpAllStats

Member Data Documentation

◆ m_data

map<string,TCallData> mrpt::utils::CTimeLogger::m_data
private

Definition at line 77 of file CTimeLogger.h.

◆ m_enabled

bool mrpt::utils::CTimeLogger::m_enabled
private

Definition at line 64 of file CTimeLogger.h.

◆ m_tictac

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

Definition at line 63 of file CTimeLogger.h.




Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo