| 1 |
#!/usr/bin/env drgn |
| 2 |
# SPDX-License-Identifier: GPL-2.0 |
| 3 |
# Copyright (C) 2025 Juri Lelli <[email protected]> |
| 4 |
# Copyright (C) 2025 Red Hat, Inc. |
| 5 |
|
| 6 |
desc = """ |
| 7 |
This is a drgn script to show dl_rq bandwidth accounting information. For more |
| 8 |
info on drgn, visit https://github.com/osandov/drgn. |
| 9 |
|
| 10 |
Only online CPUs are reported. |
| 11 |
""" |
| 12 |
|
| 13 |
import os |
| 14 |
import argparse |
| 15 |
|
| 16 |
import drgn |
| 17 |
from drgn import FaultError |
| 18 |
from drgn.helpers.common import * |
| 19 |
from drgn.helpers.linux import * |
| 20 |
|
| 21 |
def print_dl_bws_info(): |
| 22 |
|
| 23 |
print("Retrieving dl_rq bandwidth accounting information:") |
| 24 |
|
| 25 |
runqueues = prog['runqueues'] |
| 26 |
|
| 27 |
for cpu_id in for_each_possible_cpu(prog): |
| 28 |
try: |
| 29 |
rq = per_cpu(runqueues, cpu_id) |
| 30 |
|
| 31 |
if rq.online == 0: |
| 32 |
continue |
| 33 |
|
| 34 |
dl_rq = rq.dl |
| 35 |
|
| 36 |
print(f" From CPU: {cpu_id}") |
| 37 |
|
| 38 |
# Access and print relevant fields from struct dl_rq |
| 39 |
print(f" running_bw : {dl_rq.running_bw}") |
| 40 |
print(f" this_bw : {dl_rq.this_bw}") |
| 41 |
print(f" extra_bw : {dl_rq.extra_bw}") |
| 42 |
print(f" max_bw : {dl_rq.max_bw}") |
| 43 |
print(f" bw_ratio : {dl_rq.bw_ratio}") |
| 44 |
|
| 45 |
except drgn.FaultError as fe: |
| 46 |
print(f" (CPU {cpu_id}: Fault accessing kernel memory: {fe})") |
| 47 |
except AttributeError as ae: |
| 48 |
print(f" (CPU {cpu_id}: Missing attribute for root_domain (kernel struct change?): {ae})") |
| 49 |
except Exception as e: |
| 50 |
print(f" (CPU {cpu_id}: An unexpected error occurred: {e})") |
| 51 |
|
| 52 |
if __name__ == "__main__": |
| 53 |
parser = argparse.ArgumentParser(description=desc, |
| 54 |
formatter_class=argparse.RawTextHelpFormatter) |
| 55 |
args = parser.parse_args() |
| 56 |
|
| 57 |
print_dl_bws_info() |