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):
Definition at line 41 of file CTimeLogger.h.
#include <mrpt/utils/CTimeLogger.h>
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) | |
CTimeLogger & | operator= (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 |
|
protected |
Definition at line 59 of file CTimeLogger.h.
mrpt::utils::CTimeLogger::CTimeLogger | ( | bool | enabled = true , |
const std::string & | name = "" |
||
) |
|
virtual |
Default constructor.
Destructor
mrpt::utils::CTimeLogger::CTimeLogger | ( | const CTimeLogger & | o | ) |
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.
|
inline |
Definition at line 89 of file CTimeLogger.h.
|
protected |
|
protected |
void mrpt::utils::CTimeLogger::dumpAllStats | ( | const size_t | column_width = 80 | ) | const |
Dump all stats through the COutputLogger interface.
|
inline |
Definition at line 88 of file CTimeLogger.h.
|
inline |
Start of a named section.
Definition at line 97 of file CTimeLogger.h.
Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::_execGraphSlamStep(), mrpt::graphslam::optimizers::CLevMarqGSO< GRAPH_T >::_optimizeGraph(), mrpt::bayes::detail::addNewLandmarks(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::checkPartitionsForLC(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::checkRegistrationCondition2D(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::checkRegistrationCondition3D(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::computeDominantEigenVector(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::evaluatePartitionsForLC(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::execDijkstraNodesEstimation(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::execDijkstraProjection(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::getICPEdge(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initClass(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::initializeVisuals(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::initializeVisuals(), mrpt::graphslam::optimize_graph_spa_levmarq(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::updateAllVisuals(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::updateMapPartitions(), mrpt::graphslam::deciders::CICPCriteriaNRD< GRAPH_T >::updateState(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::updateState(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::updateVisuals(), and mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::updateVisuals().
double mrpt::utils::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.
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.
Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::getDescriptiveReport().
void mrpt::utils::CTimeLogger::getStats | ( | std::map< std::string, TCallStats > & | out_stats | ) | const |
Returns all the current stats as a map: section_name => stats.
std::string mrpt::utils::CTimeLogger::getStatsAsText | ( | const size_t | column_width = 80 | ) | const |
Dump all stats to a multi-line text string.
Referenced by mrpt::graphslam::deciders::CICPCriteriaNRD< GRAPH_T >::getDescriptiveReport(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::getDescriptiveReport(), mrpt::graphslam::optimizers::CLevMarqGSO< GRAPH_T >::getDescriptiveReport(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::getDescriptiveReport(), and mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::getDescriptiveReport().
|
inline |
Definition at line 90 of file CTimeLogger.h.
References exprtk::details::value().
|
inline |
End of a named section.
Definition at line 102 of file CTimeLogger.h.
Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::_execGraphSlamStep(), mrpt::graphslam::optimizers::CLevMarqGSO< GRAPH_T >::_optimizeGraph(), mrpt::bayes::detail::addNewLandmarks(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::checkPartitionsForLC(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::checkRegistrationCondition2D(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::checkRegistrationCondition3D(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::computeDominantEigenVector(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::evaluatePartitionsForLC(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::execDijkstraNodesEstimation(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::execDijkstraProjection(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::getICPEdge(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initClass(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::initializeVisuals(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::initializeVisuals(), mrpt::graphslam::optimize_graph_spa_levmarq(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::updateAllVisuals(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::updateMapPartitions(), mrpt::graphslam::deciders::CICPCriteriaNRD< GRAPH_T >::updateState(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::updateState(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::updateVisuals(), and mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::updateVisuals().
CTimeLogger& mrpt::utils::CTimeLogger::operator= | ( | const CTimeLogger & | o | ) |
void mrpt::utils::CTimeLogger::registerUserMeasure | ( | const char * | event_name, |
const double | value | ||
) |
void mrpt::utils::CTimeLogger::saveToCSVFile | ( | const std::string & | csv_file | ) | const |
Dump all stats to a Comma Separated Values (CSV) file.
|
inline |
Definition at line 94 of file CTimeLogger.h.
Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::initClass().
|
protected |
Definition at line 60 of file CTimeLogger.h.
|
private |
Definition at line 45 of file CTimeLogger.h.
|
private |
Definition at line 46 of file CTimeLogger.h.
|
private |
Definition at line 44 of file CTimeLogger.h.
Page generated by Doxygen 1.8.13 for MRPT 1.5.3 at Sun Nov 26 00:44:48 UTC 2017 |