mirror of https://github.com/Desuuuu/klipper.git
graphstats: Support selecting an mcu to graph from the command-line
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
02ae2ab984
commit
e99c0f53f8
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# Script to parse a logging file, extract the stats, and graph them
|
# Script to parse a logging file, extract the stats, and graph them
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import optparse, datetime
|
import optparse, datetime
|
||||||
|
@ -18,7 +18,10 @@ TASK_MAX=0.0025
|
||||||
APPLY_PREFIX = ['mcu_awake', 'mcu_task_avg', 'mcu_task_stddev', 'bytes_write',
|
APPLY_PREFIX = ['mcu_awake', 'mcu_task_avg', 'mcu_task_stddev', 'bytes_write',
|
||||||
'bytes_read', 'bytes_retransmit', 'freq', 'adj']
|
'bytes_read', 'bytes_retransmit', 'freq', 'adj']
|
||||||
|
|
||||||
def parse_log(logname):
|
def parse_log(logname, mcu):
|
||||||
|
if mcu is None:
|
||||||
|
mcu = "mcu"
|
||||||
|
mcu_prefix = mcu + ":"
|
||||||
apply_prefix = { p: 1 for p in APPLY_PREFIX }
|
apply_prefix = { p: 1 for p in APPLY_PREFIX }
|
||||||
f = open(logname, 'rb')
|
f = open(logname, 'rb')
|
||||||
out = []
|
out = []
|
||||||
|
@ -33,7 +36,7 @@ def parse_log(logname):
|
||||||
for p in parts[2:]:
|
for p in parts[2:]:
|
||||||
if p.endswith(':'):
|
if p.endswith(':'):
|
||||||
prefix = p
|
prefix = p
|
||||||
if prefix == 'mcu:':
|
if prefix == mcu_prefix:
|
||||||
prefix = ''
|
prefix = ''
|
||||||
continue
|
continue
|
||||||
name, val = p.split('=', 1)
|
name, val = p.split('=', 1)
|
||||||
|
@ -128,16 +131,14 @@ def plot_mcu(data, maxbw, outname):
|
||||||
fig.set_size_inches(8, 6)
|
fig.set_size_inches(8, 6)
|
||||||
fig.savefig(outname)
|
fig.savefig(outname)
|
||||||
|
|
||||||
def plot_frequency(data, outname):
|
def plot_frequency(data, outname, mcu):
|
||||||
all_keys = {}
|
all_keys = {}
|
||||||
for d in data:
|
for d in data:
|
||||||
all_keys.update(d)
|
all_keys.update(d)
|
||||||
graph_keys = {}
|
one_mcu = mcu is not None
|
||||||
for key in all_keys:
|
graph_keys = { key: ([], []) for key in all_keys
|
||||||
if ((key in ("freq", "adj")
|
if (key in ("freq", "adj") or (not one_mcu and (
|
||||||
or key.endswith(":freq") or key.endswith(":adj"))
|
key.endswith(":freq") or key.endswith(":adj")))) }
|
||||||
and key not in graph_keys):
|
|
||||||
graph_keys[key] = ([], [])
|
|
||||||
basetime = lasttime = data[0]['#sampletime']
|
basetime = lasttime = data[0]['#sampletime']
|
||||||
for d in data:
|
for d in data:
|
||||||
st = datetime.datetime.utcfromtimestamp(d['#sampletime'])
|
st = datetime.datetime.utcfromtimestamp(d['#sampletime'])
|
||||||
|
@ -149,7 +150,10 @@ def plot_frequency(data, outname):
|
||||||
|
|
||||||
# Build plot
|
# Build plot
|
||||||
fig, ax1 = matplotlib.pyplot.subplots()
|
fig, ax1 = matplotlib.pyplot.subplots()
|
||||||
ax1.set_title("MCU frequency")
|
if one_mcu:
|
||||||
|
ax1.set_title("MCU '%s' frequency" % (mcu,))
|
||||||
|
else:
|
||||||
|
ax1.set_title("MCU frequency")
|
||||||
ax1.set_xlabel('Time')
|
ax1.set_xlabel('Time')
|
||||||
ax1.set_ylabel('Frequency')
|
ax1.set_ylabel('Frequency')
|
||||||
for key in sorted(graph_keys):
|
for key in sorted(graph_keys):
|
||||||
|
@ -169,15 +173,17 @@ def main():
|
||||||
opts = optparse.OptionParser(usage)
|
opts = optparse.OptionParser(usage)
|
||||||
opts.add_option("-f", "--frequency", action="store_true",
|
opts.add_option("-f", "--frequency", action="store_true",
|
||||||
help="graph mcu frequency")
|
help="graph mcu frequency")
|
||||||
|
opts.add_option("-m", "--mcu", type="string", dest="mcu", default=None,
|
||||||
|
help="limit stats to the given mcu")
|
||||||
options, args = opts.parse_args()
|
options, args = opts.parse_args()
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
opts.error("Incorrect number of arguments")
|
opts.error("Incorrect number of arguments")
|
||||||
logname, outname = args
|
logname, outname = args
|
||||||
data = parse_log(logname)
|
data = parse_log(logname, options.mcu)
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
if options.frequency:
|
if options.frequency:
|
||||||
plot_frequency(data, outname)
|
plot_frequency(data, outname, options.mcu)
|
||||||
return
|
return
|
||||||
plot_mcu(data, MAXBANDWIDTH, outname)
|
plot_mcu(data, MAXBANDWIDTH, outname)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue