graphstats: Normalize mcu frequency to microseconds when graphing multiple mcus
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
db6346e7e5
commit
48b60a8021
|
@ -181,14 +181,48 @@ def plot_system(data):
|
||||||
ax1.grid(True)
|
ax1.grid(True)
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
def plot_frequency(data, mcu):
|
def plot_mcu_frequencies(data):
|
||||||
all_keys = {}
|
all_keys = {}
|
||||||
for d in data:
|
for d in data:
|
||||||
all_keys.update(d)
|
all_keys.update(d)
|
||||||
one_mcu = mcu is not None
|
|
||||||
graph_keys = { key: ([], []) for key in all_keys
|
graph_keys = { key: ([], []) for key in all_keys
|
||||||
if (key in ("freq", "adj") or (not one_mcu and (
|
if (key in ("freq", "adj")
|
||||||
key.endswith(":freq") or key.endswith(":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():
|
||||||
|
val = d.get(key)
|
||||||
|
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()
|
||||||
|
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:
|
for d in data:
|
||||||
st = datetime.datetime.utcfromtimestamp(d['#sampletime'])
|
st = datetime.datetime.utcfromtimestamp(d['#sampletime'])
|
||||||
for key, (times, values) in graph_keys.items():
|
for key, (times, values) in graph_keys.items():
|
||||||
|
@ -199,10 +233,7 @@ def plot_frequency(data, mcu):
|
||||||
|
|
||||||
# Build plot
|
# Build plot
|
||||||
fig, ax1 = matplotlib.pyplot.subplots()
|
fig, ax1 = matplotlib.pyplot.subplots()
|
||||||
if one_mcu:
|
ax1.set_title("MCU '%s' frequency" % (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):
|
||||||
|
@ -286,7 +317,10 @@ def main():
|
||||||
if options.heater is not None:
|
if options.heater is not None:
|
||||||
fig = plot_temperature(data, options.heater)
|
fig = plot_temperature(data, options.heater)
|
||||||
elif options.frequency:
|
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:
|
elif options.system:
|
||||||
fig = plot_system(data)
|
fig = plot_system(data)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue