|
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 process* plugins 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 process* plugins disable") |
|
31
|
|
|
for p in ['processcount', 'processlist', 'programlist']: |
|
32
|
|
|
disable(stats.get_plugin(p).args, p) |
|
33
|
|
|
stats.get_plugin(p).reset() |
|
34
|
|
|
cpu_start = sum(process.cpu_times()[:2]) |
|
35
|
|
|
for i in range(0, iteration): |
|
36
|
|
|
stats.update() |
|
37
|
|
|
print(f'{i + 1}/{iteration}') |
|
38
|
|
|
time.sleep(refresh) |
|
39
|
|
|
cpu_end = sum(process.cpu_times()[:2]) |
|
40
|
|
|
cpu_without_sensors = cpu_end - cpu_start |
|
41
|
|
|
print(f'Glances process consumption (user + kernel) with process* plugins disable: {cpu_without_sensors}') |
|
42
|
|
|
|
|
43
|
|
|
print("CPU consumption with process* plugins enable") |
|
44
|
|
|
for p in ['processcount', 'processlist', 'programlist']: |
|
45
|
|
|
enable(stats.get_plugin(p).args, p) |
|
46
|
|
|
stats.get_plugin(p).reset() |
|
47
|
|
|
cpu_start = sum(process.cpu_times()[:2]) |
|
48
|
|
|
for i in range(0, iteration): |
|
49
|
|
|
stats.update() |
|
50
|
|
|
print(f'{i + 1}/{iteration}: {len(stats.get_plugin("processlist").get_raw())} processes') |
|
51
|
|
|
time.sleep(refresh) |
|
52
|
|
|
cpu_end = sum(process.cpu_times()[:2]) |
|
53
|
|
|
cpu_with_sensors = cpu_end - cpu_start |
|
54
|
|
|
print(f'Glances process consumption (user + kernel) with process* plugins enable: {cpu_with_sensors}') |
|
55
|
|
|
|
|
56
|
|
|
print( |
|
57
|
|
|
f'Percentage of CPU consumption increase with process* plugins enable: \ |
|
58
|
|
|
{((cpu_with_sensors - cpu_without_sensors) / cpu_without_sensors) * 100:.2f}%' |
|
59
|
|
|
) |
|
60
|
|
|
|