-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathperformance-to-markdown.py
More file actions
executable file
·88 lines (68 loc) · 3.07 KB
/
performance-to-markdown.py
File metadata and controls
executable file
·88 lines (68 loc) · 3.07 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
#!/usr/bin/env python3
import json
import sys
import os
import glob
def load_all_summaries(json_files):
"""Load summaries from all JSON files and group by test name"""
summaries_by_name = {}
for json_file in json_files:
try:
with open(json_file, 'r') as f:
data = json.load(f)
if 'summaries' in data and data['summaries']:
for summary in data['summaries']:
name = summary.get('name', 'Unknown Test')
if name not in summaries_by_name:
summaries_by_name[name] = []
summaries_by_name[name].append(summary)
except (FileNotFoundError, json.JSONDecodeError) as e:
print(f"Warning: Error processing {json_file}: {e}", file=sys.stderr)
continue
return summaries_by_name
def convert_to_markdown(json_files):
"""Convert performance test JSON results to markdown format"""
summaries_by_name = load_all_summaries(json_files)
if not summaries_by_name:
return "## Performance Test Results\n\nNo performance test results found."
markdown = "## Performance Test Results\n\n"
# Create a table for each test name
for name, summaries in sorted(summaries_by_name.items()):
markdown += f"### {name}\n\n"
markdown += "| Duration (ms) | Max Memory (GB) | Processors | Parameters |\n"
markdown += "|---------------|-----------------|------------|------------|\n"
for summary in summaries:
duration = summary.get('duration', 0)
processors = summary.get('numberOfProcessors', 0)
max_memory = summary.get('maxMemory', 0)
# Convert memory from bytes to GB
max_memory_gb = max_memory / (1024 ** 3) if max_memory > 0 else 0
# Extract dynamic properties (excluding standard fields)
standard_fields = {'name', 'duration', 'numberOfProcessors', 'maxMemory'}
params = []
for key, value in summary.items():
if key not in standard_fields:
params.append(f"{key}={value}")
params_str = ", ".join(params) if params else "-"
markdown += f"| {duration} | {max_memory_gb:.2f} | {processors} | {params_str} |\n"
markdown += "\n"
return markdown
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: performance-to-markdown.py <json_file> [json_file2 ...]")
print(" or: performance-to-markdown.py <glob_pattern>")
sys.exit(1)
# Collect all JSON files from arguments (supporting both direct files and glob patterns)
json_files = []
for arg in sys.argv[1:]:
if '*' in arg:
json_files.extend(glob.glob(arg, recursive=True))
else:
json_files.append(arg)
# Filter to only existing files
json_files = [f for f in json_files if os.path.isfile(f)]
if not json_files:
print("## Performance Test Results\n\nNo performance test results found.")
sys.exit(0)
markdown = convert_to_markdown(json_files)
print(markdown)