plot_relay_throughput.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import matplotlib.pylab as plt
  2. import numpy as np
  3. import math
  4. import sys
  5. #
  6. import data_helpers
  7. #
  8. #filenames = ['relay_throughput.log', 'multithreaded-throughput-rpi.log']
  9. #filenames = ['cluck2_working_0_0.log', 'original-throughput.log']
  10. filenames = sys.argv[1:]
  11. #
  12. selected_data = {}
  13. for name in filenames:
  14. (_, data) = data_helpers.read_relay_throughput(name)
  15. #
  16. totals = np.sum(data['threads'], axis=1)
  17. start_time = np.where(totals/2**20 > 5)[0][0]-10
  18. end_time = np.where(totals/2**20 > 5)[0][-1]+10
  19. #
  20. selected_data[name] = {}
  21. selected_data[name]['timestamps'] = data['timestamps'][start_time:end_time]
  22. selected_data[name]['timestamps'] -= selected_data[name]['timestamps'][0]
  23. selected_data[name]['threads'] = data['threads'][start_time:end_time,:]
  24. #
  25. normalized_data = data_helpers.normalize_relay_throughput(data)
  26. selected_data[name]['timestamps_normalized'] = normalized_data['timestamps'][start_time:end_time]
  27. selected_data[name]['threads_normalized'] = normalized_data['threads'][start_time:end_time,:]
  28. #
  29. time_deltas = selected_data[name]['timestamps'][1:]-selected_data[name]['timestamps'][:-1]
  30. num_timesteps = int(round(30/np.mean(time_deltas)))
  31. max_throughput = np.max(np.convolve(0.5*np.sum(selected_data[name]['threads_normalized'], axis=1)/2**20, np.ones(num_timesteps)/num_timesteps, 'valid'))
  32. # we divide by 2 since we the throughput is the average of the sent and received bytes
  33. print('{}: {:.2f} MiB/s'.format(name, max_throughput))
  34. #
  35. for name in selected_data:
  36. plt.step(selected_data[name]['timestamps_normalized'], 0.5*np.sum(selected_data[name]['threads_normalized'], axis=1)/2**20, label=name, where='post')
  37. for thread in range(int(selected_data[name]['threads'].shape[1]/2)):
  38. for (ind, direction) in zip(range(2), ['sent', 'recv']):
  39. label = '{} - {} - {}'.format(name, thread, direction)
  40. #plt.plot(selected_data[name]['timestamps_normalized'], selected_data[name]['threads_normalized'][:,2*thread+ind]/2**20, label=label)
  41. #plt.plot(selected_data[name]['timestamps_normalized'], np.cumsum(selected_data[name]['threads_normalized'][:,2*thread+ind])/2**20, label=label)
  42. #
  43. #
  44. for (ind, direction) in zip(range(2), ['sent', 'recv']):
  45. label = '{} - {}'.format(name, direction)
  46. #plt.plot(selected_data[name]['timestamps_normalized'], np.sum(selected_data[name]['threads_normalized'][:,ind::2], axis=1)/2**20, label=label)
  47. #plt.plot(selected_data[name]['timestamps_normalized'], np.cumsum(np.sum(selected_data[name]['threads_normalized'][:,ind::2], axis=1))/2**20, label=label)
  48. #
  49. #
  50. plt.xlabel('Time (s)')
  51. plt.ylabel('Throughput (MiB/s)')
  52. plt.legend()
  53. plt.show()