File: test_perf.py

package info (click to toggle)
glances 4.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 13,384 kB
  • sloc: python: 23,159; makefile: 470; sh: 430; javascript: 374
file content (40 lines) | stat: -rwxr-xr-x 1,237 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
#
# Glances - An eye on your system
#
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <nicolas@nicolargo.com>
#
# SPDX-License-Identifier: LGPL-3.0-only
#

"""Glances unitary tests suite for Glances perf."""

from glances.timer import Timer


def test_perf_update(glances_stats):
    """
    Test Glances perf.
    """
    test_duration = 12  # seconds
    perf_timer = Timer(test_duration)
    counter = 0
    from_cache = 0
    from_update = 0
    previous_interrupts_gauge = None
    while not perf_timer.finished():
        glances_stats.update()
        # interrupts_gauge should always increase
        interrupts_gauge = glances_stats.get_plugin('cpu').get_raw().get('interrupts_gauge')
        if interrupts_gauge is not None:
            if interrupts_gauge == previous_interrupts_gauge:
                from_cache += 1
            else:
                from_update += 1
                previous_interrupts_gauge = interrupts_gauge
        counter += 1
    print(f"{counter} iterations. From cache: {from_cache} | From update: {from_update}")
    assert counter > test_duration
    assert from_update < from_cache
    assert from_cache >= test_duration * 2
    assert from_update >= (test_duration / 2) - 1