commit a8cf4a457628b78bca6e4f842d7919742988dc50 Author: Richard Date: Sun Mar 29 08:49:58 2026 +0000 interrupt count stcript diff --git a/monitor-interrupt-counts.py b/monitor-interrupt-counts.py new file mode 100755 index 0000000..7eba9d5 --- /dev/null +++ b/monitor-interrupt-counts.py @@ -0,0 +1,61 @@ +#!/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]} ", 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()