geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
Reporter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef REPORTER_HPP_INCLUDE
7 #define REPORTER_HPP_INCLUDE
8 
9 #include <cstdint>
10 
11 #include <map>
12 #include <set>
13 #include <string>
14 #include <memory>
15 #include <vector>
16 #include <ostream>
17 #include <functional>
18 
19 namespace geopm
20 {
21  class Comm;
22  class ApplicationIO;
23  class TreeComm;
24 
31  class Reporter
32  {
33  public:
34  Reporter() = default;
35  virtual ~Reporter() = default;
39  virtual void init(void) = 0;
42  virtual void update(void) = 0;
65  virtual void generate(const std::string &agent_name,
66  const std::vector<std::pair<std::string, std::string> > &agent_report_header,
67  const std::vector<std::pair<std::string, std::string> > &agent_host_report,
68  const std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > &agent_region_report,
69  const ApplicationIO &application_io,
70  std::shared_ptr<Comm> comm,
71  const TreeComm &tree_comm) = 0;
72  virtual std::string generate(const std::string &profile_name,
73  const std::string &agent_name,
74  const std::vector<std::pair<std::string, std::string> > &agent_report_header,
75  const std::vector<std::pair<std::string, std::string> > &agent_host_report,
76  const std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > &agent_region_report) = 0;
77  virtual void total_time(double total) = 0;
78  virtual void overhead(double overhead_sec, double sample_delay) = 0;
79  };
80 
81  class PlatformIO;
82  class PlatformTopo;
83  class SampleAggregator;
85 
86  class ReporterImp : public Reporter
87  {
88  public:
89  ReporterImp(const std::string &start_time,
90  PlatformIO &platform_io,
91  const PlatformTopo &platform_topo,
92  int rank);
93  ReporterImp(const std::string &start_time,
94  PlatformIO &platform_io,
95  const PlatformTopo &platform_topo,
96  int rank,
97  std::shared_ptr<SampleAggregator> sample_agg,
98  std::shared_ptr<ProcessRegionAggregator> proc_agg,
99  const std::string &report_name,
100  const std::vector<std::pair<std::string, int> > &env_signal,
101  const std::string &policy_path,
102  bool do_endpoint,
103  const std::string &profile_name,
104  bool do_ctl_local);
105  virtual ~ReporterImp() = default;
106  void init(void) override;
107  void update(void) override;
108  void generate(const std::string &agent_name,
109  const std::vector<std::pair<std::string, std::string> > &agent_report_header,
110  const std::vector<std::pair<std::string, std::string> > &agent_host_report,
111  const std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > &agent_region_report,
112  const ApplicationIO &application_io,
113  std::shared_ptr<Comm> comm,
114  const TreeComm &tree_comm) override;
115  std::string generate(const std::string &profile_name,
116  const std::string &agent_name,
117  const std::vector<std::pair<std::string, std::string> > &agent_report_header,
118  const std::vector<std::pair<std::string, std::string> > &agent_host_report,
119  const std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > &agent_region_report) override;
120  void total_time(double total) override;
121  void overhead(double overhead_sec, double sample_delay) override;
122 
123  private:
125  static constexpr int M_SPACES_INDENT = 2;
126  // Number of levels of indentation for each section of the report
127  static constexpr int M_INDENT_HEADER = 0;
128  static constexpr int M_INDENT_HOST = 0;
129  static constexpr int M_INDENT_HOST_NAME = M_INDENT_HOST + 1;
130  static constexpr int M_INDENT_HOST_AGENT = M_INDENT_HOST_NAME + 1;
131  static constexpr int M_INDENT_REGION = M_INDENT_HOST_NAME + 1;
132  static constexpr int M_INDENT_REGION_FIELD = M_INDENT_REGION + 1;
133  static constexpr int M_INDENT_UNMARKED = M_INDENT_HOST_NAME + 1;
134  static constexpr int M_INDENT_UNMARKED_FIELD = M_INDENT_UNMARKED + 1;
135  static constexpr int M_INDENT_EPOCH = M_INDENT_HOST_NAME + 1;
136  static constexpr int M_INDENT_EPOCH_FIELD = M_INDENT_EPOCH + 1;
137  static constexpr int M_INDENT_TOTALS = M_INDENT_HOST_NAME + 1;
138  static constexpr int M_INDENT_TOTALS_FIELD = M_INDENT_TOTALS + 1;
141  void init_sync_fields(void);
143  void init_environment_signals(void);
148  std::vector<std::pair<std::string, double> > get_region_data(uint64_t region_hash);
151  double get_max_memory(void);
152  static void yaml_write(std::ostream &os, int indent_level,
153  const std::string &val);
154  static void yaml_write(std::ostream &os, int indent_level,
155  const std::vector<std::pair<std::string, std::string> > &data);
156  static void yaml_write(std::ostream &os, int indent_level,
157  const std::vector<std::pair<std::string, double> > &data);
158 
159  std::string create_header(const std::string &agent_name,
160  const std::string &profile_name,
161  const std::vector<std::pair<std::string, std::string> > &agent_report_header);
162  std::string create_report(const std::set<std::string> &region_name_set, double max_memory, double comm_overhead,
163  const std::vector<std::pair<std::string, std::string> > &agent_host_report,
164  const std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > &agent_region_report);
165  std::string gather_report(const std::string &host_report, std::shared_ptr<Comm> comm);
166 
167  std::string m_start_time;
168  std::string m_report_name;
169  PlatformIO &m_platform_io;
170  const PlatformTopo &m_platform_topo;
171  std::shared_ptr<SampleAggregator> m_sample_agg;
172  std::shared_ptr<ProcessRegionAggregator> m_proc_region_agg;
173  const std::vector<std::pair<std::string, int> > m_env_signals;
174  const std::string m_policy_path;
175  bool m_do_endpoint;
176  int m_rank;
177  double m_sticker_freq;
178  int m_epoch_count_idx;
179 
180  // Mapping from pushed signal name to index
181  std::map<std::string, int> m_sync_signal_idx;
182 
183  // Fields for each section in order. function can be
184  // passthrough, or combo of other fields
185  struct m_sync_field_s
186  {
187  std::string field_label;
188  std::vector<std::string> supporting_signals;
189  std::function<double(uint64_t, const std::vector<std::string>&)> func;
190  };
191  // All default fields supported by sample aggregator
192  std::vector<m_sync_field_s> m_sync_fields;
193 
194  // Signals added through environment
195  std::vector<std::pair<std::string, int> > m_env_signal_name_idx;
196  bool m_do_init;
197  double m_total_time;
198  double m_overhead_time;
199  double m_sample_delay;
200  const std::string m_profile_name;
201  bool m_do_ctl_local;
202  };
203 }
204 
205 #endif
Definition: ApplicationIO.hpp:27
Class responsible for reading records from the ApplicationSampler and calculating the per-process run...
Definition: ProcessRegionAggregator.hpp:20
A class used by the Controller to format the report at the end of a run. Most of the information for ...
Definition: Reporter.hpp:32
virtual void update(void)=0
Read values from PlatformIO to update aggregated samples.
virtual ~Reporter()=default
virtual void init(void)=0
Handle any initialization that must take place after the Controller has connected to the application.
virtual void total_time(double total)=0
virtual void generate(const std::string &agent_name, const std::vector< std::pair< std::string, std::string > > &agent_report_header, const std::vector< std::pair< std::string, std::string > > &agent_host_report, const std::map< uint64_t, std::vector< std::pair< std::string, std::string > > > &agent_region_report, const ApplicationIO &application_io, std::shared_ptr< Comm > comm, const TreeComm &tree_comm)=0
Create a report for this node. If the node is the root controller, format the header,...
virtual void overhead(double overhead_sec, double sample_delay)=0
Reporter()=default
virtual std::string generate(const std::string &profile_name, const std::string &agent_name, const std::vector< std::pair< std::string, std::string > > &agent_report_header, const std::vector< std::pair< std::string, std::string > > &agent_host_report, const std::map< uint64_t, std::vector< std::pair< std::string, std::string > > > &agent_region_report)=0
Definition: Reporter.hpp:87
void total_time(double total) override
Definition: Reporter.cpp:140
void update(void) override
Read values from PlatformIO to update aggregated samples.
Definition: Reporter.cpp:132
ReporterImp(const std::string &start_time, PlatformIO &platform_io, const PlatformTopo &platform_topo, int rank)
Definition: Reporter.cpp:40
void init(void) override
Handle any initialization that must take place after the Controller has connected to the application.
Definition: Reporter.cpp:117
void generate(const std::string &agent_name, const std::vector< std::pair< std::string, std::string > > &agent_report_header, const std::vector< std::pair< std::string, std::string > > &agent_host_report, const std::map< uint64_t, std::vector< std::pair< std::string, std::string > > > &agent_region_report, const ApplicationIO &application_io, std::shared_ptr< Comm > comm, const TreeComm &tree_comm) override
Create a report for this node. If the node is the root controller, format the header,...
Definition: Reporter.cpp:151
void overhead(double overhead_sec, double sample_delay) override
Definition: Reporter.cpp:145
virtual ~ReporterImp()=default
Definition: SampleAggregator.hpp:19
Definition: TreeComm.hpp:19
Definition: Accumulator.cpp:12