process-list.hh 4.73 KB
Newer Older
1
2
3
4
5
6
/* Copyright LAAS, CNRS
 * Author: O. Stasse, 2019
 * See LICENSE file in the root directory of this repository.
 */

#ifndef DYNAMIC_GRAPH_PROCESS_LIST_H_
Bergé's avatar
Bergé committed
7
#define DYNAMIC_GRAPH_PROCESS_LIST_H
8
9

#include <boost/archive/text_iarchive.hpp>
10
#include <boost/archive/text_oarchive.hpp>
11
12
#include <boost/serialization/vector.hpp>

Bergé's avatar
Bergé committed
13
#include <dynamic-graph/dynamic-graph-api.h>
14
15
16
17
18
19
20
21
22
23
24
#include <dynamic-graph/fwd.hh>

namespace dynamicgraph {
namespace CPU {
class DYNAMIC_GRAPH_DLLAPI ProcessData {};

class DYNAMIC_GRAPH_DLLAPI ProcessList {
public:
  ProcessList();
};

25
/// This class gather information on a specific CPU.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
///
class DYNAMIC_GRAPH_DLLAPI CPUData {
public:
  CPUData();
  int cpu_id_;

  inline unsigned long long int computePeriod(unsigned long long int &a,
                                              unsigned long long int &b) {
    return (a > b) ? a - b : 0;
  }

  /// \brief Various classes of time spend by the CPU
  /// @{
  /// Total time
  unsigned long long int total_time_;
  /// Time spend in user mode
  unsigned long long int user_mode_time_;
  /// Time spend in user mode with low priority (nice mode)
  unsigned long long int nice_time_;
  /// Time spend in system mode
  unsigned long long int system_time_;
  /// Time spend in system mode
  unsigned long long int system_all_time_;
  /// Time spend in doing nothing.
  unsigned long long int idle_time_;
  /// Time spend in doing nothing.
  unsigned long long int idle_all_time_;
  /// Time spend in waiting an input/output to complete.
  unsigned long long int iowait_time_;
  /// Time spend in servicing hardware interrupts.
  unsigned long long int irq_time_;
  /// Time spend in servicing software interrupts.
  unsigned long long int softirq_time_;
  /// Time spend in other operating systems in a virtualized environments
  /// Never doing this for control !
  unsigned long long int steal_time_;
  /// Time spend running a virtual CPU for guest operating systems
  /// under the control of the Linux kernel
  unsigned long long int guest_time_;
  /// Time spent running a niced guest
  /// (virtual CPU for guest operating systems under the
  /// control of the Linux kernel)
  unsigned long long int guest_nice_time_;
  /// @}

  /// \brief Various classes of time spend by the CPU by period
  /// @{
  /// Total time
  unsigned long long int total_period_;
  /// Time spend in user mode
  unsigned long long int user_mode_period_;
  /// Time spend in user mode with low priority (nice mode)
  unsigned long long int nice_period_;
  /// Time spend in system mode
  unsigned long long int system_period_;
  /// Time spend in all system mode
  unsigned long long int system_all_period_;
  /// Time spend in doing nothing.
  unsigned long long int idle_period_;
  /// Time spend in doing nothing.
  unsigned long long int idle_all_period_;
  /// Time spend in waiting an input/output to complete.
  unsigned long long int iowait_period_;
  /// Time spend in servicing hardware interrupts.
  unsigned long long int irq_period_;
  /// Time spend in servicing software interrupts.
  unsigned long long int softirq_period_;
  /// Time spend in other operating systems in a virtualized environments
  /// Never doing this for control !
  unsigned long long int steal_period_;
  /// Time spend running a virtual CPU for guest operating systems
  /// under the control of the Linux kernel
  unsigned long long int guest_period_;
  /// @}

  double percent_;
  void ProcessLine(std::istringstream &aCPULine);

  friend class boost::serialization::access;

  template <class Archive>
  void serialize(Archive &ar, const unsigned int version) {
    ar &version;
    ar &total_time_;
    ar &user_mode_time_;
    ar &nice_time_;
    ar &system_time_;
    ar &system_all_time_;
    ar &idle_time_;
    ar &idle_all_time_;
    ar &iowait_time_;
    ar &irq_time_;
    ar &softirq_time_;
    ar &steal_time_;
    ar &guest_time_;
    ar &guest_nice_time_;
    ar &percent_;
  }
};

126
/// This class gathers information on a computer.
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/// This includes a list of CPU
class DYNAMIC_GRAPH_DLLAPI System {
private:
  bool init_;

public:
  System();

  /// Read /proc/state file to extract CPU count.
  void init();

  /// Update CPU data information from /proc/stat
  void readProcStat();

  /// Friend class for serialization.
  friend class boost::serialization::access;

  /// Number of CPU.
  unsigned int cpuNb_;

  void ProcessCPULine(unsigned int cpunb, std::istringstream &aCPULine);

  /// \brief Vector of CPU informations.
  std::vector<CPUData> vCPUData_;

  /// \brief Global CPU information.
  CPUData gCPUData_;
Bergé's avatar
Bergé committed
154

155
156
157
158
159
160
161
162
163
164
  template <class Archive>
  void serialize(Archive &ar, const unsigned int version) {
    ar &version;
    ar &cpuNb_;
    ar &gCPUData_;
    ar &vCPUData_;
  }
};
} // namespace CPU
} // namespace dynamicgraph
165
166

#endif /* DYNAMIC_GRAPH_PROCESS_LIST_H_ */