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 
7 #include <molpro/profiler/Counter.h>
8 #include <molpro/profiler/Node.h>
9 #include <molpro/profiler/Profiler.h>
10 #include <molpro/profiler/SortBy.h>
11 #include <molpro/profiler/dotgraph.h>
12 
13 #include <list>
14 #include <memory>
15 #include <ostream>
16 #include <string>
17 #include <vector>
18 
19 namespace molpro {
20 namespace profiler {
21 
43 void report(const std::shared_ptr<Node<Counter>>& root, const std::string& description, std::ostream& out,
44  bool cumulative = true, SortBy sort_by = SortBy::wall);
45 
53 void report(const Profiler& prof, std::ostream& out, bool cumulative = true, SortBy sort_by = SortBy::wall);
54 
55 #ifdef MOLPRO_PROFILER_MPI
56 void report(const Profiler& prof, std::ostream& out, MPI_Comm communicator, bool cumulative = true,
57  SortBy sort_by = SortBy::wall);
59 void report_root_process(const Profiler& prof, std::ostream& out, MPI_Comm communicator, int root_process,
60  bool cumulative = true, SortBy sort_by = SortBy::wall);
61 std::string get_dotgraph(const Profiler& prof, MPI_Comm communicator, int root_process, int* hot, int* cool,
62  double threshold, bool get_percentage_time);
63 #endif
64 std::string get_dotgraph(const Profiler& prof, int hot[3], int cool[3], double threshold, bool get_percentage_time);
65 
66 namespace detail {
68 struct TreePath {
70  explicit TreePath(std::shared_ptr<Node<Counter>> node, bool cumulative);
71 
84  static std::list<TreePath> convert_tree_to_paths(const std::shared_ptr<Node<Counter>>& root, bool cumulative,
85  SortBy sort_by);
86 
87 private:
88  template <class CompareTreePaths>
89  static std::list<TreePath> convert_tree_to_paths(const std::shared_ptr<Node<Counter>>& root, TreePath path,
90  bool cumulative);
91 
92 public:
94  std::list<std::string> path;
95  size_t depth = 0;
96 };
97 
99 std::list<std::string> path_to_node(std::shared_ptr<Node<Counter>> node);
100 
102 size_t total_operation_count(const std::shared_ptr<Node<Counter>>& node);
103 
106 template <class AccessParameter>
107 struct Compare {
108  bool operator()(const TreePath& l, const TreePath& r) const {
109  bool depth_check = l.depth < r.depth;
110  bool parameter_check = AccessParameter{}(l) > AccessParameter{}(r);
111  bool result = depth_check ? depth_check : parameter_check;
112  if (!result) {
113  if (l.depth == r.depth && AccessParameter{}(l) == AccessParameter{}(r)) {
114  result = true;
115  }
116  }
117  return result;
118  }
119 };
120 struct AccessWall {
121  double operator()(const TreePath& t) { return t.counter.get_wall().cumulative_time(); }
122 };
123 struct AccessCPU {
124  double operator()(const TreePath& t) { return t.counter.get_cpu().cumulative_time(); }
125 };
126 struct AccessCalls {
127  double operator()(const TreePath& t) { return t.counter.get_call_count(); }
128 };
130  double operator()(const TreePath& t) { return t.counter.get_operation_count(); }
131 };
132 struct None {
133  double operator()(const TreePath& t) { return 0; }
134  double operator()() {return 0;}
135 };
136 
145 std::string format_path_cumulative(const std::list<std::string>& path);
146 
155 std::string format_path_not_cumulative(const std::list<std::string>& path);
156 
157 inline std::string format_single_path(const std::list<std::string>& path, bool cumulative) {
158  if (cumulative)
159  return format_path_cumulative(path);
160  else
161  return format_path_not_cumulative(path);
162 }
163 
170 template <class CompareTreePaths>
171 std::map<TreePath, std::shared_ptr<Node<Counter>>, CompareTreePaths> sort_children(
172  const std::shared_ptr<Node<Counter>>& root, bool cumulative);
173 
183 void format_paths(std::list<std::string>& path_names, bool append);
184 
191 std::string frequency(size_t n_op, double time);
192 
193 std::string seconds(double time);
194 
195 void write_timing(std::ostream& out, double time, size_t n_op);
196 
198 void write_report(const Node<Counter>& root, const std::string& description, const std::list<TreePath>& paths,
199  std::ostream& out, bool cumulative);
200 
201 #ifdef MOLPRO_PROFILER_MPI
219 std::shared_ptr<Node<Counter>> synchronised_tree(const std::shared_ptr<Node<Counter>>& node,
220  const std::shared_ptr<Node<Counter>>& parent, MPI_Comm comm,
221  int root_process);
222 
223 void reduce_all(long long int& operation_count, double& wall_time, double& cpu_time, MPI_Comm comm);
224 void reduce_root_only(long long int& operation_count, double& wall_time, double& cpu_time, MPI_Comm comm,
225  int root_process);
226 #endif
227 
228 } // namespace detail
229 } // namespace profiler
230 } // namespace molpro
231 
232 #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
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:157
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
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
std::string get_dotgraph(const Profiler &prof, int hot[3], int cool[3], double threshold, bool get_percentage_time)
Definition: report.cpp:313
SortBy
Definition: SortBy.h:7
Definition: Profiler.h:5
profiler::Profiler Profiler
Definition: Profiler.h:6
Definition: report.h:123
double operator()(const TreePath &t)
Definition: report.h:124
double operator()(const TreePath &t)
Definition: report.h:127
double operator()(const TreePath &t)
Definition: report.h:130
Definition: report.h:120
double operator()(const TreePath &t)
Definition: report.h:121
Definition: report.h:107
bool operator()(const TreePath &l, const TreePath &r) const
Definition: report.h:108
Definition: report.h:132
double operator()()
Definition: report.h:134
double operator()(const TreePath &t)
Definition: report.h:133
Utility for storing a node as a path from root to that node and corresponding Counter.
Definition: report.h:68
size_t depth
depth of the node (root is 0)
Definition: report.h:95
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:93
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:94