forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo_bench_adapt.py
More file actions
102 lines (87 loc) · 3.5 KB
/
Copy pathgo_bench_adapt.py
File metadata and controls
102 lines (87 loc) · 3.5 KB
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
# 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.
import json
import os
import uuid
import logging
from pathlib import Path
from typing import List
from benchadapt import BenchmarkResult
from benchadapt.adapters import BenchmarkAdapter
from benchadapt.log import log
log.setLevel(logging.DEBUG)
ARROW_ROOT = Path(__file__).parent.parent.parent.resolve()
SCRIPTS_PATH = ARROW_ROOT / "ci" / "scripts"
if os.environ.get("CONBENCH_REF") == "master":
github = {
"repository": os.environ["GITHUB_REPOSITORY"],
"commit": os.environ["GITHUB_SHA"],
"pr_number": None, # implying default branch
}
run_reason = "commit"
else:
github = None # scrape github info from the local repo
run_reason = "branch"
class GoAdapter(BenchmarkAdapter):
result_file = "bench_stats.json"
command = ["bash", SCRIPTS_PATH / "go_bench.sh", ARROW_ROOT, "-json"]
def __init__(self, *args, **kwargs) -> None:
super().__init__(command=self.command, *args, **kwargs)
def _transform_results(self) -> List[BenchmarkResult]:
with open(self.result_file, "r") as f:
raw_results = json.load(f)
run_id = uuid.uuid4().hex
parsed_results = []
for suite in raw_results[0]["Suites"]:
batch_id = uuid.uuid4().hex
pkg = suite["Pkg"]
for benchmark in suite["Benchmarks"]:
data = benchmark["Mem"]["MBPerSec"] * 1e6
time = 1 / benchmark["NsPerOp"] * 1e9
name = benchmark["Name"].removeprefix('Benchmark')
ncpu = name[name.rfind('-')+1:]
pieces = name[:-(len(ncpu)+1)].split('/')
parsed = BenchmarkResult(
run_id=run_id,
batch_id=batch_id,
stats={
"data": [data],
"unit": "b/s",
"times": [time],
"time_unit": "i/s",
"iterations": benchmark["Runs"],
},
context={
"benchmark_language": "Go",
"goos": suite["Goos"],
"goarch": suite["Goarch"],
},
tags={
"pkg": pkg,
"num_cpu": ncpu,
"name": pieces[0],
"params": '/'.join(pieces[1:]),
},
run_reason=run_reason,
github=github,
)
parsed.run_name = f"{parsed.run_reason}: {parsed.github['commit']}"
parsed_results.append(parsed)
return parsed_results
if __name__ == "__main__":
go_adapter = GoAdapter(result_fields_override={"info":{}})
go_adapter()