aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-12-29 15:27:51 -0500
committerKevin O'Connor <kevin@koconnor.net>2017-12-30 18:29:58 -0500
commitcf4c31cb88e233e6cf5f2691c22bcd721b34d64f (patch)
treed6771c5faa37ae580ceaae77e164d7bbb4d779a7 /scripts
parentf10bd5726d6a7d228f6cbbf211ffd243c54cff3a (diff)
downloadkutter-cf4c31cb88e233e6cf5f2691c22bcd721b34d64f.tar.gz
kutter-cf4c31cb88e233e6cf5f2691c22bcd721b34d64f.tar.xz
kutter-cf4c31cb88e233e6cf5f2691c22bcd721b34d64f.zip
graphstats: Add support for generating a graph of mcu frequency
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/graphstats.py57
1 files changed, 53 insertions, 4 deletions
diff --git a/scripts/graphstats.py b/scripts/graphstats.py
index dbc3438b..1dfd9865 100755
--- a/scripts/graphstats.py
+++ b/scripts/graphstats.py
@@ -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__':