Skip to content

Commit 840b5d3

Browse files
committed
Add CLI options for exporting and printing FIO Report
Signed-off-by: Colin Wilk <[email protected]>
1 parent 17a3e8c commit 840b5d3

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

src/benchmarking_tool/fio.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ def export_json(self, path: str) -> Self:
239239
json.dump(self.result, f)
240240
return self
241241

242+
def get_json(self) -> str:
243+
"""
244+
Export the FIO result as a JSON string.
245+
246+
Returns:
247+
str: JSON string of the report
248+
"""
249+
return json.dumps(self.result)
250+
242251

243252
class FioConfig:
244253
"""

src/benchmarking_tool/main.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
)
6666
subparsers = parser.add_subparsers(dest="role", help="Role of the execution")
6767

68+
################################################################################
69+
# Run Parameters
70+
################################################################################
6871
parser_run: argparse.ArgumentParser = subparsers.add_parser(
6972
"run", help="Single run options"
7073
)
@@ -83,7 +86,20 @@
8386
required=False,
8487
default=None,
8588
)
89+
parser_run.add_argument(
90+
"--print-report", help="Prints the report JSON to stdout", action="store_true"
91+
)
92+
parser_run.add_argument(
93+
"--export",
94+
help="Export the report JSON to a file",
95+
type=str,
96+
required=False,
97+
default="",
98+
)
8699

100+
################################################################################
101+
# Worker Parameters
102+
################################################################################
87103
parser_worker: argparse.ArgumentParser = subparsers.add_parser(
88104
"worker", help="Worker node options"
89105
)
@@ -101,6 +117,9 @@
101117
type=str,
102118
)
103119

120+
################################################################################
121+
# Coordinator Parameters
122+
################################################################################
104123
parser_coordinator: argparse.ArgumentParser = subparsers.add_parser(
105124
"coordinator", help="Coordinator node options"
106125
)
@@ -127,18 +146,21 @@
127146
parser.print_help()
128147

129148
if args.role == "run":
130-
# TODO: Give option to specify config files
131149
fio = Fio()
132-
config = args.config if args.config is not None else "job_files/default.ini"
133-
config = FioConfig(config)
134-
config.print_job_runtime()
135-
res: FioResult = fio.run(config, args.directory)
136-
res.print_table()
150+
config_str: str = args.config or "job_files/default.ini"
151+
config: FioConfig = FioConfig(config_str).print_job_runtime()
152+
res: FioResult = fio.run(config, args.directory).print_table()
153+
if args.print_report:
154+
print(res.get_json())
155+
if args.export != "":
156+
res.export_json(args.export)
137157

138158
if args.role == "worker":
139159
if args.hostname is None:
140160
args.hostname = hostname
141161
worker.register_worker(args.group, args.hostname).start_worker()
142162

143163
if args.role == "coordinator":
144-
Coordinator().set_worker_groups(args.groups).set_filename(args.filename).run()
164+
Coordinator().set_worker_groups(args.groups).set_filename(
165+
args.filename
166+
).trigger_benchmark()

0 commit comments

Comments
 (0)