forked from apache/flink-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_jmh_result.py
executable file
·116 lines (103 loc) · 4.32 KB
/
save_jmh_result.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
####################################################
# Sample script that shows how to save result data #
####################################################
import datetime
import os
import urllib
import urllib2
import argparse
import csv
import json
import random
# You need to enter the real URL and have the server running
DEFAULT_CODESPEED_URL = 'http://localhost:8000/'
current_date = datetime.datetime.today()
parser = argparse.ArgumentParser(description='Upload jmh benchmark csv results')
parser.add_argument('--commit', dest='commit', required=True,
help='md5')
parser.add_argument('--branch', dest='branch', required=True)
parser.add_argument('--input', dest='input', required=False,
help='input csv file')
parser.add_argument('--environment', dest='environment', required=True)
parser.add_argument('--dry', dest='dry', action='store_true')
parser.add_argument('--codespeed', dest='codespeed', default=DEFAULT_CODESPEED_URL,
help='codespeed url, default: %s' % DEFAULT_CODESPEED_URL)
parser.add_argument('--project', dest='project', default="Flink")
parser.add_argument('--exec', dest='executable', default="Flink")
def readData(args):
results = []
if args.input:
path = args.input
else:
path = "jmh-result.csv"
modificationDate = datetime.datetime.fromtimestamp(os.path.getmtime(path))
#modificationDate = datetime.date(2016, 8, int(args.commit))
with open(path) as csvFile:
reader = csv.reader(csvFile, delimiter=",")
lines = [line for line in reader]
header = lines[0]
params = sorted(filter(lambda s : s.startswith("Param"), header))
paramIndexes = map(lambda param : header.index(param), params)
benchmarkIndex = header.index("Benchmark")
scoreIndex = header.index("Score")
errorIndex = scoreIndex + 1
for line in lines[1:]:
name = line[benchmarkIndex].split(".")[-1]
if len(paramIndexes) > 0:
for paramIndex in paramIndexes:
if len(line[paramIndex]) > 0:
name += "." + line[paramIndex]
results.append({
'commitid': args.commit,
'branch': args.branch,
'project': args.project,
'executable': args.executable,
'benchmark': name,
'environment': args.environment,
'lessisbetter': False,
'units': 'records/ms',
'result_value': float(line[scoreIndex]),
'revision_date': str(modificationDate),
'result_date': str(modificationDate),
'std_dev': line[errorIndex], # Optional. Default is blank
})
return results
def add(data, codespeedUrl):
#params = urllib.urlencode(data)
response = "None"
try:
f = urllib2.urlopen(
codespeedUrl + 'result/add/json/', urllib.urlencode(data))
except urllib2.HTTPError as e:
print str(e)
print e.read()
return
response = f.read()
f.close()
print "Server (%s) response: %s\n" % (codespeedUrl, response)
if __name__ == "__main__":
args = parser.parse_args()
data = json.dumps(readData(args), indent=4, sort_keys=True)
if args.dry:
print data
else:
add({'json': data}, args.codespeed)