1 #ifndef PROFILER_SRC_MOLPRO_PROFILER_PROFILER_H
2 #define PROFILER_SRC_MOLPRO_PROFILER_PROFILER_H
3 #ifdef MOLPRO_PROFILER_MPI
7 #include <molpro/profiler/SortBy.h>
19 static int hot_default[3] = {255, 0, 0};
20 static int cool_default[3] = {0, 0, 255};
21 static std::vector<std::pair<double, double>> default_heat_adjust = {{}};
24 template <
class CounterT>
48 std::shared_ptr<profiler::Node<profiler::Counter>>
root;
49 std::shared_ptr<profiler::Node<profiler::Counter>>
active_node;
56 explicit Profiler(std::string description_,
bool with_wall =
true,
bool with_cpu =
false);
69 static std::shared_ptr<Profiler>
single(
const std::string& description_,
bool with_wall =
true,
70 bool with_cpu =
false);
72 static std::shared_ptr<Profiler>
single();
173 std::string
dotgraph(std::string path,
double threshold = 0.01,
bool cumulative =
true,
int hot[3] = hot_default,
175 std::vector<std::pair<double, double>> heat_adjust = default_heat_adjust,
176 bool get_percentage_time =
false);
178 #ifdef MOLPRO_PROFILER_MPI
179 std::string
str(MPI_Comm communicator,
bool cumulative =
true,
200 std::string
dotgraph(std::string path, MPI_Comm communicator,
int root_process,
double threshold = 0.01,
201 bool cumulative =
true,
int hot[3] = hot_default,
int cool[3] = cool_default,
203 std::vector<std::pair<double, double>> heat_adjust = default_heat_adjust,
204 bool get_percentage_time =
false);
Resource counter used for storing operation count, call count, timing information.
Definition: Counter.h:15
A node in a parameter tree storing a Counter object aliased by a name.
Definition: Node.h:20
Instrumental profiler for timing sections of code.
Definition: Profiler.h:41
std::shared_ptr< profiler::Node< profiler::Counter > > root
root node of the profiler call tree
Definition: Profiler.h:48
void operator++()
Advance the counter holding the notional number of operations executed in the code segment.
Definition: Profiler.cpp:78
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.
Definition: Profiler.cpp:116
profiler::Counter & counter()
Access counter at the top of the call stack.
Definition: Profiler.cpp:74
static void erase(const std::string &description)
Remove Profiler with specified description from the singleton register.
Definition: Profiler.cpp:33
int m_max_depth
max depth level of profiler tree counting root as 0. Defaults to largest possible value.
Definition: Profiler.h:45
std::shared_ptr< profiler::Node< profiler::Counter > > active_node
the most recent active node.
Definition: Profiler.h:49
std::string m_description
name of the root node
Definition: Profiler.h:43
Profiler & stop_all()
Stop all nodes and traverse up to the root.
Definition: Profiler.cpp:67
std::string m_root_name
name of the root node
Definition: Profiler.h:44
void set_max_depth(int new_max_depth)
Set the maximum depth the profiler tree is allowed to reach.
Definition: Profiler.cpp:36
Profiler & operator=(Profiler &&)=default
void operator+=(size_t operations)
Advance the counter holding the notional number of operations executed in the code segment.
Definition: Profiler.cpp:76
int get_max_depth() const
Get the maximum depth the profiler tree is allowed to reach.
Definition: Profiler.cpp:35
Profiler & start(const std::string &name)
Traverse down to a child node and start timing.
Definition: Profiler.cpp:39
std::string str(bool cumulative=true, profiler::SortBy sort_by=profiler::SortBy::wall) const
Definition: Profiler.cpp:96
const std::string & description() const
Definition: Profiler.h:65
Profiler & operator=(const Profiler &)=delete
~Profiler()
Definition: Profiler.cpp:16
friend std::ostream & operator<<(std::ostream &os, const Profiler &obj)
Definition: Profiler.cpp:151
Profiler & stop(const std::string &name="")
Stop the active node and traverse up to its parent.
Definition: Profiler.cpp:55
int m_current_depth
current depth of the active node
Definition: Profiler.h:46
Proxy push(const std::string &name)
Returns a proxy object which will start() on construction and stop on destruction.
Definition: Profiler.h:151
Profiler & reset(const std::string &name)
Erases all data and starts from root again.
Definition: Profiler.cpp:155
int get_current_depth() const
Definition: Profiler.cpp:37
Profiler(const Profiler &)=delete
static std::shared_ptr< Profiler > single()
Access the last registered Profiler.
Definition: Profiler.cpp:31
Profiler(Profiler &&)=default
SortBy
Definition: SortBy.h:7
Proxy object that calls start() on creation and stop() on destruction.
Definition: Profiler.h:126
Profiler & prof
reference to the underlying profiler
Definition: Profiler.h:127
~Proxy()
Definition: Profiler.h:130
void operator+=(size_t operations)
Advance the counter holding the notional number of operations executed in the code segment.
Definition: Profiler.cpp:86
Proxy(Profiler &prof, const std::string &name)
Definition: Profiler.h:129
void operator++()
Advance the counter holding the notional number of operations executed in the code segment.
Definition: Profiler.cpp:88
Proxy push(const std::string &name)
Push a new proxy.
Definition: Profiler.h:133