geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
ApplicationRecordLog.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 APPLICATIONRECORDLOG_HPP_INCLUDE
7 #define APPLICATIONRECORDLOG_HPP_INCLUDE
8 
9 #include <cstdint>
10 #include <cstddef>
11 #include <map>
12 #include <vector>
13 #include <memory>
14 
15 #include "geopm_time.h"
16 #include "record.hpp"
17 
18 namespace geopm
19 {
20  class SharedMemory;
21  class SharedMemoryScopedLock;
22  class Scheduler;
23 
57  {
58  public:
62  static std::unique_ptr<ApplicationRecordLog> make_unique(std::shared_ptr<SharedMemory> shmem);
64  virtual ~ApplicationRecordLog() = default;
79  virtual void enter(uint64_t hash, const geopm_time_s &time) = 0;
96  virtual void exit(uint64_t hash, const geopm_time_s &time) = 0;
106  virtual void epoch(const geopm_time_s &time) = 0;
136  virtual void dump(std::vector<record_s> &records,
137  std::vector<short_region_s> &short_regions) = 0;
138  virtual void affinity(const geopm_time_s &time, int cpu_idx) = 0;
139  virtual void cpuset_changed(const geopm_time_s &time) = 0;
140  virtual void start_profile(const geopm_time_s &time, const std::string &profile_name) = 0;
141  virtual void stop_profile(const geopm_time_s &time, const std::string &profile_name) = 0;
142  virtual void overhead(const geopm_time_s &time, double overhead_sec) = 0;
150  static size_t buffer_size(void);
158  static size_t max_record(void);
166  static size_t max_region(void);
167  protected:
168  ApplicationRecordLog() = default;
169  static constexpr size_t M_LAYOUT_SIZE = 57384;
170  static constexpr int M_MAX_RECORD = 1024;
171  static constexpr int M_MAX_REGION = M_MAX_RECORD + 1;
172  };
174  {
175  public:
176  ApplicationRecordLogImp(std::shared_ptr<SharedMemory> shmem);
177  ApplicationRecordLogImp(std::shared_ptr<SharedMemory> shmem,
178  int process,
179  std::shared_ptr<Scheduler> scheduler);
180  virtual ~ApplicationRecordLogImp() = default;
181  void enter(uint64_t hash, const geopm_time_s &time) override;
182  void exit(uint64_t hash, const geopm_time_s &time) override;
183  void epoch(const geopm_time_s &time) override;
184  void dump(std::vector<record_s> &records,
185  std::vector<short_region_s> &short_regions) override;
186  void affinity(const geopm_time_s &time, int cpu_idx) override;
187  void cpuset_changed(const geopm_time_s &time) override;
188  void start_profile(const geopm_time_s &time, const std::string &profile_name) override;
189  void stop_profile(const geopm_time_s &time, const std::string &profile_name) override;
190  void overhead(const geopm_time_s &time, double overhead_sec) override;
191  private:
192  struct m_layout_s {
193  int32_t num_record;
194  record_s record_table[M_MAX_RECORD];
195  int32_t num_region;
196  short_region_s region_table[M_MAX_REGION];
197  };
198  static_assert(sizeof(m_layout_s) <= M_LAYOUT_SIZE,
199  "Layout size used in geopmdpy/system_files.py to create shared memory footprint is smaller than required by C++ code");
200 
201  struct m_region_enter_s {
202  int record_idx;
203  int region_idx;
204  geopm_time_s enter_time;
205  bool is_short;
206  };
207  void check_reset(m_layout_s &layout);
208  void append_record(m_layout_s &layout, const record_s &record);
209  int m_process;
210  std::shared_ptr<SharedMemory> m_shmem;
211  std::map<uint64_t, m_region_enter_s> m_hash_region_enter_map;
212  uint64_t m_epoch_count;
213  uint64_t m_entered_region_hash;
214  std::shared_ptr<Scheduler> m_scheduler;
215  };
216 }
217 
218 #endif
Provides an abstraction for a shared memory buffer that can be used to pass entry,...
Definition: ApplicationRecordLog.hpp:57
static size_t max_record(void)
Gets the maximum number of records.
Definition: ApplicationRecordLog.cpp:31
virtual void dump(std::vector< record_s > &records, std::vector< short_region_s > &short_regions)=0
Get all events that have occurred since the last call to dump().
virtual void exit(uint64_t hash, const geopm_time_s &time)=0
Create a message in the log defining a region exit.
static constexpr int M_MAX_REGION
Definition: ApplicationRecordLog.hpp:171
virtual void affinity(const geopm_time_s &time, int cpu_idx)=0
virtual ~ApplicationRecordLog()=default
Destructor for pure virtual base class.
static size_t max_region(void)
Gets the maximum number of short region events.
Definition: ApplicationRecordLog.cpp:36
virtual void cpuset_changed(const geopm_time_s &time)=0
static std::unique_ptr< ApplicationRecordLog > make_unique(std::shared_ptr< SharedMemory > shmem)
Factory constructor.
Definition: ApplicationRecordLog.cpp:21
static constexpr size_t M_LAYOUT_SIZE
Definition: ApplicationRecordLog.hpp:169
virtual void overhead(const geopm_time_s &time, double overhead_sec)=0
virtual void stop_profile(const geopm_time_s &time, const std::string &profile_name)=0
virtual void epoch(const geopm_time_s &time)=0
Create a message in the log defining an epoch event.
virtual void enter(uint64_t hash, const geopm_time_s &time)=0
Create a message in the log defining a region entry.
virtual void start_profile(const geopm_time_s &time, const std::string &profile_name)=0
static size_t buffer_size(void)
Gets the shared memory size requirement.
Definition: ApplicationRecordLog.cpp:26
static constexpr int M_MAX_RECORD
Definition: ApplicationRecordLog.hpp:170
Definition: ApplicationRecordLog.hpp:174
void start_profile(const geopm_time_s &time, const std::string &profile_name) override
Definition: ApplicationRecordLog.cpp:199
void enter(uint64_t hash, const geopm_time_s &time) override
Create a message in the log defining a region entry.
Definition: ApplicationRecordLog.cpp:61
void stop_profile(const geopm_time_s &time, const std::string &profile_name) override
Definition: ApplicationRecordLog.cpp:214
void affinity(const geopm_time_s &time, int cpu_idx) override
Definition: ApplicationRecordLog.cpp:185
void cpuset_changed(const geopm_time_s &time) override
Definition: ApplicationRecordLog.cpp:174
virtual ~ApplicationRecordLogImp()=default
void overhead(const geopm_time_s &time, double overhead_sec) override
Definition: ApplicationRecordLog.cpp:229
void epoch(const geopm_time_s &time) override
Create a message in the log defining an epoch event.
Definition: ApplicationRecordLog.cpp:158
ApplicationRecordLogImp(std::shared_ptr< SharedMemory > shmem)
Definition: ApplicationRecordLog.cpp:41
void dump(std::vector< record_s > &records, std::vector< short_region_s > &short_regions) override
Get all events that have occurred since the last call to dump().
Definition: ApplicationRecordLog.cpp:244
void exit(uint64_t hash, const geopm_time_s &time) override
Create a message in the log defining a region exit.
Definition: ApplicationRecordLog.cpp:88
Definition: Accumulator.cpp:12
Record of an application event.
Definition: record.hpp:61
Definition: record.hpp:72