GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/dynamic-graph/process-list.hh Lines: 25 25 100.0 %
Date: 2023-03-15 12:04:10 Branches: 2 2 100.0 %

Line Branch Exec Source
1
/* Copyright LAAS, CNRS
2
 * Author: O. Stasse, 2019
3
 * See LICENSE file in the root directory of this repository.
4
 */
5
6
#ifndef DYNAMIC_GRAPH_PROCESS_LIST_H_
7
#define DYNAMIC_GRAPH_PROCESS_LIST_H_
8
9
#include <dynamic-graph/dynamic-graph-api.h>
10
11
#include <boost/archive/text_iarchive.hpp>
12
#include <boost/archive/text_oarchive.hpp>
13
#include <boost/serialization/vector.hpp>
14
#include <dynamic-graph/fwd.hh>
15
16
namespace dynamicgraph {
17
namespace CPU {
18
class DYNAMIC_GRAPH_DLLAPI ProcessData {};
19
20
class DYNAMIC_GRAPH_DLLAPI ProcessList {
21
 public:
22
  ProcessList();
23
};
24
25
/// This class gather information on a specific CPU.
26
///
27
class DYNAMIC_GRAPH_DLLAPI CPUData {
28
 public:
29
  CPUData();
30
  int cpu_id_;
31
32
2052
  inline unsigned long long int computePeriod(unsigned long long int &a,
33
                                              unsigned long long int &b) {
34
2052
    return (a > b) ? a - b : 0;
35
  }
36
37
  /// \brief Various classes of time spend by the CPU
38
  /// @{
39
  /// Total time
40
  unsigned long long int total_time_;
41
  /// Time spend in user mode
42
  unsigned long long int user_mode_time_;
43
  /// Time spend in user mode with low priority (nice mode)
44
  unsigned long long int nice_time_;
45
  /// Time spend in system mode
46
  unsigned long long int system_time_;
47
  /// Time spend in system mode
48
  unsigned long long int system_all_time_;
49
  /// Time spend in doing nothing.
50
  unsigned long long int idle_time_;
51
  /// Time spend in doing nothing.
52
  unsigned long long int idle_all_time_;
53
  /// Time spend in waiting an input/output to complete.
54
  unsigned long long int iowait_time_;
55
  /// Time spend in servicing hardware interrupts.
56
  unsigned long long int irq_time_;
57
  /// Time spend in servicing software interrupts.
58
  unsigned long long int softirq_time_;
59
  /// Time spend in other operating systems in a virtualized environments
60
  /// Never doing this for control !
61
  unsigned long long int steal_time_;
62
  /// Time spend running a virtual CPU for guest operating systems
63
  /// under the control of the Linux kernel
64
  unsigned long long int guest_time_;
65
  /// Time spent running a niced guest
66
  /// (virtual CPU for guest operating systems under the
67
  /// control of the Linux kernel)
68
  unsigned long long int guest_nice_time_;
69
  /// @}
70
71
  /// \brief Various classes of time spend by the CPU by period
72
  /// @{
73
  /// Total time
74
  unsigned long long int total_period_;
75
  /// Time spend in user mode
76
  unsigned long long int user_mode_period_;
77
  /// Time spend in user mode with low priority (nice mode)
78
  unsigned long long int nice_period_;
79
  /// Time spend in system mode
80
  unsigned long long int system_period_;
81
  /// Time spend in all system mode
82
  unsigned long long int system_all_period_;
83
  /// Time spend in doing nothing.
84
  unsigned long long int idle_period_;
85
  /// Time spend in doing nothing.
86
  unsigned long long int idle_all_period_;
87
  /// Time spend in waiting an input/output to complete.
88
  unsigned long long int iowait_period_;
89
  /// Time spend in servicing hardware interrupts.
90
  unsigned long long int irq_period_;
91
  /// Time spend in servicing software interrupts.
92
  unsigned long long int softirq_period_;
93
  /// Time spend in other operating systems in a virtualized environments
94
  /// Never doing this for control !
95
  unsigned long long int steal_period_;
96
  /// Time spend running a virtual CPU for guest operating systems
97
  /// under the control of the Linux kernel
98
  unsigned long long int guest_period_;
99
  /// @}
100
101
  double percent_;
102
  void ProcessLine(std::istringstream &aCPULine);
103
104
  friend class boost::serialization::access;
105
106
  template <class Archive>
107
17
  void serialize(Archive &ar, const unsigned int version) {
108
17
    ar &version;
109
17
    ar &total_time_;
110
17
    ar &user_mode_time_;
111
17
    ar &nice_time_;
112
17
    ar &system_time_;
113
17
    ar &system_all_time_;
114
17
    ar &idle_time_;
115
17
    ar &idle_all_time_;
116
17
    ar &iowait_time_;
117
17
    ar &irq_time_;
118
17
    ar &softirq_time_;
119
17
    ar &steal_time_;
120
17
    ar &guest_time_;
121
17
    ar &guest_nice_time_;
122
17
    ar &percent_;
123
17
  }
124
};
125
126
/// This class gathers information on a computer.
127
/// This includes a list of CPU
128
class DYNAMIC_GRAPH_DLLAPI System {
129
 private:
130
  bool init_;
131
132
 public:
133
  System();
134
135
  /// Read /proc/state file to extract CPU count.
136
  void init();
137
138
  /// Update CPU data information from /proc/stat
139
  void readProcStat();
140
141
  /// Friend class for serialization.
142
  friend class boost::serialization::access;
143
144
  /// Number of CPU.
145
  unsigned int cpuNb_;
146
147
  void ProcessCPULine(unsigned int cpunb, std::istringstream &aCPULine);
148
149
  /// \brief Vector of CPU informations.
150
  std::vector<CPUData> vCPUData_;
151
152
  /// \brief Global CPU information.
153
  CPUData gCPUData_;
154
155
  template <class Archive>
156
1
  void serialize(Archive &ar, const unsigned int version) {
157
1
    ar &version;
158
1
    ar &cpuNb_;
159
1
    ar &gCPUData_;
160
1
    ar &vCPUData_;
161
1
  }
162
};
163
}  // namespace CPU
164
}  // namespace dynamicgraph
165
166
#endif /* DYNAMIC_GRAPH_PROCESS_LIST_H_ */