-
Notifications
You must be signed in to change notification settings - Fork 24
/
analyze-clusterbuster-report
executable file
·87 lines (78 loc) · 3.6 KB
/
analyze-clusterbuster-report
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
#!/usr/bin/env python3
# Copyright 2022 Robert Krawitz/Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import argparse
import json
import os
from lib.clusterbuster.reporting.analysis.ClusterBusterAnalysis import ClusterBusterAnalysis
from lib.clusterbuster.reporting.loader.ClusterBusterLoader import ClusterBusterLoader
from lib.clusterbuster.reporting.reporting_exceptions import ClusterBusterReportingException
if 'CB_LIBPATH' in os.environ:
sys.path = [element for element in os.environ['CB_LIBPATH'].split(':')] + sys.path
parser = argparse.ArgumentParser(description='Analyze ClusterBuster report')
analysis_formats = ClusterBusterAnalysis.list_analysis_formats()
parser.add_argument("-o", "--outfile", default=None, type=str, metavar='file', help='Output filename')
parser.add_argument('--list_formats', action='store_true', help='List available report formats')
parser.add_argument('--std_report', '--std-report', '--std', action='store_true',
help='Compare results for standard runtime classes')
parser.add_argument('--kata', action='store_true', help='Compare results for standard runtime classes')
parser.add_argument("-r", "--report-type", default=None, type=str, metavar='format',
choices=analysis_formats, help=f'Analysis format: one of {", ".join(analysis_formats)}')
parser.add_argument("-w", "--workload", type=str, help='Workloads to process', action='append')
parser.add_argument("files", metavar='file', type=str, nargs='+', help='Files to process')
args, extras = parser.parse_known_args()
if args.list_formats:
print('\n'.join(sorted(analysis_formats)))
sys.exit(1)
def analyze_clusterbuster_1(f, data, extras=None):
try:
report = ClusterBusterAnalysis(data, args.report_type, extras).Analyze()
if report is None:
print("No report available", file=sys.stderr)
sys.exit(1)
elif isinstance(report, str):
print(report, file=f)
else:
json.dump(report, fp=f, indent=2)
except (KeyboardInterrupt, BrokenPipeError):
sys.exit()
except ClusterBusterReportingException as exc:
print(f"Report failed: {exc}")
def analyze_clusterbuster(f):
dir_args = []
if args.std_report or args.kata:
for arg in args.files:
dir_args.append(f'{arg}:job_pattern=-runc-:name_suffix=runc')
dir_args.append(f'{arg}:job_pattern=-kata-:name_suffix=kata')
if not args.kata:
dir_args.append(f'{arg}:job_pattern=-vm-:name_suffix=vm')
else:
dir_args = args.files
if args.workload:
dir_args = [f'{f}:job_pattern=^({"|".join(args.workload)})-' for f in dir_args]
try:
analyze_clusterbuster_1(f, ClusterBusterLoader(extras).loadFromSpecs(dir_args), extras)
except ClusterBusterReportingException as exc:
print(f"Report failed: {exc}")
try:
if args.outfile and args.outfile != '-':
with open(args.outfile, 'w') as f:
analyze_clusterbuster(f)
else:
analyze_clusterbuster(sys.stdout)
except KeyboardInterrupt:
sys.exit(1)
except BrokenPipeError:
sys.exit(1)