plot-speeds.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. import matplotlib as mpl
  7. from pylab import *
  8. KB_ = 1024
  9. MB_ = 1024*KB_
  10. GB_ = 1024*MB_
  11. NCHUNKS = 128 # keep in sync with bench.c
  12. linewidth=2
  13. #markers= ['+', ',', 'o', '.', 's', 'v', 'x', '>', '<', '^']
  14. #markers= [ 'x', '+', 'o', 's', 'v', '^', '>', '<', ]
  15. markers= [ 's', 'o', 'v', '^', '+', 'x', '>', '<', '.', ',' ]
  16. markersize = 8
  17. def get_values(filename):
  18. f = open(filename)
  19. values = {"memcpyw": [], "memcpyr": []}
  20. for line in f:
  21. if line.startswith('-->'):
  22. tmp = line.split('-->')[1]
  23. nthreads, size, elsize, sbits, codec, shuffle = [i for i in tmp.split(', ')]
  24. nthreads, size, elsize, sbits = map(int, (nthreads, size, elsize, sbits))
  25. values["size"] = size * NCHUNKS / MB_;
  26. values["elsize"] = elsize;
  27. values["sbits"] = sbits;
  28. values["codec"] = codec
  29. values["shuffle"] = shuffle
  30. # New run for nthreads
  31. (ratios, speedsw, speedsr) = ([], [], [])
  32. # Add a new entry for (ratios, speedw, speedr)
  33. values[nthreads] = (ratios, speedsw, speedsr)
  34. #print "-->", nthreads, size, elsize, sbits
  35. elif line.startswith('memcpy(write):'):
  36. tmp = line.split(',')[1]
  37. memcpyw = float(tmp.split(' ')[1])
  38. values["memcpyw"].append(memcpyw)
  39. elif line.startswith('memcpy(read):'):
  40. tmp = line.split(',')[1]
  41. memcpyr = float(tmp.split(' ')[1])
  42. values["memcpyr"].append(memcpyr)
  43. elif line.startswith('comp(write):'):
  44. tmp = line.split(',')[1]
  45. speedw = float(tmp.split(' ')[1])
  46. ratio = float(line.split(':')[-1])
  47. speedsw.append(speedw)
  48. ratios.append(ratio)
  49. elif line.startswith('decomp(read):'):
  50. tmp = line.split(',')[1]
  51. speedr = float(tmp.split(' ')[1])
  52. speedsr.append(speedr)
  53. if "OK" not in line:
  54. print "WARNING! OK not found in decomp line!"
  55. f.close()
  56. return nthreads, values
  57. def show_plot(plots, yaxis, legends, gtitle, xmax=None):
  58. xlabel('Compresssion ratio')
  59. ylabel('Speed (MB/s)')
  60. title(gtitle)
  61. xlim(0, xmax)
  62. #ylim(0, 10000)
  63. ylim(0, None)
  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('-r', '--report', action='store_true',
  103. dest='report',
  104. help='generate file for reporting ',
  105. default=False)
  106. parser.add_option('-d', '--decompress', action='store_true',
  107. dest='dspeed',
  108. help='plot decompression data',
  109. default=False)
  110. parser.add_option('-c', '--compress', action='store_true',
  111. dest='cspeed',
  112. help='plot compression data',
  113. default=False)
  114. (options, args) = parser.parse_args()
  115. if len(args) == 0:
  116. parser.error("No input arguments")
  117. elif len(args) > 1:
  118. parser.error("Too many input arguments")
  119. else:
  120. pass
  121. if options.report and options.outfile:
  122. parser.error("Can only select one of [-r, -o]")
  123. if options.dspeed and options.cspeed:
  124. parser.error("Can only select one of [-d, -c]")
  125. elif options.cspeed:
  126. options.dspeed = False
  127. plot_title = compress_title
  128. else: # either neither or dspeed
  129. options.dspeed = True
  130. plot_title = decompress_title
  131. filename = args[0]
  132. cspeed = options.cspeed
  133. dspeed = options.dspeed
  134. if options.outfile:
  135. outfile = options.outfile
  136. elif options.report:
  137. if cspeed:
  138. outfile = filename[:filename.rindex('.')] + '-compr.png'
  139. else:
  140. outfile = filename[:filename.rindex('.')] + '-decompr.png'
  141. else:
  142. outfile = None
  143. plots = []
  144. legends = []
  145. nthreads, values = get_values(filename)
  146. #print "Values:", values
  147. if options.limit:
  148. thread_range = eval(options.limit)
  149. else:
  150. thread_range = range(1, nthreads+1)
  151. if options.title:
  152. plot_title = options.title
  153. else:
  154. plot_title += " (%(size).1f MB, %(elsize)d bytes, %(sbits)d bits), %(codec)s %(shuffle)s" % values
  155. gtitle = plot_title
  156. for nt in thread_range:
  157. #print "Values for %s threads --> %s" % (nt, values[nt])
  158. (ratios, speedw, speedr) = values[nt]
  159. if cspeed:
  160. speed = speedw
  161. else:
  162. speed = speedr
  163. #plot_ = semilogx(ratios, speed, linewidth=2)
  164. plot_ = plot(ratios, speed, linewidth=2)
  165. plots.append(plot_)
  166. nmarker = nt
  167. if nt >= len(markers):
  168. nmarker = nt%len(markers)
  169. setp(plot_, marker=markers[nmarker], markersize=markersize,
  170. linewidth=linewidth)
  171. legends.append("%d threads" % nt)
  172. # Add memcpy lines
  173. if cspeed:
  174. mean = np.mean(values["memcpyw"])
  175. message = "memcpy (write to memory)"
  176. else:
  177. mean = np.mean(values["memcpyr"])
  178. message = "memcpy (read from memory)"
  179. plot_ = axhline(mean, linewidth=3, linestyle='-.', color='black')
  180. text(1.0, mean+50, message)
  181. plots.append(plot_)
  182. show_plot(plots, yaxis, legends, gtitle, xmax=int(options.xmax) if
  183. options.xmax else None)