Test Failed
Push — master ( 73a01d...ef36eb )
by Nicolas
04:43
created

issue2851   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 0
1
import os
2
import sys
3
import time
4
5
import psutil
6
7
sys.path.insert(0, '../glances')
8
9
from glances.globals import disable, enable
10
from glances.main import GlancesMain
11
from glances.stats import GlancesStats
12
13
core = GlancesMain()
14
stats = GlancesStats(config=core.get_config(), args=core.get_args())
15
16
refresh = 2
17
iteration = 6
18
pid = os.getpid()
19
process = psutil.Process(pid)
20
21
print("Check Glances sensors plugin CPU consumption overhead")
22
print("=====================================================")
23
print()
24
25
print(f"Init Glances to make the stats more relevant (wait {iteration * refresh} seconds)")
26
for i in range(0, iteration):
27
    stats.update()
28
    time.sleep(refresh)
29
30
print("CPU consumption with sensors plugin disable")
31
disable(stats.get_plugin('sensors').args, 'sensors')
32
stats.get_plugin('sensors').reset()
33
cpu_start = sum(process.cpu_times()[:2])
34
for i in range(0, iteration):
35
    stats.update()
36
    print(f'{i + 1}/{iteration}: {len(stats.get_plugin("sensors").get_raw())} sensor')
37
    time.sleep(refresh)
38
cpu_end = sum(process.cpu_times()[:2])
39
cpu_without_sensors = cpu_end - cpu_start
40
print(f'Glances process consumption (user + kernel) with sensors plugin disable: {cpu_without_sensors}')
41
42
print("CPU consumption with sensors plugin enable")
43
enable(stats.get_plugin('sensors').args, 'sensors')
44
stats.get_plugin('sensors').reset()
45
cpu_start = sum(process.cpu_times()[:2])
46
for i in range(0, iteration):
47
    stats.update()
48
    print(f'{i + 1}/{iteration}: {len(stats.get_plugin("sensors").get_raw())} sensors')
49
    time.sleep(refresh)
50
cpu_end = sum(process.cpu_times()[:2])
51
cpu_with_sensors = cpu_end - cpu_start
52
print(f'Glances process consumption (user + kernel) with sensors plugin enable: {cpu_with_sensors}')
53
54
print(
55
    f'Percentage of CPU consumption increase with sensors plugin enable: \
56
 {((cpu_with_sensors - cpu_without_sensors) / cpu_without_sensors) * 100:.2f}%'
57
)
58