Skip to content

Commit f625698

Browse files
authored
Merge pull request #55 from mattip/cpython-baseline
compare to cpython3.11, fix some tools
2 parents 010389e + bb3d41a commit f625698

3 files changed

Lines changed: 214 additions & 82 deletions

File tree

speed_pypy/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
SHOW_REPORTS = False
9191
SHOW_HISTORICAL = True
9292
DEF_BASELINES = [
93-
{'executable': 'cpython', 'revision': '3.7.19'},
9493
{'executable': 'cpython', 'revision': '3.11.9'},
9594
{'executable': 'cpython', 'revision': '3.12.4'},
9695
]
9796
DEF_EXECUTABLES = [
97+
{'name': 'pypy3.11-jit-64', 'project': 'PyPy3.11'},
9898
{'name': 'pypy3.10-jit-64', 'project': 'PyPy3.10'},
9999
{'name': 'pypy3.9-jit-64', 'project': 'PyPy3.9'},
100100
]

tools/pypy/import_from_json.py

Lines changed: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,88 @@
22
################################################################################
33
# This script imports PyPy's result data from json files located on the server #
44
################################################################################
5-
import simplejson, urllib2
5+
import simplejson
6+
from urllib.request import urlopen
7+
from urllib.error import URLError
68
import sys
79
from xml.dom.minidom import parse
810
from datetime import datetime
9-
import saveresults, savecpython
11+
import saveresults
1012

11-
RESULTS_URLS = {
12-
'pypy-c-jit': 'http://buildbot.pypy.org/bench_results/',
13-
'pypy-c': 'http://buildbot.pypy.org/bench_results_nojit/',
14-
}
15-
START_REV = 79485
16-
END_REV = 79485
17-
PROJECT = "PyPy"
13+
URL = 'http://buildbot.pypy.org/benchmark-results/'
14+
START_REV = 186137
15+
END_REV = 200000
1816

19-
for INTERP in RESULTS_URLS:
20-
RESULTS_URL = RESULTS_URLS[INTERP]
21-
# get json filenames
22-
filelist = []
23-
try:
24-
datasource = urllib2.urlopen(RESULTS_URL)
25-
dom = parse(datasource)
26-
for elem in dom.getElementsByTagName('td'):
27-
for e in elem.childNodes:
28-
if len(e.childNodes):
29-
filename = e.firstChild.toxml()
30-
if e.tagName == "a" and ".json" in filename:
31-
if int(filename.replace(".json", "")) >= START_REV and\
32-
int(filename.replace(".json", "")) <= END_REV:
33-
filelist.append(filename)
34-
except urllib2.URLError, e:
35-
response = "None"
36-
if hasattr(e, 'reason'):
37-
response = '\n We failed to reach ' + RESULTS_URL + '\n'
38-
response += ' Reason: ' + str(e.reason)
39-
elif hasattr(e, 'code'):
40-
response = '\n The server couldn\'t fulfill the request\n'
41-
response += ' Error code: ' + str(e)
42-
print "Results Server (%s) response: %s\n" % (RESULTS_URL, response)
43-
sys.exit(1)
44-
finally:
45-
datasource.close()
4617

47-
# read json result and save to speed.pypy.org
48-
for filename in filelist:
49-
print "Reading %s..." % filename
50-
f = urllib2.urlopen(RESULTS_URL + filename)
51-
result = simplejson.load(f)
52-
f.close()
53-
proj = PROJECT
54-
revision = result['revision']
55-
interpreter = INTERP
56-
int_options = ""
57-
options = ""
58-
if 'options' in result:
59-
options = result['options']
18+
speed_url = "http://127.0.0.1:8000/"
6019

61-
host = 'tannit'
62-
#saveresults.save(proj, revision, result['results'], options, interpreter, host)
63-
if filename == filelist[len(filelist)-1]:
64-
savecpython.save('cpython', '100', result['results'], options, 'cpython', host)
65-
print "\nOK"
20+
# get json filenames
21+
filelist = []
22+
try:
23+
datasource = urlopen(URL)
24+
dom = parse(datasource)
25+
for elem in dom.getElementsByTagName('td'):
26+
for e in elem.childNodes:
27+
if len(e.childNodes):
28+
filename = e.firstChild.toxml()
29+
if e.tagName == "a" and ".json" in filename:
30+
rev_int = int(filename.split(":")[0])
31+
if START_REV <= rev_int <= END_REV:
32+
filelist.append(filename)
33+
except URLError as e:
34+
response = "None"
35+
if hasattr(e, 'reason'):
36+
response = '\n We failed to reach ' + URL + '\n'
37+
response += ' Reason: ' + str(e.reason)
38+
elif hasattr(e, 'code'):
39+
response = '\n The server couldn\'t fulfill the request\n'
40+
response += ' Error code: ' + str(e)
41+
print("Results Server (%s) response: %s\n" % (URL, response))
42+
sys.exit(1)
43+
finally:
44+
datasource.close()
45+
46+
# read json result and save to speed.pypy.org
47+
skipped = []
48+
for filename in filelist:
49+
print(f"Reading {filename}...")
50+
f = urlopen(URL + filename)
51+
if f.length < 10:
52+
skipped.append(filename)
53+
continue
54+
result = simplejson.load(f)
55+
f.close()
56+
revision = result['revision']
57+
int_options = ""
58+
options = ""
59+
if 'options' in result:
60+
options = result['options']
61+
62+
host = 'benchmarker'
63+
if revision and len(revision) >10:
64+
branch = result['branch']
65+
if branch in ("default", "main"):
66+
proj = "PyPy"
67+
executable = "pypy-c"
68+
branch = "main"
69+
elif branch == "py3.9":
70+
proj = "PyPy3.9"
71+
executable = "pypy3.9-64"
72+
elif branch == "py3.10":
73+
proj = "PyPy3.10"
74+
executable = "pypy3.10-64"
75+
elif branch == "py3.11":
76+
proj = "PyPy3.11"
77+
executable = "pypy3.11-64"
78+
else:
79+
skipped.append(filename)
80+
continue
81+
saveresults.save(proj, revision, result['results'], executable,
82+
host, speed_url, branch=branch, changed=True)
83+
saveresults.save(proj, revision, result['results'],
84+
executable.replace('-', '-jit-'),
85+
host, speed_url, branch=branch, changed=False)
86+
else:
87+
savecpython.save('cpython', '100', result['results'], options, 'cpython', host)
88+
print("\nOK")
89+
print("skipped", skipped)

tools/pypy/saveresults.py

Lines changed: 135 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,172 @@
33
# This script saves result data #
44
# It expects the format of unladen swallow's perf.py #
55
#######################################################
6-
import urllib, urllib2
6+
7+
"""
8+
Upload a json file generated by runner.py.
9+
10+
Revision, name and host are required.
11+
12+
Example usage:
13+
14+
$ ./saveresults.py result.json -r '45757:fabe4fc0dc08' -n pypy-c-jit \
15+
-H benchmarker
16+
17+
OR
18+
19+
$ ./saveresults.py result.json -r '45757:fabe4fc0dc08' -n pypy-c-jit-64 \
20+
-H benchmarker
21+
"""
22+
from __future__ import division, print_function
23+
724
from datetime import datetime
25+
import optparse
26+
import sys
27+
import time
28+
try:
29+
import urllib2
30+
from urllib import urlencode
31+
except ImportError:
32+
import urllib.request as urllib2
33+
from urllib.parse import urlencode
34+
import json
35+
import pprint
836

9-
#SPEEDURL = 'http://127.0.0.1:8000/'
10-
SPEEDURL = 'http://speed.pypy.org/'
37+
SPEEDURL = 'http://127.0.0.1:8000/'
38+
# SPEEDURL = 'https://speed.pypy.org/'
1139

12-
def save(project, revision, results, options, executable, environment, testing=False):
40+
def save(project, revision, results, executable, host, url, testing=False,
41+
changed=True, branch='default'):
1342
testparams = []
1443
#Parse data
1544
data = {}
16-
current_date = datetime.today()
45+
error = 0
46+
47+
print("saveresults::save sending from %s to %s" %(host, url))
1748
for b in results:
1849
bench_name = b[0]
1950
res_type = b[1]
2051
results = b[2]
2152
value = 0
2253
if res_type == "SimpleComparisonResult":
23-
value = results['changed_time']
54+
if changed:
55+
value = results['changed_time']
56+
else:
57+
value = results['base_time']
2458
elif res_type == "ComparisonResult":
25-
value = results['avg_changed']
59+
if changed:
60+
value = results['avg_changed']
61+
else:
62+
value = results['avg_base']
63+
elif res_type == "RawResult":
64+
if changed:
65+
value = results["changed_times"]
66+
else:
67+
value = results["base_times"]
68+
if value:
69+
assert len(value) == 1
70+
value = value[0]
2671
else:
2772
print("ERROR: result type unknown " + b[1])
2873
return 1
29-
data = {
74+
data = [{
3075
'commitid': revision,
3176
'project': project,
3277
'executable': executable,
3378
'benchmark': bench_name,
34-
'environment': environment,
79+
'environment': host,
3580
'result_value': value,
36-
}
81+
'branch': branch,
82+
}]
83+
if not value:
84+
print("Ignoring skipped result", data)
85+
continue
3786
if res_type == "ComparisonResult":
38-
data['std_dev'] = results['std_changed']
39-
if testing: testparams.append(data)
40-
else: send(data)
41-
if testing: return testparams
42-
else: return 0
87+
if changed:
88+
data[0]['std_dev'] = results['std_changed']
89+
else:
90+
data[0]['std_dev'] = results['std_base']
91+
if testing:
92+
testparams.append(data)
93+
else:
94+
error |= send(data, url)
4395

44-
def send(data):
96+
if error:
97+
raise IOError("Saving failed. See messages above.")
98+
if testing:
99+
return testparams
100+
else:
101+
return 0
102+
103+
104+
def send(data, url):
45105
#save results
46-
params = urllib.urlencode(data)
106+
params = urlencode({'json': json.dumps(data)}).encode("utf-8")
47107
f = None
48108
response = "None"
49-
info = str(datetime.today()) + ": Saving result for " + data['executable']
50-
info += " revision " + " " + str(data['commitid']) + ", benchmark "
51-
info += data['benchmark']
109+
info = ("%s: Saving result for %s revision %s, benchmark %s" %
110+
(str(datetime.today()), data[0]['executable'],
111+
str(data[0]['commitid']), data[0]['benchmark']))
52112
print(info)
53113
try:
54-
f = urllib2.urlopen(SPEEDURL + 'result/add/', params)
55-
response = f.read()
56-
f.close()
114+
retries = [1, 3, 6, 20]
115+
while True:
116+
try:
117+
print('result/add')
118+
f = urllib2.urlopen(url + 'result/add/json/', params)
119+
print('urlopen')
120+
response = f.read().decode()
121+
print('response')
122+
f.close()
123+
break
124+
except urllib2.URLError:
125+
if not retries:
126+
raise
127+
d = retries.pop(0)
128+
print("retrying in %d seconds..." % d)
129+
time.sleep(d)
57130
except urllib2.URLError as e:
58131
if hasattr(e, 'reason'):
59-
response = '\n We failed to reach a server\n'
132+
response = '\n We failed to save the data\n'
60133
response += ' Reason: ' + str(e.reason)
61134
elif hasattr(e, 'code'):
62-
response = '\n The server couldn\'t fulfill the request\n'
63-
response += ' Error code: ' + str(e)
64-
print("Server (%s) response: %s\n" % (SPEEDURL, response))
135+
response = '\n The server couldn\'t fulfill the request'
136+
if hasattr(e, 'readlines'):
137+
response = "".join([response] + [s.decode() for s in e.readlines()])
138+
print(response)
139+
print('when sending')
140+
pprint.pprint(data)
141+
raise
142+
with open('error.html', 'w') as error_file:
143+
error_file.write(response)
144+
print("Server (%s) response written to error.html" % (url,))
145+
print(' Error code: %s\n' % (e,))
65146
return 1
147+
print("saved correctly!", end='\n\n')
66148
return 0
149+
150+
if __name__ == '__main__':
151+
usage = "Usage: %prog [options] <results.json>"
152+
parser = optparse.OptionParser(usage=usage)
153+
parser.add_option('-b', '--base', action='store_true',
154+
help='take base values instead of modified')
155+
parser.add_option('--host', type=str, default=SPEEDURL,
156+
help="codespeed instance, defaults to '%s'" % SPEEDURL)
157+
parser.add_option('--revision',
158+
help=('for cpython, revision number (100 for cpython 2.6.2, 101 for 2.7.2, '
159+
'110 for cpython3.7.6, 120 for cpython3.11, '
160+
'edit admin interface "Revisions" to add more)\n\n'
161+
'for pypy, use the hash from the json file'),
162+
)
163+
parser.add_option('--branch', help="branch name (main, py3.11)", default='main')
164+
options, args = parser.parse_args(sys.argv)
165+
if options.host[-1] != '/':
166+
raise ValueError("host must end with '/'")
167+
if not options.host.startswith("http"):
168+
raise ValueError("host must start with 'http'")
169+
if len(args) != 2:
170+
print(parser.usage)
171+
sys.exit(1)
172+
results = json.load(open(args[1]))['results']
173+
save('cpython', options, results, 'cpython', 'benchmarker',
174+
testing=False)

0 commit comments

Comments
 (0)