33 this->saveToCSVFile(sFil);
34 std::cout <<
"[MRPT global profiler] Write stats to: "<< sFil <<std::endl;
58 COutputLogger(
"CTimeLogger"),
75 m_enabled(o.m_enabled),
82 COutputLogger::operator=(o);
91 m_enabled(o.m_enabled),
98 COutputLogger::operator=(o);
122 for (
size_t p=0;
p<
s.size();
p+=
len)
134 for (
const auto e :
m_data)
137 cs.
min_t = e.second.min_t;
138 cs.
max_t = e.second.max_t;
140 cs.
mean_t = e.second.n_calls ? e.second.mean_t/ e.second.n_calls : 0;
142 cs.
last_t = e.second.last_t;
150 std::string mrpt_string =
"MRPT CTimeLogger report ";
155 int space_to_fill = top_header.size() < column_width?
156 (column_width-top_header.size())/2 : 2;
158 top_header = dashes_half + top_header + dashes_half;
159 if (dashes_half.size() % 2) {
164 std::string middle_header(
" FUNCTION #CALLS MIN.T MEAN.T MAX.T TOTAL ");
167 stats_text += top_header +
"\n";
168 stats_text += middle_header +
"\n";
169 stats_text += bottom_header +
"\n";
172 for (
const auto i :
m_data)
174 const string sMinT =
unitsFormat(i.second.min_t,1,
false);
175 const string sMaxT =
unitsFormat(i.second.max_t,1,
false);
176 const string sTotalT =
unitsFormat(i.second.mean_t,1,
false);
177 const string sMeanT =
unitsFormat(i.second.n_calls ? i.second.mean_t/i.second.n_calls : 0,1,
false);
179 stats_text+=
format(
"%s %7u %6s%c %6s%c %6s%c %6s%c\n",
181 static_cast<unsigned int>(i.second.n_calls),
182 sMinT.c_str(), i.second.has_time_units ?
's':
' ',
183 sMeanT.c_str(),i.second.has_time_units ?
's':
' ',
184 sMaxT.c_str(),i.second.has_time_units ?
's':
' ',
185 sTotalT.c_str(),i.second.has_time_units ?
's':
' ' );
189 stats_text += footer +
"\n";
197 s+=
"FUNCTION, #CALLS, LAST.T, MIN.T, MEAN.T, MAX.T, TOTAL.T\n";
198 for (
const auto &i :
m_data)
200 s+=
format(
"\"%s\",\"%7u\",\"%e\",\"%e\",\"%e\",\"%e\",\"%e\"\n",
202 static_cast<unsigned int>(i.second.n_calls),
205 i.second.n_calls ? i.second.mean_t/i.second.n_calls : 0,
219 const string s = func_name;
231 const string s = func_name;
259 const string s = event_name;
292 else return it->second.n_calls ? it->second.mean_t/it->second.n_calls : 0;
299 else return it->second.last_t;
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
void getStats(std::map< std::string, TCallStats > &out_stats) const
Returns all the current stats as a map: section_name => stats.
#define MRPT_NO_THROWS
C++11 noexcept: Used after member declarations.
const Scalar * const_iterator
void Tic()
Starts the stopwatch.
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...
MyGlobalProfiler global_profiler
mrpt::utils::CTimeLogger BASE_IMPEXP & global_profiler_getref() MRPT_NO_THROWS
void clear(bool deep_clear=false)
Resets all stats. By default (deep_clear=false), all section names are remembered (not freed) so the ...
CTimeLogger & operator=(const CTimeLogger &o)
This CStream derived class allow using a file as a write-only, binary stream.
CTimeLogger(bool enabled=true, const std::string &name="")
std::string getStatsAsText(const size_t column_width=80) const
Dump all stats to a multi-line text string.
void saveToCSVFile(const std::string &csv_file) const
Dump all stats to a Comma Separated Values (CSV) file.
double do_leave(const char *func_name)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void do_enter(const char *func_name)
Data of each call section: # of calls, minimum, maximum, average and overall execution time (in secon...
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...
virtual ~CTimeLogger()
Default constructor.
GLsizei const GLchar ** string
CTimeLoggerEntry(const CTimeLogger &logger, const char *section_name)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define MRPT_LOG_INFO_STREAM(__CONTENTS)
std::stack< double, std::vector< double > > open_calls
std::string BASE_IMPEXP 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', 1e-9->'n', 1e-6->'u', 1e-3->'m', 1->'', 1e3->'K', 1e6->'M', 1e9->'G', 1e12->'T'.
std::string aux_format_string_multilines(const std::string &s, const size_t len)
void BASE_IMPEXP global_profiler_enter(const char *func_name) MRPT_NO_THROWS
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...
GLuint const GLchar * name
double Tac()
Stops the stopwatch.
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
double leave(const char *func_name)
End of a named section.
const char * m_section_name
void BASE_IMPEXP global_profiler_leave(const char *func_name) MRPT_NO_THROWS
std::string BASE_IMPEXP 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 registerUserMeasure(const char *event_name, const double value)
GLsizei const GLfloat * value
void enter(const char *func_name)
Start of a named section.
void dumpAllStats(const size_t column_width=80) const
Dump all stats through the COutputLogger interface.
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...
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.