1import matplotlib.pyplot as plt 2import pandas as pd 3 4from .legend_picker import * 5from .helpers import * 6 7 8def show_peripheral_access(metricsParser, options, twoPlotFigureSize, fontSize): 9 peripherals, peripheralEntries = metricsParser.get_peripheral_entries() 10 data = pd.DataFrame(peripheralEntries, columns=['realTime', 'virtualTime', 'operation', 'address']) 11 fig, (writesAx, readsAx) = plt.subplots(2, 1, figsize=twoPlotFigureSize, constrained_layout=True) 12 13 writeLines = [] 14 readLines = [] 15 time_column = 'realTime' if options.real_time else 'virtualTime' 16 17 for key, value in peripherals.items(): 18 tempData = data[data.address >= value[0]] 19 peripheralEntries = tempData[tempData.address <= value[1]] 20 readOperationFilter = peripheralEntries['operation'] == bytes([0]) 21 writeOperationFilter = peripheralEntries['operation'] == bytes([1]) 22 readEntries = peripheralEntries[readOperationFilter] 23 writeEntries = peripheralEntries[writeOperationFilter] 24 if not writeEntries.empty: 25 writeLine, = writesAx.plot(writeEntries[time_column], range(0, len(writeEntries)), label=key) 26 writeLines.append(writeLine) 27 if not readEntries.empty: 28 readLine, = readsAx.plot(readEntries[time_column], range(0, len(readEntries)), label=key) 29 readLines.append(readLine) 30 31 fig.suptitle('Peripheral access', fontsize=fontSize) 32 writeHandles, writeLabels = writesAx.get_legend_handles_labels() 33 readHandles, readLabels = readsAx.get_legend_handles_labels() 34 writeLegend = fig.legend(writeHandles, writeLabels, loc='upper left') 35 readLegend = fig.legend(readHandles, readLabels, loc='center left') 36 set_legend_picker(fig, writeLines, writeLegend) 37 set_legend_picker(fig, readLines, readLegend) 38 39 x_label = '{} time [ms]'.format('Real' if options.real_time else 'Virtual') 40 writesAx.set_xlabel(x_label) 41 readsAx.set_xlabel(x_label) 42 writesAx.set_ylabel('Write operations') 43 readsAx.set_ylabel('Read operations') 44 45 save_fig(fig, 'peripherals.png', options) 46