aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/graphstats.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-01-13 22:00:08 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-01-13 22:00:08 -0500
commitcb2ecc68d2b23e82b57f765cdb45286bbfcab16e (patch)
tree0e4bcdee1b3550864dcedcb6f086ad2a2547cfa2 /scripts/graphstats.py
parent078a03dc2107674832a720b2ddb9cb15b78e7b15 (diff)
downloadkutter-cb2ecc68d2b23e82b57f765cdb45286bbfcab16e.tar.gz
kutter-cb2ecc68d2b23e82b57f765cdb45286bbfcab16e.tar.xz
kutter-cb2ecc68d2b23e82b57f765cdb45286bbfcab16e.zip
graphstats: Add option to graph temperatures from log
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'scripts/graphstats.py')
-rwxr-xr-xscripts/graphstats.py47
1 files changed, 44 insertions, 3 deletions
diff --git a/scripts/graphstats.py b/scripts/graphstats.py
index b018bb12..49b7d7e5 100755
--- a/scripts/graphstats.py
+++ b/scripts/graphstats.py
@@ -15,8 +15,11 @@ MAXBUFFER=2.
STATS_INTERVAL=5.
TASK_MAX=0.0025
-APPLY_PREFIX = ['mcu_awake', 'mcu_task_avg', 'mcu_task_stddev', 'bytes_write',
- 'bytes_read', 'bytes_retransmit', 'freq', 'adj']
+APPLY_PREFIX = [
+ 'mcu_awake', 'mcu_task_avg', 'mcu_task_stddev', 'bytes_write',
+ 'bytes_read', 'bytes_retransmit', 'freq', 'adj',
+ 'target', 'temp', 'pwm'
+]
def parse_log(logname, mcu):
if mcu is None:
@@ -139,7 +142,6 @@ def plot_frequency(data, outname, mcu):
graph_keys = { key: ([], []) for key in all_keys
if (key in ("freq", "adj") or (not one_mcu and (
key.endswith(":freq") or key.endswith(":adj")))) }
- basetime = lasttime = data[0]['#sampletime']
for d in data:
st = datetime.datetime.utcfromtimestamp(d['#sampletime'])
for key, (times, values) in graph_keys.items():
@@ -168,11 +170,47 @@ def plot_frequency(data, outname, mcu):
fig.set_size_inches(8, 6)
fig.savefig(outname)
+def plot_temperature(data, outname, heater):
+ temp_key = heater + ':' + 'temp'
+ target_key = heater + ':' + 'target'
+ pwm_key = heater + ':' + 'pwm'
+ times = []
+ temps = []
+ targets = []
+ pwm = []
+ for d in data:
+ temp = d.get(temp_key)
+ if temp is None:
+ continue
+ times.append(datetime.datetime.utcfromtimestamp(d['#sampletime']))
+ temps.append(float(temp))
+ pwm.append(float(d[pwm_key]))
+ targets.append(float(d[target_key]))
+ # Build plot
+ fig, ax1 = matplotlib.pyplot.subplots()
+ ax1.set_title("Temperature of heater %s" % (heater,))
+ ax1.set_xlabel('Time')
+ ax1.set_ylabel('Temperature')
+ ax1.plot_date(times, temps, 'r', label='Measured temp', alpha=0.8)
+ ax1.plot_date(times, targets, 'g', label='Target', alpha=0.8)
+ ax2 = ax1.twinx()
+ ax2.set_ylabel('pwm')
+ ax2.plot_date(times, pwm, 'y', label='pwm', alpha=0.8)
+ fontP = matplotlib.font_manager.FontProperties()
+ fontP.set_size('x-small')
+ ax1.legend(loc='best', prop=fontP)
+ ax1.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%H:%M'))
+ ax1.grid(True)
+ fig.set_size_inches(8, 6)
+ fig.savefig(outname)
+
def main():
usage = "%prog [options] <logfile> <outname>"
opts = optparse.OptionParser(usage)
opts.add_option("-f", "--frequency", action="store_true",
help="graph mcu frequency")
+ opts.add_option("-t", "--temperature", type="string", dest="heater",
+ default=None, help="graph heater temperature")
opts.add_option("-m", "--mcu", type="string", dest="mcu", default=None,
help="limit stats to the given mcu")
options, args = opts.parse_args()
@@ -182,6 +220,9 @@ def main():
data = parse_log(logname, options.mcu)
if not data:
return
+ if options.heater is not None:
+ plot_temperature(data, outname, options.heater)
+ return
if options.frequency:
plot_frequency(data, outname, options.mcu)
return