62 lines
1.8 KiB
Python
Executable File
62 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Monitor per-second interrupt counts for a specific interrupt type."""
|
|
|
|
import sys
|
|
import time
|
|
|
|
|
|
def parse_interrupts(filter_str):
|
|
"""Parse /proc/interrupts and return counts for lines matching filter_str."""
|
|
results = {}
|
|
with open("/proc/interrupts") as f:
|
|
header = f.readline().split()
|
|
num_cpus = len(header)
|
|
for line in f:
|
|
if filter_str not in line:
|
|
continue
|
|
parts = line.split()
|
|
label = parts[0].rstrip(":")
|
|
counts = [int(parts[i + 1]) for i in range(num_cpus)]
|
|
results[label] = counts
|
|
return header, results
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print(f"Usage: {sys.argv[0]} <interrupt-type>", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
filter_str = sys.argv[1]
|
|
cpu_names, prev = parse_interrupts(filter_str)
|
|
|
|
if not prev:
|
|
print(f"No interrupts matching '{filter_str}' found in /proc/interrupts", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
num_cpus = len(cpu_names)
|
|
print(f"Monitoring interrupts matching '{filter_str}' every 1s (Ctrl-C to stop)\n")
|
|
|
|
# Print header
|
|
cpu_hdr = " ".join(f"{c:>8}" for c in cpu_names)
|
|
print(f"{'IRQ':<20} {cpu_hdr} {'TOTAL':>10}")
|
|
print("-" * (22 + num_cpus * 10 + 12))
|
|
|
|
try:
|
|
while True:
|
|
time.sleep(1)
|
|
_, curr = parse_interrupts(filter_str)
|
|
for label in sorted(curr):
|
|
if label not in prev:
|
|
prev[label] = [0] * num_cpus
|
|
deltas = [c - p for c, p in zip(curr[label], prev[label])]
|
|
total = sum(deltas)
|
|
cols = " ".join(f"{d:>8}" for d in deltas)
|
|
print(f"{label:<20} {cols} {total:>10}")
|
|
prev = curr
|
|
except KeyboardInterrupt:
|
|
print()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|