20#ifndef LIBMESH_PERFLOG_H
21#define LIBMESH_PERFLOG_H
25#include "libmesh/libmesh_common.h"
27#include "libmesh/threads.h"
37#ifdef LIBMESH_HAVE_SYS_TIME_H
40#ifndef LIBMESH_HAVE_GETTIMEOFDAY
41#include "libmesh/win_gettimeofday.h"
43#ifdef LIBMESH_HAVE_NVTX_API
44#include <nvtx3/nvtx3.hpp>
46#ifdef LIBMESH_HAVE_OPENMP
229 const char * header=
"",
230 bool per_entity=
false);
241 void push (
const char * label,
242 const char * header=
"");
251 void push (
const std::string & label,
252 const std::string & header=
"");
266 const char * header=
"",
267 bool per_entity=
false) noexcept;
275 void pop (const
char * label,
276 const
char * header="");
285 void pop (const
std::
string & label,
286 const
std::
string & header="");
292 const
std::
string & header="");
298 const
std::
string & header="");
304 const
std::
string & header="");
310 const
std::
string & header="");
352 typedef
std::map<
std::pair<const
char *,
410 std::vector<
std::
string> & output) const;
431 this->called_recursively++;
433 this->tstart_incl_sub = this->
tstart;
449 return this->stop_or_pause(
false);
464 const double elapsed_time = (
static_cast<double>(this->
tstart.
tv_sec - tstart_tv_sec) +
465 static_cast<double>(this->
tstart.
tv_usec - tstart_tv_usec)*1.e-6);
467 this->tot_time += elapsed_time;
471 const double elapsed_time_incl_sub = (
static_cast<double>(this->
tstart.
tv_sec - this->tstart_incl_sub.tv_sec) +
472 static_cast<double>(this->
tstart.
tv_usec - this->tstart_incl_sub.tv_usec)*1.e-6);
474 this->tot_time_incl_sub += elapsed_time_incl_sub;
488 static_cast<double>(other.
tstart.
tv_usec - this->tstart.tv_usec)*1.e-6);
489 this->tot_time += elapsed_time;
506 this->called_recursively--;
507 return this->stop_or_pause(
true);
519#ifndef LIBMESH_HAVE_NVTX_API
528#ifdef LIBMESH_HAVE_OPENMP
531 libmesh_assert_equal_to(omp_get_num_threads(), 1);
536 PerfData * perf_data = &(
log[std::make_pair(header,label)]);
544#ifdef LIBMESH_HAVE_NVTX_API
550 nvtxRangePushA(label);
559 const char * libmesh_dbg_var(header),
560 bool per_entity)
noexcept
562#ifndef LIBMESH_HAVE_NVTX_API
571#ifdef LIBMESH_HAVE_OPENMP
574 libmesh_exceptionless_assert(omp_get_num_threads() == 1);
577#ifdef LIBMESH_HAVE_NVTX_API
592 auto it =
log.find(std::make_pair(header, label));
593 PerfData * perf_data = (it ==
log.end()) ?
nullptr : &(it->second);
601 libMesh::err <<
"PerfLog can't pop (" << header <<
',' << label <<
')' << std::endl;
602 libMesh::err <<
"No such event was found in the log, you may have a mismatched START/STOP_LOG statement." << std::endl;
614 std::deque<PerfData*> tmp_stack;
628 while (!tmp_stack.empty())
631 tmp_stack.pop_back();
The PerfData class simply contains the performance data that is recorded for individual events.
double tot_time_incl_sub
Total time spent in this event, including sub-events.
PerfData & operator+=(const PerfData &other)
Sums timing results from other.
double pause_for(PerfData &other)
double stop_or_pause(const bool do_stop)
struct timeval tstart_incl_sub
Structure defining when the event was last started, including sub-events.
double tot_time
Total time spent in this event.
unsigned int count
The number of times this event has been executed.
struct timeval tstart
Structure defining when the event was last started.
bool open
Flag indicating if we are currently monitoring this event.
The PerfLog class allows monitoring of specific events.
void start_event(const std::string &label, const std::string &header="")
Start monitoring the event named label.
bool summarized_logs_enabled()
void print_log() const
Print the log.
double total_time
The total running time for recorded events.
void disable_logging()
Disables performance logging for an active object.
void pop(const char *label, const char *header="")
Pop the event label off the stack, resuming any lower event.
void clear()
Clears all the internal data and restores the data structures to a pristine state.
void fast_push(const char *label, const char *header="", bool per_entity=false)
Push the event label onto the stack, pausing any active event.
std::string get_log() const
void restart_event(const std::string &label, const std::string &header="")
Restart monitoring the event.
std::string get_perf_info() const
double get_active_time() const
double get_elapsed_time() const
log_type log
The actual log.
std::map< std::string, std::unique_ptr< const char[]> > non_temporary_strings
Workaround to give us fixed pointers to character arrays for every string.
std::map< std::pair< const char *, const char * >, PerfData > log_type
Typdef for the underlying logging data structure.
struct timeval tstart
The time we were constructed or last cleared.
void enable_logging()
Enables performance logging for an active object.
bool summarize_logs
Flag to optionally summarize logs.
void enable_summarized_logs()
Tells the PerfLog to only print log results summarized by header.
void push(const char *label, const char *header="")
Push the event label onto the stack, pausing any active event.
void pause_event(const std::string &label, const std::string &header="")
Suspend monitoring of the event.
const std::string label_name
The label for this object.
PerfData get_perf_data(const std::string &label, const std::string &header="")
Return the PerfData object associated with a label and header.
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.
std::string get_info_header() const
void fast_pop(const char *label, const char *header="", bool per_entity=false) noexcept
Pop the event label off the stack, resuming any lower event.
void stop_event(const std::string &label, const std::string &header="")
Stop monitoring the event named label.
static bool called
Flag indicating if print_log() has been called.
bool log_events
Flag to optionally disable all logging.
void disable_summarized_logs()
Tells the PerfLog to print detailed log results (this is the default behavior)
std::stack< PerfData * > log_stack
A stack to hold the current performance log trace.
int active_threads
An integer which is set to the number of active threads when we are in a Threads:: parallel operation...
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)
int gettimeofday(struct timeval *tp, struct timezone *tzp)