Responsible for timing and summarizing events. More...
#include <perf_log.h>
Public Types | |
typedef std::map< std::pair< const char *, const char * >, PerfData > | log_type |
Public Member Functions | |
PerfLog (const std::string &label_name="", const bool log_events=true) | |
~PerfLog () | |
void | clear () |
void | disable_logging () |
void | enable_logging () |
bool | logging_enabled () const |
void | fast_push (const char *label, const char *header="") |
void | push (const char *label, const char *header="") |
void | push (const std::string &label, const std::string &header="") |
void | fast_pop (const char *label, const char *header="") |
void | pop (const char *label, const char *header="") |
void | pop (const std::string &label, const std::string &header="") |
void | start_event (const std::string &label, const std::string &header="") |
void | stop_event (const std::string &label, const std::string &header="") |
void | pause_event (const std::string &label, const std::string &header="") |
void | restart_event (const std::string &label, const std::string &header="") |
std::string | get_log () const |
std::string | get_info_header () const |
std::string | get_perf_info () const |
void | print_log () const |
double | get_elapsed_time () const |
double | get_active_time () const |
PerfData | get_perf_data (const std::string &label, const std::string &header="") |
const log_type & | get_log_raw () const |
Private Member Functions | |
void | split_on_whitespace (const std::string &input, std::vector< std::string > &output) const |
Private Attributes | |
const std::string | label_name |
bool | log_events |
double | total_time |
struct timeval | tstart |
log_type | log |
std::stack< PerfData * > | log_stack |
std::map< std::string, const char * > | non_temporary_strings |
Static Private Attributes | |
static bool | called = false |
Responsible for timing and summarizing events.
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 125 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 295 of file perf_log.h.
libMesh::PerfLog::PerfLog | ( | const 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 52 of file perf_log.C.
References clear(), log_events, and tstart.
libMesh::PerfLog::~PerfLog | ( | ) |
Destructor. Calls clear()
and print_log()
.
Definition at line 66 of file perf_log.C.
References log_events, non_temporary_strings, 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 77 of file perf_log.C.
References label_name, log, log_events, log_stack, and tstart.
Referenced by libMesh::libmesh_terminate_handler(), and PerfLog().
|
inline |
Disables performance logging for an active object.
Definition at line 156 of file perf_log.h.
References log_events.
Referenced by libMesh::LibMeshInit::LibMeshInit().
|
inline |
Enables performance logging for an active object.
Definition at line 161 of file perf_log.h.
References log_events.
|
inline |
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.
Definition at line 486 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 466 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 |
|
inline |
Definition at line 519 of file perf_log.h.
References tstart.
std::string libMesh::PerfLog::get_info_header | ( | ) | const |
Definition at line 170 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 658 of file perf_log.C.
References called, get_info_header(), get_perf_info(), log, and log_events.
Referenced by print_log().
|
inline |
Also probably broken by the switch from string to const char *, though users who are liberal with "auto" might be safe.
Definition at line 305 of file perf_log.h.
References 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 696 of file perf_log.C.
References log, and non_temporary_strings.
std::string libMesh::PerfLog::get_perf_info | ( | ) | const |
Definition at line 338 of file perf_log.C.
References libMesh::PerfData::count, label_name, log, log_events, libMesh::Real, libMesh::PerfData::tot_time, libMesh::PerfData::tot_time_incl_sub, total_time, and tstart.
Referenced by get_log().
|
inline |
true
iff performance logging is enabled Definition at line 166 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 736 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 162 of file perf_log.C.
Referenced by stop_event().
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 142 of file perf_log.C.
References fast_pop(), log_events, and non_temporary_strings.
void libMesh::PerfLog::print_log | ( | ) | const |
Print the log.
Definition at line 684 of file perf_log.C.
References get_log(), log_events, and libMesh::out.
Referenced by libMesh::libmesh_terminate_handler(), 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 132 of file perf_log.C.
Referenced by start_event().
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 101 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 744 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 752 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 720 of file perf_log.C.
References push().
void libMesh::PerfLog::stop_event | ( | const std::string & | label, |
const std::string & | header = "" |
||
) |
|
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 354 of file perf_log.h.
Referenced by get_log().
|
private |
The label for this object.
Definition at line 318 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 342 of file perf_log.h.
Referenced by clear(), fast_pop(), fast_push(), get_log(), get_log_raw(), get_perf_data(), and get_perf_info().
|
private |
Flag to optionally disable all logging.
Definition at line 323 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 347 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 371 of file perf_log.h.
Referenced by get_perf_data(), pop(), push(), and ~PerfLog().
|
private |
The total running time for recorded events.
Definition at line 328 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 333 of file perf_log.h.
Referenced by clear(), get_elapsed_time(), get_perf_info(), and PerfLog().