1import matplotlib.pyplot as plt
2import matplotlib.gridspec as gridspec
3import pandas as pd
4
5from .legend_picker import *
6from .helpers import *
7
8
9def show_executed_instructions(metricsParser, options, onePlotFigureSize, fontSize):
10    cpus, instructionEntries = metricsParser.get_instructions_entries()
11    fig, ax = plt.subplots(figsize=onePlotFigureSize, constrained_layout=True)
12
13    instructionLines = _prepare_data(fig, ax, cpus, instructionEntries, 'realTime' if options.real_time else 'virtualTime')
14
15    handles, labels = ax.get_legend_handles_labels()
16    legend = fig.legend(handles, labels, loc='upper left')
17
18    fig.suptitle('Executed instructions', fontsize=fontSize)
19    ax.set_xlabel('{} time [ms]'.format('Real' if options.real_time else 'Virtual'))
20    ax.set_ylabel('Number of instructions')
21
22    set_legend_picker(fig, instructionLines, legend)
23
24    save_fig(fig, 'instructions.png', options)
25
26
27def _prepare_data(fig, ax, cpus, instructionEntries, columnName):
28    data = pd.DataFrame(instructionEntries, columns=['realTime', 'virtualTime', 'cpuId', 'executedInstruction'])
29    instructionLines = []
30
31    for cpuId, cpuName in cpus.items():
32        entries = data[data['cpuId'] == cpuId]
33        if entries.empty:
34            continue
35        line, = ax.plot(entries[columnName], entries['executedInstruction'], label=cpuName)
36        instructionLines.append(line)
37
38    return instructionLines
39