-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to process multiple benchmark files? #69
Comments
@esigo Does this create a single benchmark file which is to be uploaded? |
I ended up writing a python script to join the files to avoid docker in docker. #!/usr/bin/python3
import json
import os
build_dir = os.getcwd() + "/../../build"
result_files = []
search_path = build_dir + "/tesseract_collision/test/benchmarks"
for file in os.listdir(search_path):
if file.endswith(".json"):
result_files.append(os.path.join(search_path, file))
search_path = build_dir + "/tesseract_environment/test/benchmarks"
for file in os.listdir(search_path):
if file.endswith(".json"):
result_files.append(os.path.join(search_path, file))
cnt = 0
all_data = {}
for file in result_files:
# Opening JSON file
f = open(file, "r")
# returns JSON object as a dictionary
data = json.loads(f.read())
if cnt == 0:
all_data = data
else:
for benchmark in data["benchmarks"]:
all_data["benchmarks"].append(benchmark)
# endfor
# endif
# Closing file
f.close()
# Increment counter
cnt+=1
# endfor
# the base path to where the output must be stored
if not os.path.exists("/root/benchmarks"):
os.makedirs("/root/benchmarks")
# endif
# the json file where the output must be stored
out_file = open("/root/benchmarks/tesseract-benchmark_result.json", "w+")
json.dump(all_data, out_file, indent = 4)
out_file.close() |
Thanks for the script @Levi-Armstrong , although it would be nice if the github action supported this natively. |
Is there a blocker that is preventing this action from taking a list of files versus just a single file? |
Whilst it'd be nice to have this baked in, here's some C# code to combine benchmark results. Not as pretty as @Levi-Armstrong's python solution, but seems to do the job if you work in dotnet 6+. public static void CombineBenchmarkResults(
string resultsDir = "./BenchmarkDotNet.Artifacts/results",
string resultsFile = "Combined.Benchmarks",
string searchPattern = "Foo.*.json")
{
var resultsPath = Path.Combine(resultsDir, resultsFile + ".json");
if (!Directory.Exists(resultsDir))
{
throw new DirectoryNotFoundException($"Directory not found '{resultsDir}'");
}
if (File.Exists(resultsPath))
{
File.Delete(resultsPath);
}
var reports = Directory
.GetFiles(resultsDir, searchPattern, SearchOption.TopDirectoryOnly)
.ToArray();
if (!reports.Any())
{
throw new FileNotFoundException($"Reports not found '{searchPattern}'");
}
var combinedReport = JsonNode.Parse(File.ReadAllText(reports.First()))!;
var title = combinedReport["Title"]!;
var benchmarks = combinedReport["Benchmarks"]!.AsArray();
// Rename title whilst keeping original timestamp
combinedReport["Title"] = $"{resultsFile}{title.GetValue<string>()[^16..]}";
foreach (var report in reports.Skip(1))
{
var array = JsonNode.Parse(File.ReadAllText(report))!["Benchmarks"]!.AsArray();
foreach (var benchmark in array)
{
// Double parse avoids "The node already has a parent" exception
benchmarks.Add(JsonNode.Parse(benchmark!.ToJsonString())!);
}
}
File.WriteAllText(resultsPath, combinedReport.ToString());
} |
I have tried the GitHub action layout below but get the following error.
The text was updated successfully, but these errors were encountered: