summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-06-18 11:15:36 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-06-18 11:15:36 +0200
commit193742c324fab947d166c0b7df3d20d5e8b8da47 (patch)
tree744417ede6f97fe3a52b422892c7de9e093a3cc2
parent2900c27aef9fb1ae49070f77934ae1887819e753 (diff)
downloadscripts-193742c324fab947d166c0b7df3d20d5e8b8da47.tar.gz
rare/interrupts-graph.py: fix X axis numbers
Shift X axis as time progresses.
-rwxr-xr-xrare/interrupts-graph.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/rare/interrupts-graph.py b/rare/interrupts-graph.py
index 6e4ee23..34d28ee 100755
--- a/rare/interrupts-graph.py
+++ b/rare/interrupts-graph.py
@@ -14,8 +14,8 @@ import numpy as np
from scipy.interpolate import spline, interp1d
import threading
-# Maximimum number of time units to keep
-XSCALE = 60
+# Number of seconds to show in the graph
+XRANGE = 60
# Delay between updating the graph
INTERVAL = .5
# Log scale base or 0 to disable logarithmic y scaling
@@ -88,11 +88,10 @@ def get_diffs():
prev[name] = n
plt.ylabel(u'\u0394interrupts')
-plt.xlabel(u'\u0394time (sec)')
+plt.xlabel(u'time (sec)')
plt.grid('on')
#plt.ion() # Not necessary if show() does not block.
plt.show(block=False)
-plt.xlim(0, XSCALE)
if LOG_SCALE_BASE > 0:
plt.yscale('log', nonposy='clip', basey=LOG_SCALE_BASE)
@@ -141,9 +140,10 @@ plt.connect('pick_event', on_pick)
names = [name for name, _ in get_diffs()]
yvalues = {}
-# Create yvalues, save them and generate plot args
+x_count = int(XRANGE / INTERVAL)
+# Initialize y values for each name
for name in names:
- ydata = deque([0] * XSCALE, XSCALE)
+ ydata = deque([0] * x_count, x_count)
yvalues[name] = ydata
lines = {}
@@ -155,11 +155,15 @@ def update_title():
# Lock to avoid updating the UI while the data is being refreshed
data_lock = threading.Lock()
+# Since yvalues gets filled on the tail, substract from start time
+start_time = -XRANGE
@synchronized(data_lock)
def refresh_data():
+ global start_time
# Update data
for name, n in get_diffs():
yvalues[name].append(n)
+ start_time += INTERVAL
smooth = {}
@synchronized(data_lock)
@@ -171,7 +175,7 @@ def update():
ys = yvalues[name]
# Consider only strictly positive values
ydata = [y for y in ys if y > 0]
- xdata = [i for i, y in enumerate(ys) if y > 0]
+ xdata = [start_time + i * INTERVAL for i, y in enumerate(ys) if y > 0]
if ydata and is_line_ok(name, ys):
# Data is significant, show it
@@ -222,6 +226,9 @@ def update():
# plt.ylim(ymin, ymin + largest)
plt.ylim(0, largest)
+ min_x = max(start_time, 0)
+ plt.xlim(min_x, min_x + XRANGE)
+
def do_draw():
"""Actually draw the graph, updating the legend if necessary."""
global update_legend