diff options
author | Peter Wu <peter@lekensteyn.nl> | 2016-07-29 23:55:32 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2016-07-29 23:55:32 +0200 |
commit | 15b4bbfc33689b3780b1767301c8e8d6a2084875 (patch) | |
tree | c608dc769614460945e23f102a113ba55cd4d6f0 /rare/watch-intr.py | |
parent | 5a90a7d7b3a7d416f1a7ce735456f6796a871e59 (diff) | |
download | scripts-15b4bbfc33689b3780b1767301c8e8d6a2084875.tar.gz |
rare/watch-intr.py: utility for watching /proc/interrupts
Useful for using over SSH.
Diffstat (limited to 'rare/watch-intr.py')
-rwxr-xr-x | rare/watch-intr.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/rare/watch-intr.py b/rare/watch-intr.py new file mode 100755 index 0000000..52031eb --- /dev/null +++ b/rare/watch-intr.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# Light-weight tool to watch the /proc/interrupts file, to be combined like: +# +# ./watch-intr.py > intr.txt +# ./interrupts-graph.py -i intr.txt + +import argparse, sys, time + +parser = argparse.ArgumentParser() +parser.add_argument("limit", type=int, default=0, nargs="?", + help="Number of repetitions (or 0 for infinity), default %(default)d") +parser.add_argument("delay", type=int, default=1, nargs="?", + help="Interval between printing, default %(default)d second") + +args = parser.parse_args() +limit, delay = args.limit, args.delay + +def print_and_flush(data): + sys.stdout.write(data) + sys.stdout.write("\n") + sys.stdout.flush() + +try: + with open("/proc/interrupts") as f: + print_and_flush(f.read()) + while limit != 1: + if limit > 0: + limit -= 1 + time.sleep(delay) + f.seek(0) + print_and_flush(f.read()) +except KeyboardInterrupt: + pass |