libMesh
|
The PerfLog
class allows monitoring of specific events.
More...
#include <perf_log.h>
Public Types | |
typedef std::map< std::pair< const char *, const char * >, PerfData > | log_type |
Typdef for the underlying logging data structure. More... | |
Public Member Functions | |
PerfLog (std::string label_name="", const bool log_events=true) | |
Constructor. More... | |
~PerfLog () | |
Destructor. More... | |
void | clear () |
Clears all the internal data and restores the data structures to a pristine state. More... | |
void | disable_logging () |
Disables performance logging for an active object. More... | |
void | enable_logging () |
Enables performance logging for an active object. More... | |
bool | logging_enabled () const |
void | enable_summarized_logs () |
Tells the PerfLog to only print log results summarized by header. More... | |
void | disable_summarized_logs () |
Tells the PerfLog to print detailed log results (this is the default behavior) More... | |
bool | summarized_logs_enabled () |
void | fast_push (const char *label, const char *header="") |
Push the event label onto the stack, pausing any active event. More... | |
void | push (const char *label, const char *header="") |
Push the event label onto the stack, pausing any active event. More... | |
void | push (const std::string &label, const std::string &header="") |
Push the event label onto the stack, pausing any active event. More... | |
void | fast_pop (const char *label, const char *header="") noexcept |
Pop the event label off the stack, resuming any lower event. More... | |
void | pop (const char *label, const char *header="") |
Pop the event label off the stack, resuming any lower event. More... | |
void | pop (const std::string &label, const std::string &header="") |
Pop the event label off the stack, resuming any lower event. More... | |
void | start_event (const std::string &label, const std::string &header="") |
Start monitoring the event named label . More... | |
void | stop_event (const std::string &label, const std::string &header="") |
Stop monitoring the event named label . More... | |
void | pause_event (const std::string &label, const std::string &header="") |
Suspend monitoring of the event. More... | |
void | restart_event (const std::string &label, const std::string &header="") |
Restart monitoring the event. More... | |
std::string | get_log () const |
std::string | get_info_header () const |
std::string | get_perf_info () const |
void | print_log () const |
Print the log. More... | |
double | get_elapsed_time () const |
double | get_active_time () const |
PerfData | get_perf_data (const std::string &label, const std::string &header="") |
Return the PerfData object associated with a label and header. More... | |
Private Member Functions | |
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. More... | |
Private Attributes | |
const std::string | label_name |
The label for this object. More... | |
bool | log_events |
Flag to optionally disable all logging. More... | |
bool | summarize_logs |
Flag to optionally summarize logs. More... | |
double | total_time |
The total running time for recorded events. More... | |
struct timeval | tstart |
The time we were constructed or last cleared. More... | |
log_type | log |
The actual log. More... | |
std::stack< PerfData * > | log_stack |
A stack to hold the current performance log trace. More... | |
std::map< std::string, std::unique_ptr< const char[]> > | non_temporary_strings |
Workaround to give us fixed pointers to character arrays for every string. More... | |
Static Private Attributes | |
static bool | called = false |
Flag indicating if print_log() has been called. More... | |
The PerfLog
class allows monitoring of specific events.
An event is defined by a unique string that functions as a label. Each time the event is executed data are recorded. This class is particularly useful for finding performance bottlenecks.
Definition at line 145 of file perf_log.h.
typedef std::map<std::pair<const char *, const char *>, PerfData> libMesh::PerfLog::log_type |
Typdef for the underlying logging data structure.
Definition at line 333 of file perf_log.h.
libMesh::PerfLog::PerfLog | ( | std::string | label_name = "" , |
const bool | log_events = true |
||
) |
Constructor.
label_name
is the name of the object, which will bw print in the log to distinguish it from other objects. log_events
is a flag to optionally disable logging. You can use this flag to turn off logging without touching any other code.
Definition at line 55 of file perf_log.C.
References clear(), gettimeofday(), log_events, and tstart.
libMesh::PerfLog::~PerfLog | ( | ) |
Destructor.
Calls clear()
and print_log()
.
Definition at line 70 of file perf_log.C.
References log_events, and print_log().
void libMesh::PerfLog::clear | ( | ) |
Clears all the internal data and restores the data structures to a pristine state.
This function checks to see if it is currently monitoring any events, and if so errors. Be sure you are not logging any events when you call this function.
Definition at line 78 of file perf_log.C.
References gettimeofday(), label_name, log, log_events, log_stack, and tstart.
Referenced by libMesh::libmesh_terminate_handler(), main(), PerfLog(), and libMesh::LibMeshInit::~LibMeshInit().
|
inline |
Disables performance logging for an active object.
Definition at line 176 of file perf_log.h.
References log_events.
Referenced by libMesh::Threads::DisablePerfLogInScope::DisablePerfLogInScope().
|
inline |
Tells the PerfLog to print detailed log results (this is the default behavior)
Definition at line 197 of file perf_log.h.
References summarize_logs.
|
inline |
Enables performance logging for an active object.
Definition at line 181 of file perf_log.h.
References log_events.
Referenced by libMesh::Threads::DisablePerfLogInScope::~DisablePerfLogInScope().
|
inline |
Tells the PerfLog to only print log results summarized by header.
Definition at line 191 of file perf_log.h.
References summarize_logs.
Referenced by main().
|
inlinenoexcept |
Pop the event label
off the stack, resuming any lower event.
This method must be passed the exact same pointers as were passed to fast_push, not merely pointers to identical strings. This method is called from the PerfItem destructor, so it should not throw. We have therefore marked it noexcept as a reminder.
Definition at line 514 of file perf_log.h.
References libMesh::err, log, log_events, log_stack, and total_time.
Referenced by pop(), and libMesh::PerfItem::~PerfItem().
|
inline |
Push the event label
onto the stack, pausing any active event.
Note - for speed the PerfLog directly considers the pointers here. Supply pointers to string literals or other character arrays whose lifetime will exceed the lifetime of the PerfLog object, not to temporarily allocated arrays.
Definition at line 494 of file perf_log.h.
References log, log_events, log_stack, libMesh::PerfData::start(), and total_time.
Referenced by libMesh::PerfItem::PerfItem(), and push().
|
inline |
Definition at line 603 of file perf_log.h.
References total_time.
|
inline |
Definition at line 591 of file perf_log.h.
References gettimeofday(), tstart, timeval::tv_sec, and timeval::tv_usec.
std::string libMesh::PerfLog::get_info_header | ( | ) | const |
Definition at line 176 of file perf_log.C.
References libMesh::Utility::get_timestamp(), libMesh::global_n_processors(), libMesh::global_processor_id(), log_events, and split_on_whitespace().
Referenced by get_log().
std::string libMesh::PerfLog::get_log | ( | ) | const |
Definition at line 671 of file perf_log.C.
References called, get_info_header(), get_perf_info(), log, and log_events.
Referenced by print_log().
PerfData libMesh::PerfLog::get_perf_data | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
Return the PerfData object associated with a label and header.
Definition at line 709 of file perf_log.C.
References libMesh::libmesh_assert(), log, and non_temporary_strings.
std::string libMesh::PerfLog::get_perf_info | ( | ) | const |
Definition at line 343 of file perf_log.C.
References libMesh::PerfData::count, gettimeofday(), label_name, log, log_events, libMesh::Real, summarize_logs, libMesh::PerfData::tot_time, libMesh::PerfData::tot_time_incl_sub, total_time, tstart, timeval::tv_sec, and timeval::tv_usec.
Referenced by get_log().
|
inline |
true
iff performance logging is enabled Definition at line 186 of file perf_log.h.
References log_events.
void libMesh::PerfLog::pause_event | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
Suspend monitoring of the event.
Definition at line 749 of file perf_log.C.
void libMesh::PerfLog::pop | ( | const char * | label, |
const char * | header = "" |
||
) |
Pop the event label
off the stack, resuming any lower event.
This method will eventually be deprecated. Use fast_pop() (with the exact same pointers supplied to fast_push()) instead.
Definition at line 168 of file perf_log.C.
Referenced by assemble_biharmonic(), assemble_laplace(), assemble_poisson(), main(), stop_event(), and UnitPerfItem::~UnitPerfItem().
void libMesh::PerfLog::pop | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
Pop the event label
off the stack, resuming any lower event.
This method will eventually be deprecated. String manipulation is too low performance to use when performance monitoring hot spots. Use fast_pop() instead.
Definition at line 148 of file perf_log.C.
References fast_pop(), libMesh::libmesh_assert(), log_events, and non_temporary_strings.
void libMesh::PerfLog::print_log | ( | ) | const |
Print the log.
Definition at line 697 of file perf_log.C.
References get_log(), log_events, and libMesh::out.
Referenced by libMesh::libmesh_terminate_handler(), libMesh::LibMeshInit::~LibMeshInit(), and ~PerfLog().
void libMesh::PerfLog::push | ( | const char * | label, |
const char * | header = "" |
||
) |
Push the event label
onto the stack, pausing any active event.
This method will eventually be deprecated. For backwards compatibility, the PerfLog must copy the contents of these character arrays into strings, which ironically damages the performance we are trying to profile. Use fast_push() (with compatible long-lived character array data) instead.
Definition at line 138 of file perf_log.C.
Referenced by assemble_biharmonic(), assemble_laplace(), assemble_poisson(), main(), start_event(), and UnitPerfItem::UnitPerfItem().
void libMesh::PerfLog::push | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
Push the event label
onto the stack, pausing any active event.
This method will eventually be deprecated. String manipulation is too low performance to use when performance monitoring hot spots. Use fast_push() instead.
Definition at line 102 of file perf_log.C.
References fast_push(), log_events, and non_temporary_strings.
void libMesh::PerfLog::restart_event | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
Restart monitoring the event.
Definition at line 757 of file perf_log.C.
|
private |
Splits a string on whitespace into a vector of separate strings.
This is used to make the LIBMESH_CONFIGURE_INFO a little more manageable.
Definition at line 765 of file perf_log.C.
Referenced by get_info_header().
void libMesh::PerfLog::start_event | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
Start monitoring the event named label
.
Definition at line 733 of file perf_log.C.
References push().
void libMesh::PerfLog::stop_event | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
Stop monitoring the event named label
.
Definition at line 741 of file perf_log.C.
References pop().
|
inline |
true
iff log results will be summarized by header Definition at line 202 of file perf_log.h.
References summarize_logs.
Referenced by DistributedVectorTest::DistributedVectorTest(), EigenSparseMatrixTest::EigenSparseMatrixTest(), EigenSparseVectorTest::EigenSparseVectorTest(), EpetraVectorTest::EpetraVectorTest(), LaspackMatrixTest::LaspackMatrixTest(), LaspackVectorTest::LaspackVectorTest(), PetscMatrixTest::PetscMatrixTest(), PetscVectorTest::PetscVectorTest(), and RealVectorValueTest::RealVectorValueTest().
|
staticprivate |
Flag indicating if print_log() has been called.
This is used to print a header with machine-specific data the first time that print_log() is called.
Definition at line 382 of file perf_log.h.
Referenced by get_log().
|
private |
The label for this object.
Definition at line 341 of file perf_log.h.
Referenced by clear(), and get_perf_info().
|
private |
The actual log.
An unsorted_map would work fine here and would be asymptotically faster, but in my tests for our log sizes there was no improvement.
Definition at line 370 of file perf_log.h.
Referenced by clear(), fast_pop(), fast_push(), get_log(), get_perf_data(), and get_perf_info().
|
private |
Flag to optionally disable all logging.
Definition at line 346 of file perf_log.h.
Referenced by clear(), disable_logging(), enable_logging(), fast_pop(), fast_push(), get_info_header(), get_log(), get_perf_info(), logging_enabled(), PerfLog(), pop(), print_log(), push(), and ~PerfLog().
|
private |
A stack to hold the current performance log trace.
Definition at line 375 of file perf_log.h.
Referenced by clear(), fast_pop(), and fast_push().
|
private |
Workaround to give us fixed pointers to character arrays for every string.
Using std::set instead might work: it won't invalidate iterators, which I think means it doesn't have any reason to modify or copy their contents or otherwise invalidate their c_str() pointers... but I can't prove it from the standards doc, so let's be safe.
Definition at line 399 of file perf_log.h.
Referenced by get_perf_data(), pop(), and push().
|
private |
Flag to optionally summarize logs.
Definition at line 351 of file perf_log.h.
Referenced by disable_summarized_logs(), enable_summarized_logs(), get_perf_info(), and summarized_logs_enabled().
|
private |
The total running time for recorded events.
Definition at line 356 of file perf_log.h.
Referenced by fast_pop(), fast_push(), get_active_time(), and get_perf_info().
|
private |
The time we were constructed or last cleared.
Definition at line 361 of file perf_log.h.
Referenced by clear(), get_elapsed_time(), get_perf_info(), libMesh::PerfData::pause_for(), PerfLog(), libMesh::PerfData::restart(), libMesh::PerfData::start(), and libMesh::PerfData::stop_or_pause().