geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
StatsCollector.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 STATSCOLLECTOR_HPP_INCLUDE
7 #define STATSCOLLECTOR_HPP_INCLUDE
8 
9 #include <vector>
10 #include <array>
11 #include <string>
12 #include <memory>
13 
14 #include "geopm/PlatformIO.hpp"
15 #include "geopm_stats_collector.h"
16 
17 namespace geopm
18 {
19  class RuntimeStats;
20 
23  {
24  public:
25  struct report_s {
26  std::string host;
27  std::string sample_time_first;
28  std::array<double, GEOPM_NUM_SAMPLE_STATS> sample_stats;
29  std::vector<std::string> metric_names;
30  std::vector<std::array<double, GEOPM_NUM_METRIC_STATS> > metric_stats;
31  };
32 
42  static std::unique_ptr<StatsCollector> make_unique(const std::vector<geopm_request_s> &requests);
44  StatsCollector() = default;
46  virtual ~StatsCollector() = default;
48  virtual void update(void) = 0;
57  virtual std::string report_yaml(void) const = 0;
62  virtual void reset(void) = 0;
71  virtual report_s report_struct(void) const = 0;
78  virtual size_t update_count(void) const = 0;
79  };
80 
81 
83  {
84  public:
94  StatsCollectorImp(const std::vector<geopm_request_s> &requests);
96  StatsCollectorImp(const std::vector<geopm_request_s> &requests, PlatformIO &pio);
98  ~StatsCollectorImp() = default;
99  void update(void) override;
100  std::string report_yaml(void) const override;
101  void reset(void) override;
102  report_s report_struct(void) const override;
103  size_t update_count(void) const override;
104  private:
105  std::vector<std::string> register_requests(const std::vector<geopm_request_s> &requests);
106  std::string report_yaml_curr(void) const;
107  PlatformIO &m_pio;
108  std::vector<std::string> m_metric_names;
109  std::vector<int> m_pio_idx;
110  std::shared_ptr<RuntimeStats> m_stats;
111  int m_time_pio_idx;
112  size_t m_update_count; // Number of times update() has been called
113  double m_time_sample;
114  double m_time_delta_m_1;
115  double m_time_delta_m_2;
116  std::string m_time_begin_str;
117  double m_time_begin;
118  mutable bool m_is_cached;
119  mutable std::string m_report_cache;
120  };
121 
122 }
123 
124 #endif
Class which is a collection of all valid control and signal objects for a platform.
Definition: PlatformIO.hpp:26
Class that accumulates statistics based on PlatformIO requests.
Definition: StatsCollector.hpp:23
virtual report_s report_struct(void) const =0
Return report of statistics in a structure representation.
virtual void update(void)=0
Sample PlatformIO and update all tracked signals.
virtual ~StatsCollector()=default
Default destructor.
virtual size_t update_count(void) const =0
Number of updates since last reset.
StatsCollector()=default
Default null constructor without requests.
virtual std::string report_yaml(void) const =0
Generate a YAML report of statistics.
virtual void reset(void)=0
May be called after report_yaml() to reset statistics.
static std::unique_ptr< StatsCollector > make_unique(const std::vector< geopm_request_s > &requests)
Factory access method.
Definition: StatsCollector.cpp:24
Definition: StatsCollector.hpp:83
StatsCollectorImp()
Default null constructor without requests.
Definition: StatsCollector.cpp:29
std::string report_yaml(void) const override
Generate a YAML report of statistics.
Definition: StatsCollector.cpp:107
size_t update_count(void) const override
Number of updates since last reset.
Definition: StatsCollector.cpp:205
void reset(void) override
May be called after report_yaml() to reset statistics.
Definition: StatsCollector.cpp:193
~StatsCollectorImp()=default
Default destructor.
void update(void) override
Sample PlatformIO and update all tracked signals.
Definition: StatsCollector.cpp:72
report_s report_struct(void) const override
Return report of statistics in a structure representation.
Definition: StatsCollector.cpp:116
Definition: Agg.cpp:20
Definition: StatsCollector.hpp:25
std::vector< std::string > metric_names
Definition: StatsCollector.hpp:29
std::string host
Definition: StatsCollector.hpp:26
std::vector< std::array< double, GEOPM_NUM_METRIC_STATS > > metric_stats
Definition: StatsCollector.hpp:30
std::array< double, GEOPM_NUM_SAMPLE_STATS > sample_stats
Definition: StatsCollector.hpp:28
std::string sample_time_first
Definition: StatsCollector.hpp:27