1 #ifndef CPPROFILER_CONDUCTOR_HH
2 #define CPPROFILER_CONDUCTOR_HH
3 
4 #include <QMainWindow>
5 #include <QStandardItemModel>
6 #include <map>
7 #include <memory>
8 #include <unordered_map>
9 
10 #include "core.hh"
11 #include "options.hh"
12 #include "settings.hh"
13 
14 namespace cpprofiler
15 {
16 
17 namespace analysis
18 {
19 class MergeWindow;
20 }
21 
22 class TcpServer;
23 class Execution;
24 class ExecutionList;
25 class ExecutionWindow;
26 class ReceiverThread;
27 class TreeBuilder;
28 class NameMap;
29 
30 struct ExecMeta
31 {
32     std::string group_name;
33     std::string ex_name;
34     std::shared_ptr<NameMap> name_map;
35 };
36 
37 class Conductor : public QMainWindow
38 {
39     Q_OBJECT
40 
41   public:
42     Conductor(Options opt, QWidget* parent = nullptr);
43 
44     ~Conductor();
45 
46     void handleStart(ReceiverThread *receiver, const std::string &ex_name,
47                      int ex_id, bool restarts);
48 
49     Execution *addNewExecution(const std::string &ex_name, int ex_id = 0,
50                                bool restarts = false);
51 
52     /// Add existing execution to the displayed list; return generated execution id
53     int addNewExecution(std::shared_ptr<Execution> ex);
54 
55     void showTraditionalView(Execution *e);
56 
57     void mergeTrees(Execution *e1, Execution *e2);
58 
59     void savePixelTree(Execution *e, const char *path, int compression_factor = 2) const;
60 
61     void saveSearch(Execution *e, const char *path) const;
62     void saveSearch(Execution *e) const;
63 
64     void runNogoodAnalysis(Execution *e1, Execution *e2);
65 
66     ExecutionWindow &getExecutionWindow(Execution *e);
67 
68     int getListenPort() const;
69 
70     int getNextExecId() const;
71 
72     void setMetaData(int exec_id, const std::string &group_name,
73                      const std::string &execution_name,
74                      std::shared_ptr<NameMap> nm);
75 
76   signals:
77 
78     void readyForBuilding(Execution *e);
79 
80     /// For a heatmap in the IDE
81     void showNogood(QString url, QString name, bool record);
82 
83     void showExecutionWindow(ExecutionWindow& e);
84 
85     void showMergeWindow(analysis::MergeWindow& m);
86   private:
87     void saveExecution(Execution *e);
88 
89     void readSettings();
90 
91     void onExecutionDone(Execution *e);
92 
93     // void getSelectedExecutions
94 
95     static constexpr quint16 DEFAULT_PORT = 6565;
96 
97     Settings settings_;
98 
99     /// Port number opened for solvers to connect to
100     quint16 listen_port_;
101 
102     std::unique_ptr<TcpServer> server_;
103 
104     Options options_;
105 
106     /// a map from execution id to an execution
107     std::unordered_map<int, std::shared_ptr<Execution>> executions_;
108 
109     /// a map from exec_id to its builder
110     std::unordered_map<int, TreeBuilder *> builders_;
111 
112     std::unique_ptr<ExecutionList> execution_list_;
113 
114     std::unordered_map<ExecID, ExecMeta> exec_meta_;
115 
116     std::unordered_map<const Execution *, ExecutionWindow*>
117         execution_windows_;
118 
119   public slots:
120 
121     void computeHeatMap(ExecID eid, std::vector<NodeID>);
122 };
123 
124 } // namespace cpprofiler
125 
126 #endif
127