-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
182 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import json | ||
|
||
# load json data from benchmark_results.json | ||
with open("benchmark_results.json", "r") as file: | ||
data = json.load(file) | ||
|
||
|
||
# Function to generate an HTML table from a dictionary | ||
def generate_table_from_dict(data_dict, title=None): | ||
html = f"<h2>{title}</h2>" if title else "" | ||
html += "<table class='info-table'>" | ||
for key, value in data_dict.items(): | ||
html += "<tr>" | ||
html += f"<td class='key-cell'><strong>{key}</strong></td>" | ||
if isinstance(value, list): | ||
html += "<td><table class='inner-table'>" | ||
for item in value: | ||
html += "<tr>" | ||
if isinstance(item, dict): | ||
for k, v in item.items(): | ||
html += f"<td>{k}: {v}</td>" | ||
else: | ||
html += f"<td>{item}</td>" | ||
html += "</tr>" | ||
html += "</table></td>" | ||
else: | ||
html += f"<td>{value}</td>" | ||
html += "</tr>" | ||
html += "</table>" | ||
return html | ||
|
||
# Function to generate an HTML table for benchmarks | ||
def generate_benchmarks_table(benchmarks): | ||
if not benchmarks: | ||
return "" | ||
|
||
# Headers to be removed | ||
headers_to_remove = ['family_index', 'per_family_instance_index', 'run_name', 'run_type', 'repetitions', 'repetition_index', 'threads', 'time_unit'] | ||
|
||
html = "<h2>Benchmarks</h2>" | ||
html += "<table class='benchmark-table'><tr>" | ||
html += "<th>Index</th>" | ||
|
||
# Add headers | ||
for key in benchmarks[0].keys(): | ||
if key not in headers_to_remove: | ||
new_key = key | ||
if key == 'name': | ||
new_key = 'Benchmark' | ||
elif key == 'real_time': | ||
new_key = 'Real Time (us)' | ||
elif key == 'cpu_time': | ||
new_key = 'CPU Time (us)' | ||
html += f"<th>{new_key}</th>" | ||
|
||
html += "</tr>" | ||
|
||
# Add rows | ||
for benchmark in benchmarks: | ||
html += "<tr>" | ||
# Add index | ||
html += f"<td>{benchmark['family_index']+1}</td>" | ||
for key, value in benchmark.items(): | ||
if key not in headers_to_remove: | ||
if key == 'name': | ||
value = value.replace('OASValidatorPerf/', '').split('/min_time')[0] | ||
elif key in ['real_time', 'cpu_time']: | ||
value = f"{value:.3f}" | ||
html += f"<td>{value}</td>" | ||
html += "</tr>" | ||
|
||
html += "</table>" | ||
return html | ||
|
||
# Main function to generate the complete HTML page | ||
def generate_html(data): | ||
html = """ | ||
<html> | ||
<head> | ||
<title>Benchmark Report</title> | ||
<style> | ||
body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f4f4f4; color: #333; } | ||
.container { width: 80%; margin: 20px auto; } | ||
h1 { text-align: center; } | ||
.info-table, .benchmark-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } | ||
.info-table td, .benchmark-table th, .benchmark-table td { border: 1px solid #ddd; padding: 8px; text-align: left; } | ||
.info-table .key-cell { width: 20%; font-weight: bold; } | ||
.inner-table { width: 100%; margin-top: 5px; } | ||
.inner-table td { border: none; padding: 4px; font-size: 0.9em; } | ||
.benchmark-table th { background-color: #4CAF50; color: white; } | ||
tr:nth-child(even) { background-color: #f2f2f2; } | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Benchmark Report</h1> | ||
""" + generate_table_from_dict(data["context"], "Context") + generate_benchmarks_table(data["benchmarks"]) + """ | ||
</div> | ||
</body> | ||
</html> | ||
""" | ||
return html | ||
|
||
# Generate HTML page | ||
html_page = generate_html(data) | ||
|
||
# Save the HTML to a file | ||
with open("benchmark_report.html", "w") as file: | ||
file.write(html_page) | ||
|
||
print("HTML page generated and saved as benchmark_report.html") |
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,51 @@ | ||
name: Benchmark | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
benchmark: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
submodules: 'recursive' | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y gcc g++ cmake lcov gcovr | ||
sudo apt-get install -y libgtest-dev | ||
sudo apt install -y libbenchmark-dev | ||
cd /usr/src/gtest | ||
sudo cmake CMakeLists.txt | ||
sudo make | ||
sudo cp ./lib/libgtest*.a /usr/lib | ||
- name: Configure CMake | ||
run: cmake -S . -B build -DBUILD_PERF=ON | ||
|
||
- name: Build | ||
run: cmake --build build --config Release | ||
|
||
- name: Run benchmark | ||
run: | | ||
cd build/test/perftest | ||
./cpp-oasvalidator-perftests > --benchmark_out=benchmark_result.json --benchmark_format=json > benchmark_result.json | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Generate HTML Page | ||
run: python .github/workflows/convert_json_to_html.py | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./build/test/perftest/benchmark_report.html |
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
branches: [ main ] | ||
|
||
jobs: | ||
build-and-test: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
branches: [ main ] | ||
|
||
jobs: | ||
build-and-test: | ||
code-coverage: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
branches: [ main ] | ||
|
||
jobs: | ||
build-and-test: | ||
unittest: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
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