plot-speeds.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. """Script for plotting the results of the 'suite' benchmark.
  2. Invoke without parameters for usage hints.
  3. :Author: Francesc Alted
  4. :Date: 2010-06-01
  5. """
  6. from __future__ import print_function
  7. import matplotlib as mpl
  8. from pylab import *
  9. KB_ = 1024
  10. MB_ = 1024*KB_
  11. GB_ = 1024*MB_
  12. NCHUNKS = 128 # keep in sync with bench.c
  13. linewidth=2
  14. #markers= ['+', ',', 'o', '.', 's', 'v', 'x', '>', '<', '^']
  15. #markers= [ 'x', '+', 'o', 's', 'v', '^', '>', '<', ]
  16. markers= [ 's', 'o', 'v', '^', '+', 'x', '>', '<', '.', ',' ]
  17. markersize = 8
  18. def get_values(filename):
  19. f = open(filename)
  20. values = {"memcpyw": [], "memcpyr": []}
  21. for line in f:
  22. if line.startswith('-->'):
  23. tmp = line.split('-->')[1]
  24. nthreads, size, elsize, sbits, codec, shuffle = [i for i in tmp.split(', ')]
  25. nthreads, size, elsize, sbits = map(int, (nthreads, size, elsize, sbits))
  26. values["size"] = size * NCHUNKS / MB_
  27. values["elsize"] = elsize
  28. values["sbits"] = sbits
  29. values["codec"] = codec
  30. values["shuffle"] = shuffle
  31. # New run for nthreads
  32. (ratios, speedsw, speedsr) = ([], [], [])
  33. # Add a new entry for (ratios, speedw, speedr)
  34. values[nthreads] = (ratios, speedsw, speedsr)
  35. #print("-->", nthreads, size, elsize, sbits)
  36. elif line.startswith('memcpy(write):'):
  37. tmp = line.split(',')[1]
  38. memcpyw = float(tmp.split(' ')[1])
  39. values["memcpyw"].append(memcpyw)
  40. elif line.startswith('memcpy(read):'):
  41. tmp = line.split(',')[1]
  42. memcpyr = float(tmp.split(' ')[1])
  43. values["memcpyr"].append(memcpyr)
  44. elif line.startswith('comp(write):'):
  45. tmp = line.split(',')[1]
  46. speedw = float(tmp.split(' ')[1])
  47. ratio = float(line.split(':')[-1])
  48. speedsw.append(speedw)
  49. ratios.append(ratio)
  50. elif line.startswith('decomp(read):'):
  51. tmp = line.split(',')[1]
  52. speedr = float(tmp.split(' ')[1])
  53. speedsr.append(speedr)
  54. if "OK" not in line:
  55. print("WARNING! OK not found in decomp line!")
  56. f.close()
  57. return nthreads, values
  58. def show_plot(plots, yaxis, legends, gtitle, xmax=None, ymax=None):
  59. xlabel('Compresssion ratio')
  60. ylabel('Speed (MB/s)')
  61. title(gtitle)
  62. xlim(0, xmax)
  63. ylim(0, ymax)
  64. grid(True)
  65. # legends = [f[f.find('-'):f.index('.out')] for f in filenames]
  66. # legends = [l.replace('-', ' ') for l in legends]
  67. #legend([p[0] for p in plots], legends, loc = "upper left")
  68. legend([p[0] for p in plots
  69. if not isinstance(p, mpl.lines.Line2D)],
  70. legends, loc = "best")
  71. #subplots_adjust(bottom=0.2, top=None, wspace=0.2, hspace=0.2)
  72. if outfile:
  73. print("Saving plot to:", outfile)
  74. savefig(outfile, dpi=64)
  75. else:
  76. show()
  77. if __name__ == '__main__':
  78. from optparse import OptionParser
  79. usage = "usage: %prog [-r] [-o outfile] [-t title ] [-d|-c] filename"
  80. compress_title = 'Compression speed'
  81. decompress_title = 'Decompression speed'
  82. yaxis = 'No axis name'
  83. parser = OptionParser(usage=usage)
  84. parser.add_option('-o',
  85. '--outfile',
  86. dest='outfile',
  87. help=('filename for output (many extensions '
  88. 'supported, e.g. .png, .jpg, .pdf)'))
  89. parser.add_option('-t',
  90. '--title',
  91. dest='title',
  92. help='title of the plot',)
  93. parser.add_option('-l',
  94. '--limit',
  95. dest='limit',
  96. help='expression to limit number of threads shown',)
  97. parser.add_option('-x',
  98. '--xmax',
  99. dest='xmax',
  100. help='limit the x-axis',
  101. default=None)
  102. parser.add_option('-y',
  103. '--ymax',
  104. dest='ymax',
  105. help='limit the y-axis',
  106. default=None)
  107. parser.add_option('-r', '--report', action='store_true',
  108. dest='report',
  109. help='generate file for reporting ',
  110. default=False)
  111. parser.add_option('-d', '--decompress', action='store_true',
  112. dest='dspeed',
  113. help='plot decompression data',
  114. default=False)
  115. parser.add_option('-c', '--compress', action='store_true',
  116. dest='cspeed',
  117. help='plot compression data',
  118. default=False)
  119. (options, args) = parser.parse_args()
  120. if len(args) == 0:
  121. parser.error("No input arguments")
  122. elif len(args) > 1:
  123. parser.error("Too many input arguments")
  124. else:
  125. pass
  126. if options.report and options.outfile:
  127. parser.error("Can only select one of [-r, -o]")
  128. if options.dspeed and options.cspeed:
  129. parser.error("Can only select one of [-d, -c]")
  130. elif options.cspeed:
  131. options.dspeed = False
  132. plot_title = compress_title
  133. else: # either neither or dspeed
  134. options.dspeed = True
  135. plot_title = decompress_title
  136. filename = args[0]
  137. cspeed = options.cspeed
  138. dspeed = options.dspeed
  139. if options.outfile:
  140. outfile = options.outfile
  141. elif options.report:
  142. if cspeed:
  143. outfile = filename[:filename.rindex('.')] + '-compr.png'
  144. else:
  145. outfile = filename[:filename.rindex('.')] + '-decompr.png'
  146. else:
  147. outfile = None
  148. plots = []
  149. legends = []
  150. nthreads, values = get_values(filename)
  151. #print("Values:", values)
  152. if options.limit:
  153. thread_range = eval(options.limit)
  154. else:
  155. thread_range = range(1, nthreads+1)
  156. if options.title:
  157. plot_title = options.title
  158. else:
  159. plot_title += " (%(size).1f MB, %(elsize)d bytes, %(sbits)d bits), %(codec)s %(shuffle)s" % values
  160. gtitle = plot_title
  161. for nt in thread_range:
  162. #print("Values for %s threads --> %s" % (nt, values[nt]))
  163. (ratios, speedw, speedr) = values[nt]
  164. if cspeed:
  165. speed = speedw
  166. else:
  167. speed = speedr
  168. #plot_ = semilogx(ratios, speed, linewidth=2)
  169. plot_ = plot(ratios, speed, linewidth=2)
  170. plots.append(plot_)
  171. nmarker = nt
  172. if nt >= len(markers):
  173. nmarker = nt%len(markers)
  174. setp(plot_, marker=markers[nmarker], markersize=markersize,
  175. linewidth=linewidth)
  176. legends.append("%d threads" % nt)
  177. # Add memcpy lines
  178. if cspeed:
  179. mean = np.mean(values["memcpyw"])
  180. message = "memcpy (write to memory)"
  181. else:
  182. mean = np.mean(values["memcpyr"])
  183. message = "memcpy (read from memory)"
  184. plot_ = axhline(mean, linewidth=3, linestyle='-.', color='black')
  185. text(4.0, mean+400, message)
  186. plots.append(plot_)
  187. show_plot(plots, yaxis, legends, gtitle,
  188. xmax=int(options.xmax) if options.xmax else None,
  189. ymax=int(options.ymax) if options.ymax else None)