graphstats: Support graphing "mcu_awake" statistic

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-07-19 14:13:35 -04:00
parent 118fd21cb8
commit c4b8d3ea8b
1 changed files with 9 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import matplotlib.pyplot as plt, matplotlib.dates as mdates
MAXBANDWIDTH=25000. MAXBANDWIDTH=25000.
MAXBUFFER=2. MAXBUFFER=2.
STATS_INTERVAL=5.
def parse_log(logname): def parse_log(logname):
f = open(logname, 'rb') f = open(logname, 'rb')
@ -48,7 +49,7 @@ def find_print_restarts(data):
sample_resets[st] = 1 sample_resets[st] = 1
return sample_resets return sample_resets
def plot_mcu(data, maxbw, outname): def plot_mcu(data, maxbw, outname, graph_awake=False):
# Generate data for plot # Generate data for plot
basetime = lasttime = data[0]['#sampletime'] basetime = lasttime = data[0]['#sampletime']
lastbw = float(data[0]['bytes_write']) + float(data[0]['bytes_retransmit']) lastbw = float(data[0]['bytes_write']) + float(data[0]['bytes_retransmit'])
@ -56,6 +57,7 @@ def plot_mcu(data, maxbw, outname):
times = [] times = []
bwdeltas = [] bwdeltas = []
loads = [] loads = []
awake = []
hostbuffers = [] hostbuffers = []
for d in data: for d in data:
st = d['#sampletime'] st = d['#sampletime']
@ -79,6 +81,7 @@ def plot_mcu(data, maxbw, outname):
times.append(datetime.datetime.utcfromtimestamp(st)) times.append(datetime.datetime.utcfromtimestamp(st))
bwdeltas.append(100. * (bw - lastbw) / (maxbw * timedelta)) bwdeltas.append(100. * (bw - lastbw) / (maxbw * timedelta))
loads.append(100. * load / .001) loads.append(100. * load / .001)
awake.append(100. * float(d['mcu_awake']) / STATS_INTERVAL)
lasttime = st lasttime = st
lastbw = bw lastbw = bw
@ -87,6 +90,8 @@ def plot_mcu(data, maxbw, outname):
ax1.set_title("MCU bandwidth and load utilization") ax1.set_title("MCU bandwidth and load utilization")
ax1.set_xlabel('Time') ax1.set_xlabel('Time')
ax1.set_ylabel('Usage (%)') ax1.set_ylabel('Usage (%)')
if graph_awake:
ax1.plot_date(times, awake, 'b', label='Awake time')
ax1.plot_date(times, bwdeltas, 'g', label='Bandwidth') ax1.plot_date(times, bwdeltas, 'g', label='Bandwidth')
ax1.plot_date(times, loads, 'r', label='MCU load') ax1.plot_date(times, loads, 'r', label='MCU load')
ax1.plot_date(times, hostbuffers, 'c', label='Host buffer') ax1.plot_date(times, hostbuffers, 'c', label='Host buffer')
@ -99,6 +104,8 @@ def plot_mcu(data, maxbw, outname):
def main(): def main():
usage = "%prog [options] <logfile> <outname>" usage = "%prog [options] <logfile> <outname>"
opts = optparse.OptionParser(usage) opts = optparse.OptionParser(usage)
opts.add_option("-a", "--awake", action="store_true"
, help="graph mcu awake time")
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")
@ -106,7 +113,7 @@ def main():
data = parse_log(logname) data = parse_log(logname)
if not data: if not data:
return return
plot_mcu(data, MAXBANDWIDTH, outname) plot_mcu(data, MAXBANDWIDTH, outname, graph_awake=options.awake)
if __name__ == '__main__': if __name__ == '__main__':
main() main()