stacked-histogram.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python3
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4. plt.rcParams.update({
  5. "text.usetex": True,
  6. "font.family": "sans-serif",
  7. })
  8. files = [
  9. ['rv32-freertos/dump/main.csr'],
  10. ['rv32-zephyr/dump/zephyr.csr'],
  11. ['rv32-glibc-busybox-linux/dump/vmlinux.csr', 'rv32-glibc-busybox-linux/dump/busybox.csr'],
  12. ['rv32-uclibc-busybox-nommu-linux/dump/vmlinux.csr', 'rv32-uclibc-busybox-nommu-linux/dump/busybox.csr'],
  13. ]
  14. names = [
  15. 'FreeRTOS',
  16. 'Zephyr RTOS',
  17. 'Linux (glibc + busybox)',
  18. 'Linux (uClibc + busybox) nommu',
  19. ]
  20. short_names = [
  21. 'FreeRTOS',
  22. 'Zephyr RTOS',
  23. 'Linux (glibc)',
  24. 'Linux (uClibc)',
  25. ]
  26. data = { 'System': [], 'CSR': [], 'Count': [] }
  27. for name, filelist in zip(names, files):
  28. for fp in filelist:
  29. with open(fp) as lines:
  30. for line in lines:
  31. count, csr = line.strip().split(' ')
  32. data['System'].append(name)
  33. data['CSR'].append(csr)
  34. data['Count'].append(int(count))
  35. df = pd.DataFrame(data)
  36. #print(df)
  37. # latex table output
  38. print(df.pivot_table(index='CSR', columns='System', values='Count', fill_value='').to_latex(index_names=True, label='table:os-csr-counts', caption='\# CSR occurences compared across systems', header=short_names))
  39. #df2 = df.groupby(['CSR', 'System']).sum()
  40. #print(df2)
  41. #ax = df[df['count'] > 1].groupby(['CSR', 'System']).sum().unstack().plot( \
  42. #x="Control Status Registers", \
  43. #kind="bar", \
  44. #stacked=True, \
  45. #title="CSRs across different systems", \
  46. #logy=True, \
  47. #rot=0, \
  48. #colormap='tab10_r', \
  49. #width=0.7, \
  50. #figsize=(11, 8))
  51. #plt.legend([names[0], names[2], names[3], names[1]], title='Systems')
  52. # modify plot to have grid in the background
  53. #ax.grid(which='major', linestyle='-', linewidth='0.5') #, color='red')
  54. #ax.grid(which='minor', linestyle='--', linewidth='0.4') #, color='red')
  55. #ax.set_axisbelow(True)
  56. # extract figure and save to file
  57. #fig = ax.get_figure()
  58. #fig.savefig(f'histogram.{3}.png')