-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): save benchmark results (#395)
- Loading branch information
1 parent
19e533c
commit 82a2418
Showing
9 changed files
with
438 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import os | ||
import json | ||
import plotly.express as px | ||
from dash import Dash, html, dcc, callback, Output, Input | ||
|
||
cached_timestamp = None | ||
cached_layout = None | ||
path = "results/metrics/" | ||
|
||
def server_layout(): | ||
layout = [ | ||
html.H1(children='Sig: Benchmarks', style={'textAlign':'center'}), | ||
] | ||
|
||
# hash all the files together | ||
latest_timestamp = 0 | ||
for file_path in os.listdir(path): | ||
# results/metrics/output-$git_commit-$timestamp.json | ||
# parse file name | ||
timestamp = int(file_path.split("-")[2].split(".")[0]) | ||
latest_timestamp = max(latest_timestamp, timestamp) | ||
|
||
if latest_timestamp == cached_timestamp: | ||
return cached_layout | ||
|
||
# for each file in the directory | ||
all_metrics = {} | ||
for file_path in os.listdir(path): | ||
# results/metrics/output-$git_commit-$timestamp.json | ||
# parse file_path name | ||
commit = file_path.split("-")[1] | ||
timestamp = file_path.split("-")[2].split(".")[0] | ||
|
||
commit_metrics = json.load(open(path + file_path)) | ||
for metric in commit_metrics: | ||
metric["timestamp"] = timestamp | ||
metric["commit"] = commit | ||
key = metric["name"] | ||
if key in all_metrics: | ||
all_metrics[key].append(metric) | ||
else: | ||
all_metrics[key] = [metric] | ||
|
||
for key in all_metrics: | ||
data = all_metrics[key] | ||
if len(data) == 0: continue | ||
title = data[0]["name"] | ||
fig = px.line( | ||
x=[d['timestamp'] for d in data], | ||
y=[d['value'] for d in data], | ||
title=title, | ||
hover_data={"commit": [d['commit'] for d in data]}, | ||
markers=True, | ||
) | ||
fig.update_layout( | ||
xaxis_title="Timestamp", | ||
yaxis_title=data[0]["unit"], | ||
) | ||
layout.append(dcc.Graph(figure=fig)) | ||
|
||
cached_layout = layout | ||
return layout | ||
|
||
|
||
app = Dash() | ||
# re-runs on each page refresh | ||
app.layout = server_layout | ||
|
||
if __name__ == '__main__': | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
|
||
app.run(debug=True, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# pull the latest changes | ||
git pull | ||
|
||
git_commit=$(git rev-parse HEAD) | ||
timestamp=$(date +%s) | ||
result_dir="results/metrics" | ||
result_file="${result_dir}/output-${git_commit}-*.json" | ||
|
||
if ls $result_file 1> /dev/null 2>&1; then | ||
echo "Results for commit $git_commit already exist. Skipping benchmark." | ||
else | ||
# Run the benchmark only if the result file doesn't exist | ||
zig build -Doptimize=ReleaseSafe -Dno-run benchmark | ||
./zig-out/bin/benchmark --metrics all | ||
|
||
mkdir -p "$result_dir" | ||
mv results/output.json "${result_dir}/output-${git_commit}-${timestamp}.json" | ||
echo "Benchmark results saved to ${result_dir}/output-${git_commit}-${timestamp}.json" | ||
fi |
Oops, something went wrong.