OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
make_benchmark_graphs.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Requires matplotlib for graphing
4 # reads *_benchmark.csv files as output by atomspace_bm and turns them into
5 # graphs.
6 
7 
8 import csv
9 import numpy as np
10 import matplotlib.colors as colors
11 #import matplotlib.finance as finance
12 import matplotlib.dates as mdates
13 import matplotlib.ticker as mticker
14 import matplotlib.mlab as mlab
15 import matplotlib.pyplot as plt
16 #import matplotlib.font_manager as font_manager
17 
18 import glob
19 import pdb
20 
21 
22 def moving_average(x, n, type='simple'):
23  """
24  compute an n period moving average.
25 
26  type is 'simple' | 'exponential'
27 
28  """
29  x = np.asarray(x)
30  if type=='simple':
31  weights = np.ones(n)
32  else:
33  weights = np.exp(np.linspace(-1., 0., n))
34 
35  weights /= weights.sum()
36 
37  a = np.convolve(x, weights, mode='full')[:len(x)]
38  a[:n] = a[n]
39  return a
40 
41 def graph_file(fn,delta_rss=True):
42  print "Graphing " + fn
43  records = csv.reader(open(fn,'rb'),delimiter=",")
44  sizes=[]; times=[]; times_seconds=[]; memories=[]
45  for row in records:
46  sizes.append(int(row[0]))
47  times.append(int(row[1]))
48  memories.append(int(row[2]))
49  times_seconds.append(float(row[3]))
50 
51  left, width = 0.1, 0.8
52  rect1 = [left, 0.5, width, 0.4] #left, bottom, width, height
53  rect2 = [left, 0.1, width, 0.4]
54 
55  fig = plt.figure(facecolor='white')
56  axescolor = '#f6f6f6' # the axies background color
57 
58  ax1 = fig.add_axes(rect1, axisbg=axescolor)
59  ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex=ax1)
60 
61  ax1.plot(sizes,times_seconds,color='black')
62  if len(times_seconds) > 1000:
63  ax1.plot(sizes,moving_average(times_seconds,len(times_second) / 100),color='blue')
64  if delta_rss:
65  oldmemories = list(memories)
66  for i in range(1,len(memories)): memories[i] = oldmemories[i] - oldmemories[i-1]
67  ax2.plot(sizes,memories,color='black')
68 
69  for label in ax1.get_xticklabels():
70  label.set_visible(False)
71 
72  class MyLocator(mticker.MaxNLocator):
73  def __init__(self, *args, **kwargs):
74  mticker.MaxNLocator.__init__(self, *args, **kwargs)
75 
76  def __call__(self, *args, **kwargs):
77  return mticker.MaxNLocator.__call__(self, *args, **kwargs)
78 
79  # at most 7 ticks, pruning the upper and lower so they don't overlap
80  # with other ticks
81  fmt = mticker.ScalarFormatter()
82  fmt.set_powerlimits((-3, 4))
83  ax1.yaxis.set_major_formatter(fmt)
84 
85  ax2.yaxis.set_major_locator(MyLocator(7, prune='upper'))
86  fmt = mticker.ScalarFormatter()
87  fmt.set_powerlimits((-3, 4))
88  ax2.yaxis.set_major_formatter(fmt)
89  ax2.yaxis.offsetText.set_visible(False)
90  fig.show()
91  size = int(fmt.orderOfMagnitude) / 3
92  labels = ["B","KB","MB","GB"]
93  label = labels[size]
94  labels = ["","(10s)","(100s)"]
95  label += " " + labels[int(fmt.orderOfMagnitude) % 3]
96 
97  ax2.set_xlabel("AtomSpace Size")
98  ax2.set_ylabel("RSS " + label)
99  ax1.set_ylabel("Time (seconds)")
100  ax1.set_title(fn)
101  fig.show()
102 
103  fig.savefig(fn+".png",format="png")
104 
105 files_to_graph = glob.glob("*_benchmark.csv")
106 
107 for fn in files_to_graph:
108  graph_file(fn);
109 
110 
111 
112