profiler  0.0
dotgraph.h
1 #ifndef PROFILER_SRC_MOLPRO_PROFILER_DOTGRAPH
2 #define PROFILER_SRC_MOLPRO_PROFILER_DOTGRAPH
3 #include <sstream>
4 #include <string>
5 #include <iomanip>
6 #include <cmath>
7 
8 #include <molpro/profiler/Counter.h>
9 #include <molpro/profiler/Node.h>
10 #include <molpro/profiler/report.h>
11 
12 namespace molpro {
13 namespace profiler {
14 namespace dotgraph {
15 
16 enum EntryType{ node, edge };
17 
19 class GraphEntry{
20 
21  public:
22 
23  EntryType entry_type; // whether the entry is a node or edge
24  std::string name; // name of the node (used for labels and connectivity)
25  double runtime; // runtime of the node/edge
26  int calls; // number of calls for the node/edge
27  std::string name_to; // if this is a edge, this is where it goes to
28  std::string fontcolour; // colour of the font for an edge
29  int operations = -1; // number of operations in a node
30 
31  GraphEntry(EntryType entry_type, std::string name, double runtime, int calls,
32  double total_time, int operations = -1, std::string name_to = "" );
33 
34  std::pair<std::string, std::string> get_colours(int hot[3], int cool[3], double total_time);
35 
36 };
37 
38 // This file contains functions related to the creation of graphviz .dot files from profiles. The interface can be found
39 // in profiler::dotgraph.
40 
48 std::string blend_colours(double ratio, int hot_colour[3], int cool_colour[3]);
49 
57 std::string print_time(double time, double total_time, bool show_percentage_time);
58 
71 std::string make_box(std::string name, double time, double total_time, size_t call_count, size_t opcount,
72  int hot[3], int cool[3], bool show_percentage_time);
73 
86 std::string make_arrow(std::string name_from, std::string name_to, double time, double total_time, size_t call_count,
87  int hot[3], int cool[3], bool show_percentage_time);
88 
95 void combine_graph_entries(GraphEntry& entry1, GraphEntry& entry2);
96 
104 void merge_vec(std::vector<GraphEntry>& graph_entries);
105 
113 void apply_threshold(std::vector<GraphEntry>& graph_entries, double threshold, double total_time);
114 
121 bool has_parent(GraphEntry& child, std::vector<GraphEntry>& graph_entries);
122 
129 void destroy_orphans(std::vector<GraphEntry>& graph_entries);
130 
140 std::string get_graph_markup(std::vector<GraphEntry>& graph_entries, double total_time, int hot[3], int cool[3],
141  bool show_percentage_time);
142 
153 void make_dotgraph_vec(std::shared_ptr<Node<Counter>> root, double total_time,
154  /*out*/ std::vector<GraphEntry>& graph_entries);
155 
168 std::string make_dotgraph(std::shared_ptr<Node<Counter>> root, double total_time, int hot[3], int cool[3],
169  double threshold, bool show_percentage_time);
170 
171 } // namespace dotgraph
172 } // namespace profiler
173 } // namespace molpro
174 #endif // PROFILER_SRC_MOLPRO_PROFILER_DOTGRAPH
A node in a parameter tree storing a Counter object aliased by a name.
Definition: Node.h:20
int operations
Definition: dotgraph.h:29
std::string fontcolour
Definition: dotgraph.h:28
std::pair< std::string, std::string > get_colours(int hot[3], int cool[3], double total_time)
int calls
Definition: dotgraph.h:26
double runtime
Definition: dotgraph.h:25
std::string name
Definition: dotgraph.h:24
std::string name_to
Definition: dotgraph.h:27
GraphEntry(EntryType entry_type, std::string name, double runtime, int calls, double total_time, int operations=-1, std::string name_to="")
Definition: dotgraph.cpp:164
EntryType entry_type
Definition: dotgraph.h:23
std::string make_arrow(std::string name_from, std::string name_to, double time, double total_time, size_t call_count, int hot[3], int cool[3], bool show_percentage_time)
Create a graphviz arrow of a profiler node.
Definition: dotgraph.cpp:49
std::string make_dotgraph(std::shared_ptr< Node< Counter >> root, double total_time, int hot[3], int cool[3], double threshold, bool show_percentage_time)
This creates the complete graphviz markup for the whole performance graph, including global styles....
Definition: dotgraph.cpp:172
bool has_parent(GraphEntry &child, std::vector< GraphEntry > &graph_entries)
Determines if a node has a parent.
Definition: dotgraph.cpp:139
void apply_threshold(std::vector< GraphEntry > &graph_entries, double threshold, double total_time)
This removes any enntry from graph_entries with a runtime/total_time less than threshold.
Definition: dotgraph.cpp:127
void combine_graph_entries(GraphEntry &entry1, GraphEntry &entry2)
Combines two graph entries, summing their time, calls and opcount.
Definition: dotgraph.cpp:76
EntryType
Definition: dotgraph.h:16
@ edge
Definition: dotgraph.h:16
@ node
Definition: dotgraph.h:16
std::string print_time(double time, double total_time, bool show_percentage_time)
Returns a string with the runtime of a node.
Definition: dotgraph.cpp:26
std::string make_box(std::string name, double time, double total_time, size_t call_count, size_t opcount, int hot[3], int cool[3], bool show_percentage_time)
Create a graphviz box of a profiler node.
Definition: dotgraph.cpp:36
void destroy_orphans(std::vector< GraphEntry > &graph_entries)
Removes every element from graph_entries that does not have an edge pointing towards it (unless it's ...
Definition: dotgraph.cpp:151
std::string blend_colours(double ratio, int hot_colour[3], int cool_colour[3])
Simple additive blending of two colours. May be reduced with nicer colour blending in the future.
Definition: dotgraph.cpp:12
void make_dotgraph_vec(std::shared_ptr< Node< Counter >> root, double total_time, std::vector< GraphEntry > &graph_entries)
This populates a vector containing a GraphEntry for each profiler node. This is an intermediate data ...
Definition: dotgraph.cpp:85
std::string get_graph_markup(std::vector< GraphEntry > &graph_entries, double total_time, int hot[3], int cool[3], bool show_percentage_time)
This gets the graphviz markup for the main part of the graph (excepting global styles).
Definition: dotgraph.cpp:58
void merge_vec(std::vector< GraphEntry > &graph_entries)
Iterates through the list of GraphEntries and merges any two nodes with the same name....
Definition: dotgraph.cpp:104
Definition: Profiler.h:5