File: test_vmstat.py

package info (click to toggle)
drgn 0.0.33-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,892 kB
  • sloc: python: 59,081; ansic: 51,400; awk: 423; makefile: 339; sh: 113
file content (46 lines) | stat: -rw-r--r-- 1,554 bytes parent folder | download
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
41
42
43
44
45
46
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later

import re

from drgn.helpers.linux.vmstat import (
    global_numa_event_state,
    global_vm_event_state,
    nr_free_pages,
)
from tests.linux_kernel import LinuxKernelTestCase, meminfo_field_in_pages


class TestVmstat(LinuxKernelTestCase):
    def test_nr_free_pages(self):
        self.assertAlmostEqual(
            nr_free_pages(self.prog),
            meminfo_field_in_pages("MemFree"),
            delta=1024 * 1024 * 1024,
        )

    def test_global_numa_event_state(self):
        with open("/proc/vmstat", "r") as f:
            for line in f:
                match = re.match(r"numa_hit\s+([0-9]+)", line)
                if match:
                    expected = int(match.group(1))
                    break
            else:
                self.skipTest("kernel does not support NUMA statistics")
        self.assertAlmostEqual(
            global_numa_event_state(self.prog["NUMA_HIT"]), expected, delta=1024 * 1024
        )

    def test_global_vm_event_state(self):
        with open("/proc/vmstat", "r") as f:
            for line in f:
                match = re.match(r"pgmajfault\s+([0-9]+)", line)
                if match:
                    expected = int(match.group(1))
                    break
            else:
                self.skipTest("kernel does not support VM event statistics")
        self.assertAlmostEqual(
            global_vm_event_state(self.prog["PGMAJFAULT"]), expected, delta=1024 * 1024
        )