File: cpu.py

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (29 lines) | stat: -rw-r--r-- 903 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
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Robin Jarry

CPU_TOTAL = "total_cycles"
CPU_BUSY = "busy_cycles"


def info() -> "dict[Name, tuple[Description, Type]]":
    return {
        CPU_TOTAL: ("Total number of CPU cycles.", "counter"),
        CPU_BUSY: ("Number of busy CPU cycles.", "counter"),
    }


def metrics(sock: "TelemetrySocket") -> "list[tuple[Name, Value, Labels]]":
    out = []
    for lcore_id in sock.cmd("/eal/lcore/list"):
        lcore = sock.cmd("/eal/lcore/info", lcore_id)
        cpu = ",".join(str(c) for c in lcore.get("cpuset", []))
        total = lcore.get("total_cycles")
        busy = lcore.get("busy_cycles", 0)
        if not (cpu and total):
            continue
        labels = {"cpu": cpu, "numa": lcore.get("socket", 0)}
        out += [
            (CPU_TOTAL, total, labels),
            (CPU_BUSY, busy, labels),
        ]
    return out