profiler  0.0
report.h
1 #ifndef PROFILER_SRC_MOLPRO_PROFILER_TREE_REPORT_H
2 #define PROFILER_SRC_MOLPRO_PROFILER_TREE_REPORT_H
3 #ifdef MOLPRO_PROFILER_MPI
4 // #include <mpi.h>
5 #endif
6 #include <molpro/mpi.h>
7 
8 #include <molpro/profiler/Counter.h>
9 #include <molpro/profiler/Node.h>
10 #include <molpro/profiler/Profiler.h>
11 #include <molpro/profiler/SortBy.h>
12 #include <molpro/profiler/dotgraph.h>
13 
14 #include <list>
15 #include <memory>
16 #include <ostream>
17 #include <string>
18 #include <vector>
19 
20 namespace molpro {
21 namespace profiler {
22 
44 void report(const std::shared_ptr<Node<Counter>>& root, const std::string& description, std::ostream& out,
45  bool cumulative = true, SortBy sort_by = SortBy::wall);
46 
54 void report(const Profiler& prof, std::ostream& out, bool cumulative = true, SortBy sort_by = SortBy::wall);
55 
56 // #ifdef MOLPRO_PROFILER_MPI
57 void report(const Profiler& prof, std::ostream& out, MPI_Comm communicator, bool cumulative = true,
58  SortBy sort_by = SortBy::wall);
60 void report_root_process(const Profiler& prof, std::ostream& out, MPI_Comm communicator, int root_process,
61  bool cumulative = true, SortBy sort_by = SortBy::wall);
62 std::string get_dotgraph(const Profiler& prof, MPI_Comm communicator, int root_process, int* hot, int* cool,
63  double threshold, bool get_percentage_time);
64 // #endif
65 std::string get_dotgraph(const Profiler& prof, int hot[3], int cool[3], double threshold, bool get_percentage_time);
66 
67 namespace detail {
69 struct TreePath {
71  explicit TreePath(std::shared_ptr<Node<Counter>> node, bool cumulative);
72 
85  static std::list<TreePath> convert_tree_to_paths(const std::shared_ptr<Node<Counter>>& root, bool cumulative,
86  SortBy sort_by);
87 
88 private:
89  template <class CompareTreePaths>
90  static std::list<TreePath> convert_tree_to_paths(const std::shared_ptr<Node<Counter>>& root, TreePath path,
91  bool cumulative);
92 
93 public:
95  std::list<std::string> path;
96  size_t depth = 0;
97 };
98 
100 std::list<std::string> path_to_node(std::shared_ptr<Node<Counter>> node);
101 
103 size_t total_operation_count(const std::shared_ptr<Node<Counter>>& node);
104 
107 template <class AccessParameter>
108 struct Compare {
109  bool operator()(const TreePath& l, const TreePath& r) const {
110  bool depth_check = l.depth < r.depth;
111  bool parameter_check = AccessParameter{}(l) > AccessParameter{}(r);
112  bool result = depth_check ? depth_check : parameter_check;
113  if (!result) {
114  if (l.depth == r.depth && AccessParameter{}(l) == AccessParameter{}(r)) {
115  result = true;
116  }
117  }
118  return result;
119  }
120 };
121 struct AccessWall {
122  double operator()(const TreePath& t) { return t.counter.get_wall().cumulative_time(); }
123 };
124 struct AccessCPU {
125  double operator()(const TreePath& t) { return t.counter.get_cpu().cumulative_time(); }
126 };
127 struct AccessCalls {
128  double operator()(const TreePath& t) { return t.counter.get_call_count(); }
129 };
131  double operator()(const TreePath& t) { return t.counter.get_operation_count(); }
132 };
133 struct None {
134  double operator()(const TreePath& t) { return 0; }
135  double operator()() {return 0;}
136 };
137 
146 std::string format_path_cumulative(const std::list<std::string>& path);
147 
156 std::string format_path_not_cumulative(const std::list<std::string>& path);
157 
158 inline std::string format_single_path(const std::list<std::string>& path, bool cumulative) {
159  if (cumulative)
160  return format_path_cumulative(path);
161  else
162  return format_path_not_cumulative(path);
163 }
164 
171 template <class CompareTreePaths>
172 std::map<TreePath, std::shared_ptr<Node<Counter>>, CompareTreePaths> sort_children(
173  const std::shared_ptr<Node<Counter>>& root, bool cumulative);
174 
184 void format_paths(std::list<std::string>& path_names, bool append);
185 
192 std::string frequency(size_t n_op, double time);
193 
194 std::string seconds(double time);
195 
196 void write_timing(std::ostream& out, double time, size_t n_op);
197 
199 void write_report(const Node<Counter>& root, const std::string& description, const std::list<TreePath>& paths,
200  std::ostream& out, bool cumulative);
201 
202 #ifdef MOLPRO_PROFILER_MPI
220 std::shared_ptr<Node<Counter>> synchronised_tree(const std::shared_ptr<Node<Counter>>& node,
221  const std::shared_ptr<Node<Counter>>& parent, MPI_Comm comm,
222  int root_process);
223 
224 void reduce_all(long long int& operation_count, double& wall_time, double& cpu_time, MPI_Comm comm);
225 void reduce_root_only(long long int& operation_count, double& wall_time, double& cpu_time, MPI_Comm comm,
226  int root_process);
227 #endif
228 
229 } // namespace detail
230 } // namespace profiler
231 } // namespace molpro
232 
233 #endif // PROFILER_SRC_MOLPRO_PROFILER_TREE_REPORT_H
Resource counter used for storing operation count, call count, timing information.
Definition: Counter.h:15
size_t get_operation_count() const
Definition: Counter.h:40
const Timer & get_cpu() const
Definition: Counter.h:41
size_t get_call_count() const
Definition: Counter.h:39
const Timer & get_wall() const
Definition: Counter.h:42
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:42
double cumulative_time() const
Cumulative time over all start/stop periods. If active than it includes the time from start to curren...
Definition: Timer.cpp:42
std::string format_path_cumulative(const std::list< std::string > &path)
convert path to a formatted string
Definition: report.cpp:53
std::string format_single_path(const std::list< std::string > &path, bool cumulative)
Definition: report.h:158
std::string format_path_not_cumulative(const std::list< std::string > &path)
convert path to a formatted string
Definition: report.cpp:62
size_t total_operation_count(const std::shared_ptr< Node< Counter >> &node)
Performs depth first search through the tree and accumulates operation counter value.
Definition: report.cpp:43
std::list< std::string > path_to_node(std::shared_ptr< Node< Counter >> node)
Returns path of node names from root to node.
Definition: report.cpp:34
std::string get_dotgraph(const Profiler &prof, MPI_Comm communicator, int root_process, int *hot, int *cool, double threshold, bool get_percentage_time)
void report(const std::shared_ptr< Node< Counter >> &root, const std::string &description, std::ostream &out, bool cumulative=true, SortBy sort_by=SortBy::wall)
Reports the content of a Profiler call subtree.
Definition: report.cpp:209
void report_root_process(const Profiler &prof, std::ostream &out, MPI_Comm communicator, int root_process, bool cumulative=true, SortBy sort_by=SortBy::wall)
Reports collective content of Profiler but writing on the root process only.
SortBy
Definition: SortBy.h:7
Definition: Profiler.h:5
profiler::Profiler Profiler
Definition: Profiler.h:6
Definition: report.h:124
double operator()(const TreePath &t)
Definition: report.h:125
double operator()(const TreePath &t)
Definition: report.h:128
double operator()(const TreePath &t)
Definition: report.h:131
Definition: report.h:121
double operator()(const TreePath &t)
Definition: report.h:122
Definition: report.h:108
bool operator()(const TreePath &l, const TreePath &r) const
Definition: report.h:109
Definition: report.h:133
double operator()()
Definition: report.h:135
double operator()(const TreePath &t)
Definition: report.h:134
Utility for storing a node as a path from root to that node and corresponding Counter.
Definition: report.h:69
size_t depth
depth of the node (root is 0)
Definition: report.h:96
static std::list< TreePath > convert_tree_to_paths(const std::shared_ptr< Node< Counter >> &root, bool cumulative, SortBy sort_by)
Performs Depth-First-Search and converts the whole tree to a list of TreePath objects.
Definition: report.cpp:94
Counter counter
copy of the counter object with cumulative effects or lack of them already accounted
Definition: report.h:94
TreePath(std::shared_ptr< Node< Counter >> node, bool cumulative)
Processes path from root nodes into list of strings and copies Counter accounting for cumulative effe...
Definition: report.cpp:14
std::list< std::string > path
concatenation of names from root to the node
Definition: report.h:95