diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2022-07-26 21:15:06 +0300 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2022-07-29 18:40:54 +0300 |
commit | 48b60a8021bd02d998fd3d6ea9e55645e3dc75e4 (patch) | |
tree | 77b46bb4cd36238cbd592ecf9a1b8d07f2f8336d | |
parent | db6346e7e55d34763904488deff4a67338b1acbd (diff) |
graphstats: Normalize mcu frequency to microseconds when graphing multiple mcus
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rwxr-xr-x | scripts/graphstats.py | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/scripts/graphstats.py b/scripts/graphstats.py index 7cd52964b..5cd2ad34f 100755 --- a/scripts/graphstats.py +++ b/scripts/graphstats.py @@ -181,14 +181,13 @@ def plot_system(data): ax1.grid(True) return fig -def plot_frequency(data, mcu): +def plot_mcu_frequencies(data): all_keys = {} for d in data: all_keys.update(d) - one_mcu = mcu is not None 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")))) } + if (key in ("freq", "adj") + or (key.endswith(":freq") or key.endswith(":adj"))) } for d in data: st = datetime.datetime.utcfromtimestamp(d['#sampletime']) for key, (times, values) in graph_keys.items(): @@ -196,13 +195,45 @@ def plot_frequency(data, mcu): if val not in (None, '0', '1'): times.append(st) values.append(float(val)) + est_mhz = { key: round((sum(values)/len(values)) / 1000000.) + for key, (times, values) in graph_keys.items() } # Build plot fig, ax1 = matplotlib.pyplot.subplots() - if one_mcu: - ax1.set_title("MCU '%s' frequency" % (mcu,)) - else: - ax1.set_title("MCU frequency") + ax1.set_title("MCU frequencies") + ax1.set_xlabel('Time') + ax1.set_ylabel('Microsecond deviation') + for key in sorted(graph_keys): + times, values = graph_keys[key] + mhz = est_mhz[key] + label = "%s(%dMhz)" % (key, mhz) + hz = mhz * 1000000. + ax1.plot_date(times, [(v - hz)/mhz for v in values], '.', label=label) + 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) + return fig + +def plot_mcu_frequency(data, mcu): + all_keys = {} + for d in data: + all_keys.update(d) + graph_keys = { key: ([], []) for key in all_keys + if key in ("freq", "adj") } + 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 '%s' frequency" % (mcu,)) ax1.set_xlabel('Time') ax1.set_ylabel('Frequency') for key in sorted(graph_keys): @@ -286,7 +317,10 @@ def main(): if options.heater is not None: fig = plot_temperature(data, options.heater) elif options.frequency: - fig = plot_frequency(data, options.mcu) + if options.mcu is not None: + fig = plot_mcu_frequency(data, options.mcu) + else: + fig = plot_mcu_frequencies(data) elif options.system: fig = plot_system(data) else: |