geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
Tracer.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 TRACER_HPP_INCLUDE
7 #define TRACER_HPP_INCLUDE
8 
9 #include <fstream>
10 #include <string>
11 #include <vector>
12 #include <sstream>
13 #include <set>
14 #include <list>
15 #include <memory>
16 
17 #include "geopm/PlatformIO.hpp"
18 #include "CSV.hpp"
19 
20 namespace geopm
21 {
23  class Tracer
24  {
25  public:
26  Tracer() = default;
27  virtual ~Tracer() = default;
29  // provided by the Agent.
30  virtual void columns(const std::vector<std::string> &agent_cols,
31  const std::vector<std::function<std::string(double)> > &agent_formats) = 0;
39  virtual void update(const std::vector<double> &agent_signals) = 0;
42  virtual void flush(void) = 0;
43  };
44 
45  class PlatformIO;
46  class PlatformTopo;
47  class CSV;
48 
50  class TracerImp : public Tracer
51  {
52  public:
54  TracerImp(const std::string &start_time);
55  TracerImp(const std::string &start_time,
56  const std::string &file_path,
57  const std::string &hostname,
58  bool do_trace,
59  PlatformIO &platform_io,
60  const PlatformTopo &platform_topo,
61  const std::vector<std::pair<std::string, int> > &env_column);
63  virtual ~TracerImp() = default;
64  void columns(const std::vector<std::string> &agent_cols,
65  const std::vector<std::function<std::string(double)> > &agent_formats) override;
66  void update(const std::vector<double> &agent_signals) override;
67  void flush(void) override;
68  private:
69  struct m_request_s {
70  std::string name;
71  int domain_type;
72  int domain_idx;
73  std::function<std::string(double)> format;
74  };
75 
76  std::vector<std::string> env_signals(void);
77  std::vector<int> env_domains(void);
78  std::vector<std::function<std::string(double)> > env_formats(void);
79 
80  std::string m_file_path;
81  std::string m_header;
82  std::string m_hostname;
83  bool m_is_trace_enabled;
84 
85  PlatformIO &m_platform_io;
86  const PlatformTopo &m_platform_topo;
87  std::vector<std::pair<std::string, int> > m_env_column; // extra columns from environment
88  std::vector<int> m_column_idx; // columns sampled by TracerImp
89  std::vector<double> m_last_telemetry;
90  const size_t M_BUFFER_SIZE;
91  std::unique_ptr<CSV> m_csv;
92  int m_region_hash_idx;
93  int m_region_hint_idx;
94  int m_region_progress_idx;
95  int m_region_runtime_idx;
96  };
97 }
98 
99 #endif
CSV class provides the GEOPM interface for creation of character separated value tabular data files....
Definition: CSV.hpp:25
Abstract base class for the Tracer object defines the interface.
Definition: Tracer.hpp:24
Tracer()=default
virtual ~Tracer()=default
virtual void update(const std::vector< double > &agent_signals)=0
Update the trace with telemetry samples and region info. The Tracer samples values for default and en...
virtual void flush(void)=0
Write the remaining trace data to the file and stop tracing.
virtual void columns(const std::vector< std::string > &agent_cols, const std::vector< std::function< std::string(double)> > &agent_formats)=0
Set up default columns and add columns to be.
Class used to write a trace of the telemetry and policy.
Definition: Tracer.hpp:51
void columns(const std::vector< std::string > &agent_cols, const std::vector< std::function< std::string(double)> > &agent_formats) override
Set up default columns and add columns to be.
Definition: Tracer.cpp:60
TracerImp(const std::string &start_time)
TracerImp constructor.
Definition: Tracer.cpp:30
virtual ~TracerImp()=default
TracerImp destructor, virtual.
void update(const std::vector< double > &agent_signals) override
Update the trace with telemetry samples and region info. The Tracer samples values for default and en...
Definition: Tracer.cpp:144
void flush(void) override
Write the remaining trace data to the file and stop tracing.
Definition: Tracer.cpp:170
Definition: Accumulator.cpp:12