Instrumental profiler for timing sections of code. More...
#include <Profiler.h>
Classes | |
struct | Proxy |
Proxy object that calls start() on creation and stop() on destruction. More... | |
Public Member Functions | |
Profiler (std::string description_, bool with_wall=true, bool with_cpu=false) | |
Construct profiler and start timing. More... | |
Profiler (Profiler &&)=default | |
Profiler & | operator= (Profiler &&)=default |
~Profiler () | |
Profiler ()=delete | |
Profiler (const Profiler &)=delete | |
Profiler & | operator= (const Profiler &)=delete |
const std::string & | description () const |
int | get_max_depth () const |
Get the maximum depth the profiler tree is allowed to reach. More... | |
void | set_max_depth (int new_max_depth) |
Set the maximum depth the profiler tree is allowed to reach. More... | |
int | get_current_depth () const |
Profiler & | start (const std::string &name) |
Traverse down to a child node and start timing. More... | |
Profiler & | stop (const std::string &name="") |
Stop the active node and traverse up to its parent. More... | |
Profiler & | stop_all () |
Stop all nodes and traverse up to the root. More... | |
profiler::Counter & | counter () |
Access counter at the top of the call stack. More... | |
Profiler & | reset (const std::string &name) |
Erases all data and starts from root again. More... | |
void | operator+= (size_t operations) |
Advance the counter holding the notional number of operations executed in the code segment. More... | |
void | operator++ () |
Advance the counter holding the notional number of operations executed in the code segment. More... | |
size_t | operator++ (int) |
Proxy | push (const std::string &name) |
Returns a proxy object which will start() on construction and stop on destruction. More... | |
std::string | str (bool cumulative=true, profiler::SortBy sort_by=profiler::SortBy::wall) const |
std::string | dotgraph (std::string path, double threshold=0.01, bool cumulative=true, int hot[3]=hot_default, int cool[3]=cool_default, SortBy sort_by=profiler::SortBy::none, std::vector< std::pair< double, double >> heat_adjust=default_heat_adjust, bool get_percentage_time=false) |
Get a graphviz .dot markup file for a profile. More... | |
Static Public Member Functions | |
static std::shared_ptr< Profiler > | single (const std::string &description_, bool with_wall=true, bool with_cpu=false) |
static std::shared_ptr< Profiler > | single () |
Access the last registered Profiler. More... | |
static void | erase (const std::string &description) |
Remove Profiler with specified description from the singleton register. More... | |
Public Attributes | |
std::shared_ptr< profiler::Node< profiler::Counter > > | root |
root node of the profiler call tree More... | |
std::shared_ptr< profiler::Node< profiler::Counter > > | active_node |
the most recent active node. More... | |
Protected Attributes | |
std::string | m_description |
name of the root node More... | |
std::string | m_root_name = "All" |
name of the root node More... | |
int | m_max_depth |
max depth level of profiler tree counting root as 0. Defaults to largest possible value. More... | |
int | m_current_depth = 0 |
current depth of the active node More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Profiler &obj) |
Instrumental profiler for timing sections of code.
Profiler constructs and navigates the call tree using start() and stop() to move between nodes or create them on first run. The profiler uses wall clock by default, but could also use cpu time, or do no timing at all and simply accumulate number of calls to each node. The maximum depth of profiler tree can be set using set_max_depth(), any nodes below max_depth are not created. This allow for profiler calls to be used in Production code without degrading the performance
|
explicit |
Construct profiler and start timing.
description_ | description of profiler |
with_wall | whether to include wall time |
with_cpu | whether to include cpu time |
|
default |
molpro::profiler::Profiler::~Profiler | ( | ) |
|
delete |
|
delete |
Counter & molpro::profiler::Profiler::counter | ( | ) |
Access counter at the top of the call stack.
|
inline |
std::string molpro::profiler::Profiler::dotgraph | ( | std::string | path, |
double | threshold = 0.01 , |
||
bool | cumulative = true , |
||
int | hot[3] = hot_default , |
||
int | cool[3] = cool_default , |
||
SortBy | sort_by = profiler::SortBy::none , |
||
std::vector< std::pair< double, double >> | heat_adjust = default_heat_adjust , |
||
bool | get_percentage_time = false |
||
) |
Get a graphviz .dot markup file for a profile.
path | path to the file to be written to disk. This should be an absolute path, as the working directory may be a temporary folder. |
threshold | - ratio of the time spent in one node to the whole runtime. If the time spent in that node is less that the threshold, the node is hidden. |
hot | the RGB values (0-255) of the 'hot' colour (a ratio of 1 will produce the hot colour, 0 the cool) |
cool | the RGB values (0-255) of the 'cool' colour. |
cumulative | whether to print the cumulative time, or to subtract the time spent in the children from a node's timings. |
sort_by | whether to sort by wall clock time, calls, frequency, etc. Currently unused! |
heat_adjust | currently unused, will eventually be used to establish non-linear mappings between ratio and colour. |
get_percentage_time | whether to show the time as a percentage of the runtime (true) or in seconds (false). |
|
static |
Remove Profiler with specified description from the singleton register.
int molpro::profiler::Profiler::get_current_depth | ( | ) | const |
Get the current depth of the call stack from root to the active node. This tracks virtual nodes beyond max_depth, even though they are not constructed.
int molpro::profiler::Profiler::get_max_depth | ( | ) | const |
void molpro::profiler::Profiler::operator++ | ( | ) |
Advance the counter holding the notional number of operations executed in the code segment.
size_t molpro::profiler::Profiler::operator++ | ( | int | ) |
void molpro::profiler::Profiler::operator+= | ( | size_t | operations | ) |
Advance the counter holding the notional number of operations executed in the code segment.
operations | The number of additional operations. |
|
inline |
Returns a proxy object which will start() on construction and stop on destruction.
Profiler & molpro::profiler::Profiler::reset | ( | const std::string & | name | ) |
Erases all data and starts from root again.
void molpro::profiler::Profiler::set_max_depth | ( | int | new_max_depth | ) |
Set the maximum depth the profiler tree is allowed to reach.
|
static |
Access the last registered Profiler.
|
static |
Access a Profiler registered with the WeakSingleton creating a new one if a Profiler instance with that description does not exist
Profiler & molpro::profiler::Profiler::start | ( | const std::string & | name | ) |
Traverse down to a child node and start timing.
name | name of the child node |
Profiler & molpro::profiler::Profiler::stop | ( | const std::string & | name = "" | ) |
Stop the active node and traverse up to its parent.
Profiler & molpro::profiler::Profiler::stop_all | ( | ) |
Stop all nodes and traverse up to the root.
std::string molpro::profiler::Profiler::str | ( | bool | cumulative = true , |
profiler::SortBy | sort_by = profiler::SortBy::wall |
||
) | const |
Produce a report on profiler as a string
cumulative | whether to use cumulative times or subtract the time spend by children |
|
friend |
std::shared_ptr<profiler::Node<profiler::Counter> > molpro::profiler::Profiler::active_node |
the most recent active node.
|
protected |
current depth of the active node
|
protected |
name of the root node
|
protected |
max depth level of profiler tree counting root as 0. Defaults to largest possible value.
|
protected |
name of the root node
std::shared_ptr<profiler::Node<profiler::Counter> > molpro::profiler::Profiler::root |
root node of the profiler call tree