Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/benchmarks/gen-plots
blob: 3918b708cccabffb7171bf01c9c5aceb6486b5d8 (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
#!/usr/bin/env python
import re
import sys

opNames=["createRepo", "checkoutFirst", "commit", "checkoutIntermediate", "createBranch", "checkoutBranch", "commitBranch"]
shortOpNames=["create", "checkout", "commit", "intermediate", "branch", "checkoutB", "commitB"]
multiOpNames=["commit", "checkoutFirst", "checkoutBranch", "commitBranch"]

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 outside right"
  print "set style fill solid"
  print "set style histogram clustered gap 2"
  print "set autoscale yfixmax"
  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 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 autoscale ymax"
  print "set autoscale y2max"
  print "set yrange [0:]"
  print "set y2range [0:]"
  print "set ylabel 'Repository size [MB]'"
  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])
  for vcs in vcsNames :
    dset = stats[vcs]
    printInlineData([(dset["repoSizeAfter"+lName[0].upper()+lName[1:]]/1024, sName)
      for (lName, sName) in zip(opNames, shortOpNames)
      if not lName.startswith("checkout")])

  for vcs in vcsNames :
    print "set output 'output/op-vs-size-%s.%s'" % (vcs,ftype)
    print "plot '-' using 1:xtic(2) with histograms title '%s'" % (vcs,)
    printInlineData([(stats[vcs]["repoSizeAfter"+lName[0].upper()+lName[1:]]/1024, sName)
      for (lName, sName) in zip(opNames, shortOpNames)
      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 layout 1,2"
  print "unset key"
  print "set style fill solid"
  print "set style histogram clustered gap 2"
  print "set autoscale yfixmax"
  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 [MB]'"
  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["repoSizeAfterTotal"]/1024, "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:]))