-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
338 additions
and
25 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,91 @@ | ||
from typing import List | ||
Check failure on line 1 in benchmark.py GitHub Actions / build (3.8)Ruff (F401)
Check failure on line 1 in benchmark.py GitHub Actions / build (3.10)Ruff (F401)
|
||
|
||
import matplotlib.pyplot as plt | ||
import argparse | ||
from github_client import GithubClient | ||
from results_parser import parse | ||
from single_file_cache import SingleFileCache | ||
from utilities import get_dates_between, convert_to_plot | ||
from datetime import datetime | ||
from collections import defaultdict | ||
|
||
COMMIT_CACHE_FILE = 'cache/benchmark-date-commit-cache.json' | ||
REPORT_CACHE_FILE = 'cache/benchmark-report-cache.json' | ||
|
||
|
||
class BenchmarkApp: | ||
def __init__(self, file_path: str): | ||
self.client = GithubClient() | ||
self.commit_cache = SingleFileCache(location=COMMIT_CACHE_FILE) | ||
self.report_cache = SingleFileCache(location=REPORT_CACHE_FILE) | ||
self.file_path = file_path | ||
|
||
def get_commit_by_date(self, repository, date): | ||
find_commit = self.commit_cache.retrieve_value(date) | ||
if not find_commit: | ||
find_commit = self.client.get_most_recent_commit(repository, date, "gh-pages") | ||
if find_commit: | ||
self.commit_cache.add_to_cache(date, find_commit) | ||
|
||
return find_commit | ||
|
||
def get_report_by_commit(self, repository, commit): | ||
repo_data = self.report_cache.retrieve_value(commit) | ||
|
||
if not repo_data: | ||
repo_data = self.client.get_file_at_commit(repository=repository, filepath=self.file_path, commit_sha=commit) | ||
self.report_cache.add_to_cache(commit, repo_data) | ||
|
||
return repo_data | ||
|
||
|
||
def main(args): | ||
file_path = "benchmark-overhead/results/release/summary.txt" | ||
|
||
metrics = [ | ||
"Min heap used (MB)", | ||
"Max heap used (MB)" | ||
] | ||
|
||
timeframe = get_dates_between(args.start, datetime.now().date(), args.interval) | ||
result = defaultdict(dict) | ||
|
||
app = BenchmarkApp(file_path=file_path) | ||
|
||
for snapshot in timeframe: | ||
commit = app.get_commit_by_date(date=snapshot, repository=args.repo) | ||
|
||
report = app.get_report_by_commit(repository=args.repo, commit=commit) | ||
parsed = parse(report, metrics) | ||
if parsed: | ||
result[snapshot]["date"] = snapshot | ||
for metric in metrics: | ||
result[snapshot][metric] = parsed.metrics[metric] | ||
|
||
dates, metric_values = convert_to_plot(result, metrics) | ||
|
||
for metric, values in metric_values.items(): | ||
plt.plot(dates, values, label=metric) | ||
|
||
plt.xlabel('Date') | ||
plt.ylabel('MB') | ||
plt.title('Benchmark Metrics') | ||
plt.xticks(rotation=45) | ||
plt.legend() | ||
plt.tight_layout() | ||
plt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Benchmark Tracker') | ||
parser.add_argument("-r", "--repo", | ||
help="Repository name. " | ||
"ex: open-telemetry/opentelemetry-java-instrumentation", | ||
required=True) | ||
parser.add_argument("-s", "--start", | ||
help="Starting Date (will calculate from this date until now)", | ||
required=True) | ||
parser.add_argument("-i", "--interval", | ||
help="Interval (in days) between data points", required=True) | ||
arguments = parser.parse_args() | ||
main(arguments) |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,46 @@ | ||
from datetime import datetime | ||
from typing import List | ||
|
||
|
||
class ReportMetrics: | ||
def __init__(self, date: str): | ||
self.date = date | ||
self.metrics = {} | ||
|
||
|
||
def parse(report: str, metrics: List[str]) -> ReportMetrics: | ||
if report is None: | ||
return None | ||
|
||
split = report.split("----------------------------------------------------------\n") | ||
|
||
metrics_split = split[2].split("\n") | ||
date = convert_to_desired_format(split[1].split("Run at ")[1].split("\n")[0]) | ||
|
||
report_metrics = ReportMetrics(date=date) | ||
|
||
try: | ||
for line in metrics_split: | ||
for metric in metrics: | ||
|
||
if line.startswith(metric): | ||
values = line.split(":") | ||
report_metrics.metrics[metric] = float(values[1].split()[1]) | ||
except IndexError: | ||
return None | ||
|
||
return report_metrics | ||
|
||
|
||
def convert_to_desired_format(date_str): | ||
# Define the input and output date formats | ||
input_format = "%a %b %d %H:%M:%S UTC %Y" | ||
output_format = "%Y-%m-%d" | ||
|
||
try: | ||
parsed_date = datetime.strptime(date_str, input_format) | ||
formatted_date = parsed_date.strftime(output_format) | ||
return formatted_date | ||
except ValueError: | ||
print("Invalid date format") | ||
return None |
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,25 @@ | ||
import unittest | ||
|
||
from results_parser import parse | ||
|
||
|
||
class ResultsParserTestCase(unittest.TestCase): | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.example = """----------------------------------------------------------\n Run at Sat Sep 23 05:22:19 UTC 2023\n release : compares no agent, latest stable, and latest snapshot agents\n 5 users, 5000 iterations\n----------------------------------------------------------\nAgent : none latest snapshot\nRun duration : 00:02:27 00:02:57 00:03:06\nAvg. CPU (user) % : 0.46024063 0.48809186 0.49900937\nMax. CPU (user) % : 0.5527638 0.5891089 0.6\nAvg. mch tot cpu % : 0.9943353 0.99306744 0.9932704\nStartup time (ms) : 19598 16351 17050\nTotal allocated MB : 27799.50 34195.20 58039.97\nMin heap used (MB) : 88.10 115.85 112.63\nMax heap used (MB) : 365.90 557.00 478.78\nThread switch rate : 28534.94 29848.291 32354.986\nGC time (ms) : 1800 3014 2928\nGC pause time (ms) : 1814 3052 2959\nReq. mean (ms) : 10.74 12.82 13.51\nReq. p95 (ms) : 32.04 38.45 40.28\nIter. mean (ms) : 144.60 173.90 182.65\nIter. p95 (ms) : 233.74 275.94 291.89\nNet read avg (bps) : 5441971.00 4728712.00 4507975.00\nNet write avg (bps) : 7256048.00 25533599.00 24434992.00\nPeak threads : 43 55 56\n""" | ||
self.metrics = [ | ||
"Min heap used (MB)", | ||
"Max heap used (MB)" | ||
] | ||
super(ResultsParserTestCase, self).__init__(*args, **kwargs) | ||
|
||
def test_parse_metrics_from_summary(self): | ||
result = parse(report=self.example, metrics=self.metrics) | ||
self.assertEqual(557.00, result.metrics["Max heap used (MB)"]) | ||
self.assertEqual(115.85, result.metrics["Min heap used (MB)"]) | ||
|
||
def test_parse_date_from_summary(self): | ||
result = parse(report=self.example, metrics=self.metrics) | ||
self.assertEqual("2023-09-23", result.date) | ||
|
||
|
Oops, something went wrong.