23
23
# FIXME Test that the instrument methods can be called concurrently safely.
24
24
25
25
26
- class ChildMeasurement (Measurement ):
27
- def __init__ (self , value , attributes = None ):
28
- super ().__init__ (value , attributes = attributes )
29
-
30
- def __eq__ (self , o : Measurement ) -> bool :
31
- return self .value == o .value and self .attributes == o .attributes
32
-
33
-
34
26
class TestCpuTimeIntegration (TestCase ):
35
27
"""Integration test of scraping CPU time from proc stat with an observable
36
28
counter"""
@@ -48,24 +40,24 @@ class TestCpuTimeIntegration(TestCase):
48
40
softirq 1644603067 0 166540056 208 309152755 8936439 0 1354908 935642970 13 222975718\n """
49
41
50
42
measurements_expected = [
51
- ChildMeasurement (6150 , {"cpu" : "cpu0" , "state" : "user" }),
52
- ChildMeasurement (3177 , {"cpu" : "cpu0" , "state" : "nice" }),
53
- ChildMeasurement (5946 , {"cpu" : "cpu0" , "state" : "system" }),
54
- ChildMeasurement (891264 , {"cpu" : "cpu0" , "state" : "idle" }),
55
- ChildMeasurement (1296 , {"cpu" : "cpu0" , "state" : "iowait" }),
56
- ChildMeasurement (0 , {"cpu" : "cpu0" , "state" : "irq" }),
57
- ChildMeasurement (8343 , {"cpu" : "cpu0" , "state" : "softirq" }),
58
- ChildMeasurement (421 , {"cpu" : "cpu0" , "state" : "guest" }),
59
- ChildMeasurement (0 , {"cpu" : "cpu0" , "state" : "guest_nice" }),
60
- ChildMeasurement (5882 , {"cpu" : "cpu1" , "state" : "user" }),
61
- ChildMeasurement (3491 , {"cpu" : "cpu1" , "state" : "nice" }),
62
- ChildMeasurement (6404 , {"cpu" : "cpu1" , "state" : "system" }),
63
- ChildMeasurement (891564 , {"cpu" : "cpu1" , "state" : "idle" }),
64
- ChildMeasurement (1244 , {"cpu" : "cpu1" , "state" : "iowait" }),
65
- ChildMeasurement (0 , {"cpu" : "cpu1" , "state" : "irq" }),
66
- ChildMeasurement (2410 , {"cpu" : "cpu1" , "state" : "softirq" }),
67
- ChildMeasurement (418 , {"cpu" : "cpu1" , "state" : "guest" }),
68
- ChildMeasurement (0 , {"cpu" : "cpu1" , "state" : "guest_nice" }),
43
+ Measurement (6150 , {"cpu" : "cpu0" , "state" : "user" }),
44
+ Measurement (3177 , {"cpu" : "cpu0" , "state" : "nice" }),
45
+ Measurement (5946 , {"cpu" : "cpu0" , "state" : "system" }),
46
+ Measurement (891264 , {"cpu" : "cpu0" , "state" : "idle" }),
47
+ Measurement (1296 , {"cpu" : "cpu0" , "state" : "iowait" }),
48
+ Measurement (0 , {"cpu" : "cpu0" , "state" : "irq" }),
49
+ Measurement (8343 , {"cpu" : "cpu0" , "state" : "softirq" }),
50
+ Measurement (421 , {"cpu" : "cpu0" , "state" : "guest" }),
51
+ Measurement (0 , {"cpu" : "cpu0" , "state" : "guest_nice" }),
52
+ Measurement (5882 , {"cpu" : "cpu1" , "state" : "user" }),
53
+ Measurement (3491 , {"cpu" : "cpu1" , "state" : "nice" }),
54
+ Measurement (6404 , {"cpu" : "cpu1" , "state" : "system" }),
55
+ Measurement (891564 , {"cpu" : "cpu1" , "state" : "idle" }),
56
+ Measurement (1244 , {"cpu" : "cpu1" , "state" : "iowait" }),
57
+ Measurement (0 , {"cpu" : "cpu1" , "state" : "irq" }),
58
+ Measurement (2410 , {"cpu" : "cpu1" , "state" : "softirq" }),
59
+ Measurement (418 , {"cpu" : "cpu1" , "state" : "guest" }),
60
+ Measurement (0 , {"cpu" : "cpu1" , "state" : "guest_nice" }),
69
61
]
70
62
71
63
def test_cpu_time_callback (self ):
@@ -78,31 +70,31 @@ def cpu_time_callback() -> Iterable[Measurement]:
78
70
if not line .startswith ("cpu" ):
79
71
break
80
72
cpu , * states = line .split ()
81
- yield ChildMeasurement (
73
+ yield Measurement (
82
74
int (states [0 ]) // 100 , {"cpu" : cpu , "state" : "user" }
83
75
)
84
- yield ChildMeasurement (
76
+ yield Measurement (
85
77
int (states [1 ]) // 100 , {"cpu" : cpu , "state" : "nice" }
86
78
)
87
- yield ChildMeasurement (
79
+ yield Measurement (
88
80
int (states [2 ]) // 100 , {"cpu" : cpu , "state" : "system" }
89
81
)
90
- yield ChildMeasurement (
82
+ yield Measurement (
91
83
int (states [3 ]) // 100 , {"cpu" : cpu , "state" : "idle" }
92
84
)
93
- yield ChildMeasurement (
85
+ yield Measurement (
94
86
int (states [4 ]) // 100 , {"cpu" : cpu , "state" : "iowait" }
95
87
)
96
- yield ChildMeasurement (
88
+ yield Measurement (
97
89
int (states [5 ]) // 100 , {"cpu" : cpu , "state" : "irq" }
98
90
)
99
- yield ChildMeasurement (
91
+ yield Measurement (
100
92
int (states [6 ]) // 100 , {"cpu" : cpu , "state" : "softirq" }
101
93
)
102
- yield ChildMeasurement (
94
+ yield Measurement (
103
95
int (states [7 ]) // 100 , {"cpu" : cpu , "state" : "guest" }
104
96
)
105
- yield ChildMeasurement (
97
+ yield Measurement (
106
98
int (states [8 ]) // 100 , {"cpu" : cpu , "state" : "guest_nice" }
107
99
)
108
100
@@ -130,54 +122,54 @@ def cpu_time_generator() -> Generator[
130
122
break
131
123
cpu , * states = line .split ()
132
124
measurements .append (
133
- ChildMeasurement (
125
+ Measurement (
134
126
int (states [0 ]) // 100 ,
135
127
{"cpu" : cpu , "state" : "user" },
136
128
)
137
129
)
138
130
measurements .append (
139
- ChildMeasurement (
131
+ Measurement (
140
132
int (states [1 ]) // 100 ,
141
133
{"cpu" : cpu , "state" : "nice" },
142
134
)
143
135
)
144
136
measurements .append (
145
- ChildMeasurement (
137
+ Measurement (
146
138
int (states [2 ]) // 100 ,
147
139
{"cpu" : cpu , "state" : "system" },
148
140
)
149
141
)
150
142
measurements .append (
151
- ChildMeasurement (
143
+ Measurement (
152
144
int (states [3 ]) // 100 ,
153
145
{"cpu" : cpu , "state" : "idle" },
154
146
)
155
147
)
156
148
measurements .append (
157
- ChildMeasurement (
149
+ Measurement (
158
150
int (states [4 ]) // 100 ,
159
151
{"cpu" : cpu , "state" : "iowait" },
160
152
)
161
153
)
162
154
measurements .append (
163
- ChildMeasurement (
155
+ Measurement (
164
156
int (states [5 ]) // 100 , {"cpu" : cpu , "state" : "irq" }
165
157
)
166
158
)
167
159
measurements .append (
168
- ChildMeasurement (
160
+ Measurement (
169
161
int (states [6 ]) // 100 ,
170
162
{"cpu" : cpu , "state" : "softirq" },
171
163
)
172
164
)
173
165
measurements .append (
174
- ChildMeasurement (
166
+ Measurement (
175
167
int (states [7 ]) // 100 ,
176
168
{"cpu" : cpu , "state" : "guest" },
177
169
)
178
170
)
179
171
measurements .append (
180
- ChildMeasurement (
172
+ Measurement (
181
173
int (states [8 ]) // 100 ,
182
174
{"cpu" : cpu , "state" : "guest_nice" },
183
175
)
0 commit comments