Skip to content

Commit

Permalink
contrib/cgroup: Print counts of subsys state structs
Browse files Browse the repository at this point in the history
Print information about cgroup_subsys_state counts associated with given
cgroup. The main purpose is to show subsys structs in offline state on
cgroup v2.

Signed-off-by: Michal Koutný <[email protected]>
  • Loading branch information
Werkov committed Nov 8, 2024
1 parent 3ef1afe commit c1a117a
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion contrib/cgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from contextlib import contextmanager
import os
import sys
from collections import Counter

from drgn import cast
from drgn.helpers.common.type import enum_type_to_class
Expand All @@ -25,6 +26,11 @@
exclude=("__MAX_BPF_ATTACH_TYPE",),
)

CgroupSubsysId = enum_type_to_class(
prog.type("enum cgroup_subsys_id"),
"CgroupSubsysId",
exclude=("CGROUP_SUBSYS_COUNT",),
)

@contextmanager
def open_dir(*args, **kwds):
Expand Down Expand Up @@ -82,9 +88,41 @@ def cmd_bpf(cgroup):
print_cgroup_bpf_progs(pos.cgroup)


def cmd_stat(cgroup):
stat = Counter()
stat_dying = Counter()

for ssid in CgroupSubsysId:
css = cgroup.subsys[ssid.value]
# XXX if subsys of offlined or cgroup rmdir'd under our hands we won't see its subtree
if not css:
continue
for pos in css_for_each_descendant_pre(css):
stat[ssid] +=1
if not pos.flags & prog["CSS_ONLINE"]:
stat_dying[ssid] += 1

for ssid in CgroupSubsysId:
if stat[ssid.value] == 0:
continue
print("nr_{:<30} {:>4}".format(
ssid.name,
stat[ssid.value]
)
)
for ssid in CgroupSubsysId:
if stat_dying[ssid.value] == 0:
continue
print("nr_dying_{:<24} {:>4}".format(
ssid.name,
stat_dying[ssid.value]
)
)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("command", choices=["tree", "bpf"])
parser.add_argument("command", choices=["tree", "bpf", "stat"])
parser.add_argument("cgroups", help="Cgroups", nargs="*", type=get_cgroup)
args = parser.parse_args()

Expand Down

0 comments on commit c1a117a

Please sign in to comment.