Go to the documentation of this file.
30 this->saveToCSVFile(sFil);
31 std::cout <<
"[MRPT global profiler] Write stats to: " << sFil
70 m_enabled(o.m_enabled),
77 COutputLogger::operator=(o);
85 m_enabled(o.m_enabled),
92 COutputLogger::operator=(o);
113 for (
size_t p = 0;
p <
s.size();
p +=
len)
116 if (
p +
len <
s.size()) ret +=
"\n";
124 for (
const auto e :
m_data)
127 cs.
min_t = e.second.min_t;
128 cs.
max_t = e.second.max_t;
130 cs.
mean_t = e.second.n_calls ? e.second.mean_t / e.second.n_calls : 0;
132 cs.
last_t = e.second.last_t;
140 std::string mrpt_string =
"MRPT CTimeLogger report ";
145 int space_to_fill = top_header.size() < column_width
146 ? (column_width - top_header.size()) / 2
149 top_header = dashes_half + top_header + dashes_half;
150 if (dashes_half.size() % 2)
157 " FUNCTION #CALLS MIN.T MEAN.T "
161 stats_text += top_header +
"\n";
162 stats_text += middle_header +
"\n";
163 stats_text += bottom_header +
"\n";
166 for (
const auto i :
m_data)
168 const string sMinT =
unitsFormat(i.second.min_t, 1,
false);
169 const string sMaxT =
unitsFormat(i.second.max_t, 1,
false);
170 const string sTotalT =
unitsFormat(i.second.mean_t, 1,
false);
172 i.second.n_calls ? i.second.mean_t / i.second.n_calls : 0, 1,
176 "%s %7u %6s%c %6s%c %6s%c %6s%c\n",
178 static_cast<unsigned int>(i.second.n_calls), sMinT.c_str(),
179 i.second.has_time_units ?
's' :
' ', sMeanT.c_str(),
180 i.second.has_time_units ?
's' :
' ', sMaxT.c_str(),
181 i.second.has_time_units ?
's' :
' ', sTotalT.c_str(),
182 i.second.has_time_units ?
's' :
' ');
186 stats_text += footer +
"\n";
194 s +=
"FUNCTION, #CALLS, LAST.T, MIN.T, MEAN.T, MAX.T, TOTAL.T\n";
195 for (
const auto& i :
m_data)
198 "\"%s\",\"%7u\",\"%e\",\"%e\",\"%e\",\"%e\",\"%e\"\n",
199 i.first.c_str(),
static_cast<unsigned int>(i.second.n_calls),
200 i.second.last_t, i.second.min_t,
201 i.second.n_calls ? i.second.mean_t / i.second.n_calls : 0,
202 i.second.max_t, i.second.mean_t);
204 std::ofstream(csv_file) <<
s;
214 const string s = func_name;
226 const string s = func_name;
253 const char* event_name,
const double value)
256 const string s = event_name;
275 : n_calls(0), min_t(0), max_t(0), mean_t(0), last_t(0), has_time_units(true)
285 return it->second.n_calls ? it->second.mean_t / it->second.n_calls : 0;
293 return it->second.last_t;
297 const CTimeLogger& logger,
const char* section_name)
298 : m_logger(const_cast<
CTimeLogger&>(logger)), m_section_name(section_name)
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value.
Data of each call section: # of calls, minimum, maximum, average and overall execution time (in secon...
const Scalar * const_iterator
mrpt::system::CTimeLogger & global_profiler_getref() noexcept
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X),...
MyGlobalProfiler global_profiler
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void registerUserMeasure(const char *event_name, const double value)
void enter(const char *func_name)
Start of a named section.
double do_leave(const char *func_name)
void dumpAllStats(const size_t column_width=80) const
Dump all stats through the COutputLogger interface.
void clear(bool deep_clear=false)
Resets all stats.
double leave(const char *func_name)
End of a named section.
GLuint const GLchar * name
virtual ~CTimeLogger()
Default constructor.
double Tac() noexcept
Stops the stopwatch.
void do_enter(const char *func_name)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value.
std::stack< double, std::vector< double > > open_calls
CTimeLoggerEntry(const CTimeLogger &logger, const char *section_name)
std::string unitsFormat(const double val, int nDecimalDigits=2, bool middle_space=true)
This function implements formatting with the appropriate SI metric unit prefix: 1e-12->'p',...
void Tic() noexcept
Starts the stopwatch.
void global_profiler_leave(const char *func_name) noexcept
Versatile class for consistent logging and management of output messages.
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" wit...
CTimeLogger(bool enabled=true, const std::string &name="")
void getStats(std::map< std::string, TCallStats > &out_stats) const
Returns all the current stats as a map: section_name => stats.
std::string rightPad(const std::string &str, const size_t total_len, bool truncate_if_larger=false)
Enlarge the string with spaces up to the given length.
void saveToCSVFile(const std::string &csv_file) const
Dump all stats to a Comma Separated Values (CSV) file.
std::string aux_format_string_multilines(const std::string &s, const size_t len)
GLsizei const GLfloat * value
#define MRPT_LOG_INFO_STREAM(__CONTENTS)
GLsizei const GLchar ** string
const char * m_section_name
std::string getStatsAsText(const size_t column_width=80) const
Dump all stats to a multi-line text string.
CTimeLogger & operator=(const CTimeLogger &o)
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" wit...
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
void global_profiler_enter(const char *func_name) noexcept
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |