/
speedcenter.py
118 lines (90 loc) · 3.28 KB
/
speedcenter.py
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
"""
Evaluate one or more benchmarks and upload the results to a Speedcenter server.
"""
from __future__ import division
from sys import argv, stdout
from os import uname
from sys import executable
from datetime import datetime
from urllib import urlopen, urlencode
import twisted
from twisted.python.filepath import FilePath
from twisted.python.usage import UsageError
from all import allBenchmarks
from benchlib import BenchmarkOptions, Driver
# Unfortunately, benchmark name is the primary key for speedcenter
SPEEDCENTER_NAMES = {
'tcp_connect': 'TCP Connections',
'tcp_throughput': 'TCP Throughput',
'ssh_connect': 'SSH Connections',
'ssh_throughput': 'SSH Throughput',
'ssl_connect': 'SSL Connections',
'ssl_throughput': 'SSL Throughput',
'sslbio_connect': 'SSL (Memory BIO) Connections',
'sslbio_throughput': 'SSL (Memory BIO) Throughput',
}
class SpeedcenterOptions(BenchmarkOptions):
optParameters = [
('url', None, None, 'Location of Speedcenter to which to upload results.'),
]
def postOptions(self):
if not self['url']:
raise UsageError("The Speedcenter URL must be provided.")
class SpeedcenterDriver(Driver):
def benchmark_report(self, acceptCount, duration, name):
print name, acceptCount, duration
stdout.flush()
self.results.setdefault(name, []).append((acceptCount, duration))
def reportEnvironment():
revision = twisted.version.short().split('r', 1)[1]
packageDirectory = FilePath(twisted.__file__).parent()
try:
import pysvn
except ImportError:
entries = packageDirectory.child('.svn').child('entries').getContent()
lines = entries.splitlines()
revision = lines[3]
date = lines[9][:20].replace('T', ' ')
else:
client = pysvn.Client()
[entry] = client.log(
packageDirectory.path,
pysvn.Revision(pysvn.opt_revision_kind.number, int(revision)),
limit=1)
date = str(datetime.fromtimestamp(entry['date']))
return {
'project': 'Twisted',
'executable': executable,
'environment': uname()[1],
'commitid': revision,
'revision_date': date,
'result_date': str(datetime.now()),
}
def main():
options = SpeedcenterOptions()
try:
options.parseOptions(argv[1:])
except UsageError, e:
raise SystemExit(str(e))
driver = SpeedcenterDriver()
driver.results = {}
driver.run_jobs(
allBenchmarks,
options['duration'], options['iterations'], options['warmup'])
environment = reportEnvironment()
for (name, results) in sorted(driver.results.items()):
rates = [count / duration for (count, duration) in results]
totalCount = sum([count for (count, duration) in results])
totalDuration = sum([duration for (count, duration) in results])
name = SPEEDCENTER_NAMES.get(name, name)
stats = environment.copy()
stats['benchmark'] = name
stats['result_value'] = totalCount / totalDuration
stats['min'] = min(rates)
stats['max'] = max(rates)
# Please excuse me.
fObj = urlopen(options['url'], urlencode(stats))
print name, fObj.read()
fObj.close()
if __name__ == '__main__':
main()