| Total Complexity | 0 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 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 | iteration = 6 |
||
| 17 | pid = os.getpid() |
||
| 18 | process = psutil.Process(pid) |
||
| 19 | |||
| 20 | print(f"Init Glances to make the stats more relevant (wait {iteration} seconds)") |
||
| 21 | for i in range(0, iteration): |
||
| 22 | stats.update() |
||
| 23 | time.sleep(1) |
||
| 24 | |||
| 25 | disable(stats.get_plugin('sensors').args, 'sensors') |
||
| 26 | print("CPU consumption with sensors plugin disable") |
||
| 27 | process.cpu_percent() |
||
| 28 | stats.get_plugin('sensors').reset() |
||
| 29 | for i in range(0, iteration): |
||
| 30 | stats.update() |
||
| 31 | print(f'{i + 1}/{iteration}: {len(stats.get_plugin("sensors").get_raw())} sensor') |
||
| 32 | time.sleep(1) |
||
| 33 | print(f'CPU consumption with sensors plugin disable: {process.cpu_percent()}') |
||
| 34 | |||
| 35 | enable(stats.get_plugin('sensors').args, 'sensors') |
||
| 36 | print("CPU consumption with sensors plugin enable") |
||
| 37 | process.cpu_percent() |
||
| 38 | stats.get_plugin('sensors').reset() |
||
| 39 | for i in range(0, iteration): |
||
| 40 | stats.update() |
||
| 41 | print(f'{i + 1}/{iteration}: {len(stats.get_plugin("sensors").get_raw())} sensors') |
||
| 42 | time.sleep(1) |
||
| 43 | print(f'CPU consumption with sensors plugin enable: {process.cpu_percent()}') |
||
| 44 |