]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/simulators/bench_spans.py
Don't call time.tzset() if the platform doesn't have it. fixes ticket:2723
[tahoe-lafs/tahoe-lafs.git] / misc / simulators / bench_spans.py
1 """
2 To use this, get a trace file such as this one:
3
4 wget http://tahoe-lafs.org/trac/tahoe-lafs/raw-attachment/ticket/1170/run-112-above28-flog-dump-sh8-on-nsziz.txt
5
6 And run this command passing that trace file's name:
7
8 python bench_spans.py run-112-above28-flog-dump-sh8-on-nsziz.txt
9 """
10
11 from pyutil import benchutil
12
13 from allmydata.util.spans import DataSpans
14
15 import re, sys
16
17 DUMP_S='_received spans trace .dump()'
18 GET_R=re.compile('_received spans trace .get\(([0-9]*), ([0-9]*)\)')
19 POP_R=re.compile('_received spans trace .pop\(([0-9]*), ([0-9]*)\)')
20 REMOVE_R=re.compile('_received spans trace .remove\(([0-9]*), ([0-9]*)\)')
21 GET_SPANS_S='_received spans trace .get_spans()'
22 ADD_R=re.compile('_received spans trace .add\(([0-9]*), len=([0-9]*)\)')
23 INIT_S='_received spans trace = DataSpans'
24
25 class B(object):
26     def __init__(self, inf):
27         self.inf = inf
28
29     def init(self, N):
30         self.s = DataSpans()
31         # self.stats = {}
32
33     def run(self, N):
34         count = 0
35         inline = self.inf.readline()
36
37         while count < N and inline != '':
38             if DUMP_S in inline:
39                 self.s.dump()
40                 # self.stats['dump'] = self.stats.get('dump', 0) + 1
41             elif GET_SPANS_S in inline:
42                 self.s.get_spans()
43                 # self.stats['get_spans'] = self.stats.get('get_spans', 0) + 1
44             elif ADD_R.search(inline):
45                 mo = ADD_R.search(inline)
46                 start = int(mo.group(1))
47                 length = int(mo.group(2))
48                 self.s.add(start, 'x'*length)
49                 # self.stats['add'] = self.stats.get('add', 0) + 1
50             elif GET_R.search(inline):
51                 mo = GET_R.search(inline)
52                 start = int(mo.group(1))
53                 length = int(mo.group(2))
54                 self.s.get(start, length)
55                 # self.stats['get'] = self.stats.get('get', 0) + 1
56             elif REMOVE_R.search(inline):
57                 mo = REMOVE_R.search(inline)
58                 start = int(mo.group(1))
59                 length = int(mo.group(2))
60                 self.s.remove(start, length)
61                 # self.stats['remove'] = self.stats.get('remove', 0) + 1
62             elif POP_R.search(inline):
63                 mo = POP_R.search(inline)
64                 start = int(mo.group(1))
65                 length = int(mo.group(2))
66                 self.s.pop(start, length)
67                 # self.stats['pop'] = self.stats.get('pop', 0) + 1
68             elif INIT_S in inline:
69                 pass
70             else:
71                 print "Warning, didn't recognize this line: %r" % (inline,)
72             count += 1
73             inline = self.inf.readline()
74
75         # print self.stats
76
77 benchutil.print_bench_footer(UNITS_PER_SECOND=1000000)
78 print "(microseconds)"
79
80 for N in [600, 6000, 60000]:
81     b = B(open(sys.argv[1], 'rU'))
82     print "%7d" % N,
83     benchutil.rep_bench(b.run, N, b.init, UNITS_PER_SECOND=1000000)
84