Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/benchmarks/gen-plots
blob: 9d6d43a5016cbd3aa265cd27587e581f8f76b751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python
import re
import sys

opNames=["createRepo", "checkoutFirst", "commit", "checkoutIntermediate", "createBranch", "checkoutBranch", "commitBranch"]
shortOpNames=["create", "checkout", "commit", "checkoutInterm.", "branch", "checkoutBr.", "commitBr."]
multiOpNames=["commit", "checkoutFirst", "checkoutBranch", "commitBranch"]
dataSize=33443482

def formatInline(datum) :
  if isinstance(datum, unicode) :
    return '"%s"' % (datum.replace('"', '\"').encode('utf-8'),)
  elif isinstance(datum, str) :
    return '"%s"' % (datum.replace('"', '\"'),)
  else :
    return str(datum)

def printInlineData(data) :
  print "\n".join([" ".join([formatInline(col) for col in row]) for row in data])
  print "e"

def genOpVsTimePlot(stats, ftype) :
  vcsNames = stats.keys()
  vcsNames.sort()

  print "set output 'output/op-vs-time.%s'" % (ftype,)
  print "set key inside right"
  print "set boxwidth 0.93 relative"
  print "set style fill solid"
  print "set style histogram clustered gap 2"
  print "set autoscale yfixmax"
  print "set xrange [-.5:6.6]"
  print "set ylabel 'Runtime [s]'"
  print "set xlabel 'Operation'"
  print "set xtics scale 0"
  print "plot "+",".join(["'-' using 1:xtic(2) with histograms title '%s'" % (vcs,) for vcs in vcsNames])
  for vcs in vcsNames :
    printInlineData([(stats[vcs][lName+"Time"], sName) for (lName, sName) in zip(opNames, shortOpNames)])

  for vcs in vcsNames :
    print "set style histogram clustered gap 1"
    print "set output 'output/op-vs-time-%s.%s'" % (vcs,ftype)
    print "plot '-' using 1:xtic(2) with histograms title '%s'" % (vcs,)
    printInlineData([(stats[vcs][lName+"Time"], sName) for (lName, sName) in zip(opNames, shortOpNames)])

def genOpVsSizePlot(stats, ftype) :
  vcsNames = stats.keys()
  vcsNames.sort()

  print "reset"
  print "set output 'output/op-vs-size.%s'" % (ftype,)
  print "set key inside left"
  print "set boxwidth 0.93 relative"
  print "set autoscale ymax"
  print "set autoscale y2max"
  print "set xrange [-.5:3.6]"
  print "set yrange [0:]"
  print "set y2range [0:]"
  print "set ylabel 'Repository size (relative)'"
  print "set xlabel 'Operation'"
  print "set style fill solid"
  print "set style histogram clustered gap 2"
  print "set style line 1 linewidth 3"
  print "set style line 1 default"
  print "set xtics scale 0"
  print "set ytics nomirror"
  print "set y2tics"
  print "plot "+",".join(
      ["'-' using 1:xtic(2) with histograms title '%s'" % (vcs,) for vcs in vcsNames]+
      ["1 title 'input size'"])
  for vcs in vcsNames :
    dset = stats[vcs]
    printInlineData([(dset["repoSizeAfter"+lName[0].upper()+lName[1:]]*1024./dataSize, lName)
      for lName in opNames
      if not lName.startswith("checkout")])

  for vcs in vcsNames :
    print "set style histogram clustered gap 1"
    print "set output 'output/op-vs-size-%s.%s'" % (vcs,ftype)
    print "plot '-' using 1:xtic(2) with histograms title '%s', 1 title 'input size'" % (vcs,)
    printInlineData([(stats[vcs]["repoSizeAfter"+lName[0].upper()+lName[1:]]*1024./dataSize, lName)
      for lName in opNames
      if not lName.startswith("checkout")])


def genTotalsPlot(stats, ftype) :
  vcsNames = stats.keys()
  vcsNames.sort()

  print "reset"
  print "set output 'output/total.%s'" % (ftype,)
  print "set multiplot"
  print "set size 0.42,1"
  print "set origin 0,0"
  print "unset key"
  print "set boxwidth 0.93 relative"
  print "set style fill solid"
  print "set style histogram clustered gap 2"
  print "set autoscale ymax"
  print "set xrange [-.4:.5]"
  print "set yrange [0:]"
  print "set ylabel 'Runtime [s]'"
  print "unset xlabel"
  print "unset xtics"
  print "set ytics nomirror"
  print "plot "+",".join(["'-' using 1:xtic(2) with histograms title '%s'" % (vcs) for vcs in vcsNames])
  for vcs in vcsNames :
    dset = stats[vcs]
    printInlineData([(dset["totalTime"], "totalTime")])

  print "set key outside right"
  print "set ylabel 'Repository size (relative)'"
  print "set size 0.58,1"
  print "set origin 0.42,0"
  print "plot "+",".join(
      ["'-' using 1:xtic(2) with histograms title '%s'" % (vcs) for vcs in vcsNames]+
      ["1 title 'input size'"])
  for vcs in vcsNames :
    dset = stats[vcs]
    printInlineData([(dset["repoSizeAfterTotal"]*1024./dataSize, "repoSizeAfterTotal")])

  print "unset multiplot"

def genPlots(stats, ftype) :
  genOpVsTimePlot(stats, ftype)
  genOpVsSizePlot(stats, ftype)
  genTotalsPlot(stats, ftype)

def avg(samples) :
  return sum(samples)/len(samples)

def calcTotals(stats) :
  for dset in stats.values() :
    # summary of repeated commands
    for op in multiOpNames :
      timeRe = re.compile("^%s[0-9]+Time$" % (op,))
      samples = [val for (key, val) in dset.items() if timeRe.match(key)]
      dset[op+"SumTime"] = sum(samples)
      dset[op+"Time"] = avg(samples)
      if op.startswith("checkout") :
        continue

      sizeRe = re.compile("^repoSizeAfter%s%s[0-9]+$" % (op[0].upper(),op[1:]))
      dset["repoSizeAfter"+op[0].upper()+op[1:]] = max([val for (key, val) in dset.items() if sizeRe.match(key)])

    # summary over all operations
    dset["totalTime"] = sum([dset["%s%sTime" % (op, ['','Sum'][op in multiOpNames])] for op in opNames])
    dset["repoSizeAfterTotal"] = max([dset["repoSizeAfter"+op[0].upper()+op[1:]] for op in opNames if not op.startswith("checkout")])

def main(myName, args) :
  ftype = ["ps", "png"]["png" in args]
  stats = input()
  if (ftype == "png") :
    print 'set terminal png size 1024 768'
  else :
    print 'set terminal postscript landscape enhanced color solid lw 1 "Helvetica" 14'

  calcTotals(stats)
  genPlots(stats, ftype)

sys.exit(main(sys.argv[0], sys.argv[1:]))