diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-06-18 12:31:01 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-06-18 12:31:01 +0200 |
commit | 3fc0dde9a90699c6137ecfb9175c36367fcd8f91 (patch) | |
tree | 6197830d7f3548814964b3d4272a2fc3e52ded07 | |
parent | 120f967196c4ce76fb9836162ac6e237a4327166 (diff) | |
download | scripts-3fc0dde9a90699c6137ecfb9175c36367fcd8f91.tar.gz |
interrupts-graph.py: implement read/write to file
-rwxr-xr-x | rare/interrupts-graph.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/rare/interrupts-graph.py b/rare/interrupts-graph.py index eb4c5c4..c7b824f 100755 --- a/rare/interrupts-graph.py +++ b/rare/interrupts-graph.py @@ -13,6 +13,7 @@ from collections import deque, OrderedDict import numpy as np from scipy.interpolate import spline, interp1d import threading +from argparse import ArgumentParser # Number of seconds to show in the graph XRANGE = 60 @@ -40,6 +41,17 @@ ALT_COLORS = ['#023FA5', '#7D87B9', '#BEC1D4', '#D6BCC0', '#BB7784', '#FFFFFF', input_filename, output_filename = '', '' +parser = ArgumentParser(description='Monitor /proc/interrupts changes') +parser.add_argument('-i', dest='input_filename', + help='Source to read interrupts entries from') +parser.add_argument('-o', dest='output_filename', + help='Target file to write interrupt entries to') +args = parser.parse_args() +if args.input_filename: + input_filename = args.input_filename +if args.output_filename: + output_filename = args.output_filename + def is_line_ok(name, yvalues): """Returns True if a line should be displayed for this name.""" if max(yvalues) < 5: @@ -189,9 +201,13 @@ start_time = -XRANGE def refresh_data(): global start_time # Update data + updated = False for name, n in get_diffs(): yvalues[name].append(n) - start_time += INTERVAL + updated = True + if updated: + start_time += INTERVAL + return updated smooth = {} @synchronized(data_lock) @@ -285,11 +301,18 @@ def do_draw(): update_title() # Separate worker for fetching data +t = None def refresh_data_timer(): global t t = threading.Timer(INTERVAL, refresh_data_timer) t.start() refresh_data() + +# Fill xrange of entries +if not input_is_proc: + for i in range(0, int(XRANGE / INTERVAL)): + if not refresh_data(): + break refresh_data_timer() while running: @@ -299,4 +322,5 @@ while running: plt.pause(INTERVAL) # Cancel any scheduled timer -t.cancel() +if t: + t.cancel() |