mirror of https://github.com/Desuuuu/klipper.git
graphstats: Add support for generating a graph of mcu frequency
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
f10bd5726d
commit
cf4c31cb88
|
@ -8,6 +8,7 @@ import optparse, datetime
|
|||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot, matplotlib.dates, matplotlib.font_manager
|
||||
import matplotlib.ticker
|
||||
|
||||
MAXBANDWIDTH=25000.
|
||||
MAXBUFFER=2.
|
||||
|
@ -23,8 +24,16 @@ def parse_log(logname):
|
|||
#if parts and parts[0] == 'INFO:root:shutdown:':
|
||||
# break
|
||||
continue
|
||||
keyparts = dict(p.split('=', 1)
|
||||
for p in parts[2:] if not p.endswith(':'))
|
||||
prefix = ""
|
||||
keyparts = {}
|
||||
for p in parts[2:]:
|
||||
if p.endswith(':'):
|
||||
prefix = p
|
||||
if prefix == 'mcu:':
|
||||
prefix = ''
|
||||
continue
|
||||
name, val = p.split('=', 1)
|
||||
keyparts[prefix + name] = val
|
||||
if keyparts.get('bytes_write', '0') == '0':
|
||||
continue
|
||||
keyparts['#sampletime'] = float(parts[1][:-1])
|
||||
|
@ -107,11 +116,48 @@ def plot_mcu(data, maxbw, outname, graph_awake=False):
|
|||
ax1.grid(True)
|
||||
fig.savefig(outname)
|
||||
|
||||
def plot_frequency(data, outname):
|
||||
all_keys = {}
|
||||
for d in data:
|
||||
all_keys.update(d)
|
||||
graph_keys = {}
|
||||
for key in all_keys:
|
||||
if ((key in ("freq", "adj")
|
||||
or key.endswith(":freq") or key.endswith(":adj"))
|
||||
and key not in graph_keys):
|
||||
graph_keys[key] = ([], [])
|
||||
basetime = lasttime = data[0]['#sampletime']
|
||||
for d in data:
|
||||
st = datetime.datetime.utcfromtimestamp(d['#sampletime'])
|
||||
for key, (times, values) in graph_keys.items():
|
||||
val = d.get(key)
|
||||
if val not in (None, '0', '1'):
|
||||
times.append(st)
|
||||
values.append(float(val))
|
||||
|
||||
# Build plot
|
||||
fig, ax1 = matplotlib.pyplot.subplots()
|
||||
ax1.set_title("MCU frequency")
|
||||
ax1.set_xlabel('Time')
|
||||
ax1.set_ylabel('Frequency')
|
||||
for key in sorted(graph_keys):
|
||||
times, values = graph_keys[key]
|
||||
ax1.plot_date(times, values, '.', label=key)
|
||||
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.yaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter('%d'))
|
||||
ax1.grid(True)
|
||||
fig.savefig(outname)
|
||||
|
||||
def main():
|
||||
usage = "%prog [options] <logfile> <outname>"
|
||||
opts = optparse.OptionParser(usage)
|
||||
opts.add_option("-a", "--awake", action="store_true"
|
||||
, help="graph mcu awake time")
|
||||
opts.add_option("-a", "--awake", action="store_true",
|
||||
help="graph mcu awake time")
|
||||
opts.add_option("-f", "--frequency", action="store_true",
|
||||
help="graph mcu frequency")
|
||||
options, args = opts.parse_args()
|
||||
if len(args) != 2:
|
||||
opts.error("Incorrect number of arguments")
|
||||
|
@ -119,6 +165,9 @@ def main():
|
|||
data = parse_log(logname)
|
||||
if not data:
|
||||
return
|
||||
if options.frequency:
|
||||
plot_frequency(data, outname)
|
||||
return
|
||||
plot_mcu(data, MAXBANDWIDTH, outname, graph_awake=options.awake)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue