-
Notifications
You must be signed in to change notification settings - Fork 3
/
speedcenter.py
128 lines (101 loc) · 3.3 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
119
120
121
122
123
124
125
126
127
128
"""
Evaluate one or more benchmarks and upload the results to a Speedcenter server.
"""
from __future__ import division, print_function
import json
import subprocess
import sys
import platform
from datetime import datetime
from os import path, uname
from sys import argv, executable, stdout
import requests
from twisted.python.compat import nativeString
from twisted.python.usage import UsageError
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():
lines = subprocess.check_output(
["git", "show", "-q", '--format=%H,%ai']
).split(b"\n")
revision, date = lines[0].split(b",")
exec_trimmed = path.basename(executable)
resp = {
'project': 'Twisted',
'executable': exec_trimmed,
'environment': platform.uname()[0],
'commitid': nativeString(revision),
'branch': 'trunk',
'revision_date': " ".join(nativeString(date).split(" ")[0:2]),
'result_date': str(datetime.now())[0:-7],
}
print(resp)
return resp
def main():
options = SpeedcenterOptions()
try:
options.parseOptions(argv[1:])
except UsageError as e:
raise SystemExit(str(e))
environment = reportEnvironment()
from all import allBenchmarks
driver = SpeedcenterDriver()
driver.results = {}
driver.run_jobs(
allBenchmarks,
options['duration'],
options['iterations'],
options['warmup'],
)
allStats = []
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)
allStats.append(stats)
tries = 0
r = None
while tries < 5:
r = requests.post(options['url'], data={"json": json.dumps(allStats)})
if r.status_code == 202:
print(r.content)
return
tries = tries + 1
print("Try #{}".format(tries))
print(r.content)
sys.exit(1)
if __name__ == '__main__':
main()