Rose
SystemMonitor.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "Label.h"
11 #include "Signals.h"
12 #include "Timer.h"
13 
14 namespace rose {
15 
16  enum CpuTimeIndex : std::size_t {
17  USER = 0, NICE, SYSTEM, IDLE, IOWAIT, IRQ, SOFTIRQ, STEAL, GUEST, GUEST_NICE, ARRAY_SIZE
18  };
19 
24  class SystemData {
25  protected:
26  SignalSerialNumber mSignalSerialNumber{};
27 
28  bool mHasTemperatureDevice{true};
29 
33  void readCPUTemperature();
34 
38  void readProcessUsage();
39 
43  void cpuCount();
44 
45  std::array<uint64_t,CpuTimeIndex::ARRAY_SIZE> mCpuTime{};
46  std::array<uint64_t,CpuTimeIndex::ARRAY_SIZE> mPastCpuTime{};
47 
48  int mCpuCount{0};
49  float mCpuTimeUse{};
50  float mCpuTotalTime{};
51  int mProcTimeUse{};
53 
54  float mUsage{0.f};
55  float mTemperature{0.f};
56 
57  static constexpr std::string_view ProcSelfStat = "/proc/self/stat";
58  static constexpr std::string_view ProcStat = "/proc/stat";
59  static constexpr std::string_view ProcCpuInfo = "/proc/cpuinfo";
60 
61  public:
62  SystemData();
63  ~SystemData() = default;
64 
65  std::shared_ptr<Slot<int>> rxTrigger;
66 
67  using TemperatureSignal = std::array<float,3>;
69 
70  using ProcessSignal = std::array<float,3>;
72 
73  using SystemSignal = std::array<float,3>;
74  Signal<SystemSignal> txSystem{};
75  };
76 
81  class SystemMonitor : public Row {
82  protected:
86  void readCPUTemperature();
87 
91  void readProcessUsage();
92 
96  void cpuCount();
97 
101  std::shared_ptr<Label> mTemperature;
102  std::shared_ptr<Label> mUsage;
103  int mCpuCount{0};
104  int cpuTimeUse{},
105  cpuTimeStart{0};
106  int procTimeUse{},
107  procTimeStart{0};
108 
109  SecondTickPtr mSecondTick{};
110 
111  public:
112  static constexpr std::string_view ProcSelfStat = "/proc/self/stat";
113  static constexpr std::string_view ProcStat = "/proc/stat";
114  static constexpr std::string_view ProcCpuInfo = "/proc/cpuinfo";
115 
116  void initializeComposite() override;
117 
118  std::shared_ptr<Slot<int>> rxTrigger;
119 
120  SystemMonitor() = delete;
121 
122  ~SystemMonitor() override = default;
123 
128  explicit SystemMonitor(SecondTickPtr secondTick);
129  };
130 }
131 
132 
133 
Signal< ProcessSignal > txProcess
The Signal object to transmit process usage.
Definition: SystemMonitor.h:71
static constexpr std::string_view ProcSelfStat
The process stats path.
Definition: SystemMonitor.h:57
color::RGBA mCPUAlert
CPU temperature alert color.
Definition: SystemMonitor.h:99
void cpuCount()
Count the number of CPUs in the system.
Definition: SystemMonitor.cpp:255
Red Green Blue Alpha representation of a color.
Definition: Color.h:64
static constexpr std::string_view ProcCpuInfo
The CPU info path.
Definition: SystemMonitor.h:59
int mProcTimeStart
The process time use at interval start.
Definition: SystemMonitor.h:52
std::array< uint64_t, CpuTimeIndex::ARRAY_SIZE > mCpuTime
CPU current times.
Definition: SystemMonitor.h:45
std::shared_ptr< Slot< int > > rxTrigger
The slot to receive interval triggers on.
Definition: SystemMonitor.h:65
std::shared_ptr< Label > mTemperature
The Label to display temperature.
Definition: SystemMonitor.h:101
std::array< float, 3 > SystemSignal
The type used for the system usage signal.
Definition: SystemMonitor.h:73
std::shared_ptr< Slot< int > > rxTrigger
The slot to receive interval triggers on.
Definition: SystemMonitor.h:118
float mUsage
The process usage as percent of a CPU.
Definition: SystemMonitor.h:54
int mCpuCount
The number of CPUs in the system.
Definition: SystemMonitor.h:48
float mCpuTimeUse
The current CPU time use.
Definition: SystemMonitor.h:49
std::array< float, 3 > ProcessSignal
The type used for process usage signal.
Definition: SystemMonitor.h:70
bool mHasTemperatureDevice
Signal serial number identifying the object.
Definition: SystemMonitor.h:28
std::array< float, 3 > TemperatureSignal
The type used for system temperature signal.
Definition: SystemMonitor.h:67
void readCPUTemperature()
Read the CPU temperature from the system.
Definition: SystemMonitor.cpp:155
void readProcessUsage()
Read processor usage and estimate this process&#39; contribution.
Definition: SystemMonitor.cpp:180
float mTemperature
The cpu temperature.
Definition: SystemMonitor.h:55
float mCpuTotalTime
The total CPU time available.
Definition: SystemMonitor.h:50
Gather system data to transmit on Signal objects.
Definition: SystemMonitor.h:24
color::RGBA mCPUWarning
CPU temperature warning color.
Definition: SystemMonitor.h:98
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
std::shared_ptr< Label > mUsage
The Label to display usage.
Definition: SystemMonitor.h:102
static constexpr std::string_view ProcStat
The system stats apth.
Definition: SystemMonitor.h:58
std::array< uint64_t, CpuTimeIndex::ARRAY_SIZE > mPastCpuTime
CPU past times.
Definition: SystemMonitor.h:46
int mProcTimeUse
The current process time use.
Definition: SystemMonitor.h:51
Definition: Manager.h:59
Establish an intra-application signaling protocol.
A widget to display some system values to be monitored.
Definition: SystemMonitor.h:81
Signal< TemperatureSignal > txTemperature
The Signal object to transmit temperature.
Definition: SystemMonitor.h:68