20 #ifndef LIBMESH_PERFLOG_H 21 #define LIBMESH_PERFLOG_H 25 #include "libmesh/libmesh_common.h" 35 #ifdef LIBMESH_HAVE_SYS_TIME_H 38 #ifndef LIBMESH_HAVE_GETTIMEOFDAY 39 #include "libmesh/win_gettimeofday.h" 213 const char * header=
"");
224 void push (
const char * label,
225 const char * header=
"");
234 void push (
const std::string & label,
235 const std::string & header=
"");
246 const char * header=
"") noexcept;
254 void pop (const
char * label,
255 const
char * header="");
264 void pop (const
std::
string & label,
265 const
std::
string & header="");
271 const
std::
string & header="");
277 const
std::
string & header="");
283 const
std::
string & header="");
289 const
std::
string & header="");
331 typedef
std::map<
std::pair<const
char *,
389 std::vector<
std::
string> & output) const;
410 this->called_recursively++;
412 this->tstart_incl_sub = this->
tstart;
428 return this->stop_or_pause(
false);
443 const double elapsed_time = (
static_cast<double>(this->
tstart.
tv_sec - tstart_tv_sec) +
444 static_cast<double>(this->
tstart.
tv_usec - tstart_tv_usec)*1.e-6);
446 this->tot_time += elapsed_time;
450 const double elapsed_time_incl_sub = (
static_cast<double>(this->
tstart.
tv_sec - this->tstart_incl_sub.tv_sec) +
451 static_cast<double>(this->
tstart.
tv_usec - this->tstart_incl_sub.tv_usec)*1.e-6);
453 this->tot_time_incl_sub += elapsed_time_incl_sub;
467 static_cast<double>(other.
tstart.
tv_usec - this->tstart.tv_usec)*1.e-6);
468 this->tot_time += elapsed_time;
485 this->called_recursively--;
486 return this->stop_or_pause(
true);
501 PerfData * perf_data = &(
log[std::make_pair(header,label)]);
515 const char * libmesh_dbg_var(header)) noexcept
530 auto it =
log.find(std::make_pair(header, label));
531 PerfData * perf_data = (it ==
log.end()) ?
nullptr : &(it->second);
539 libMesh::err <<
"PerfLog can't pop (" << header <<
',' << label <<
')' << std::endl;
540 libMesh::err <<
"No such event was found in the log, you may have a mismatched START/STOP_LOG statement." << std::endl;
552 std::deque<PerfData*> tmp_stack;
566 while (!tmp_stack.empty())
569 tmp_stack.pop_back();
612 #endif // LIBMESH_PERFLOG_H
double tot_time_incl_sub
Total time spent in this event, including sub-events.
void pop(const char *label, const char *header="")
Pop the event label off the stack, resuming any lower event.
PerfLog(std::string label_name="", const bool log_events=true)
Constructor.
void disable_summarized_logs()
Tells the PerfLog to print detailed log results (this is the default behavior)
void fast_push(const char *label, const char *header="")
Push the event label onto the stack, pausing any active event.
The PerfData class simply contains the performance data that is recorded for individual events...
void enable_logging()
Enables performance logging for an active object.
bool log_events
Flag to optionally disable all logging.
int gettimeofday(struct timeval *tp, struct timezone *tzp)
double total_time
The total running time for recorded events.
double get_elapsed_time() const
PerfData & operator+=(const PerfData &other)
Sums timing results from other.
double pause_for(PerfData &other)
void stop_event(const std::string &label, const std::string &header="")
Stop monitoring the event named label.
log_type log
The actual log.
The libMesh namespace provides an interface to certain functionality in the library.
void fast_pop(const char *label, const char *header="") noexcept
Pop the event label off the stack, resuming any lower event.
std::stack< PerfData * > log_stack
A stack to hold the current performance log trace.
bool summarized_logs_enabled()
bool summarize_logs
Flag to optionally summarize logs.
PerfData get_perf_data(const std::string &label, const std::string &header="")
Return the PerfData object associated with a label and header.
The PerfLog class allows monitoring of specific events.
void enable_summarized_logs()
Tells the PerfLog to only print log results summarized by header.
std::string get_perf_info() const
const std::string label_name
The label for this object.
double stop_or_pause(const bool do_stop)
double get_active_time() const
std::map< std::pair< const char *, const char * >, PerfData > log_type
Typdef for the underlying logging data structure.
std::string get_log() const
std::string get_info_header() const
void push(const char *label, const char *header="")
Push the event label onto the stack, pausing any active event.
void restart_event(const std::string &label, const std::string &header="")
Restart monitoring the event.
bool logging_enabled() const
void split_on_whitespace(const std::string &input, std::vector< std::string > &output) const
Splits a string on whitespace into a vector of separate strings.
struct timeval tstart
Structure defining when the event was last started.
struct timeval tstart_incl_sub
Structure defining when the event was last started, including sub-events.
void clear()
Clears all the internal data and restores the data structures to a pristine state.
double tot_time
Total time spent in this event.
void print_log() const
Print the log.
void pause_event(const std::string &label, const std::string &header="")
Suspend monitoring of the event.
unsigned int count
The number of times this event has been executed.
struct timeval tstart
The time we were constructed or last cleared.
static bool called
Flag indicating if print_log() has been called.
bool open
Flag indicating if we are currently monitoring this event.
void disable_logging()
Disables performance logging for an active object.
std::map< std::string, std::unique_ptr< const char[]> > non_temporary_strings
Workaround to give us fixed pointers to character arrays for every string.
void start_event(const std::string &label, const std::string &header="")
Start monitoring the event named label.