Skip to content

Commit 6f57d12

Browse files
authored
Explicitly pass out_file to benchcomp visualizers (rust-lang#2408)
This commit adds an `out_file` to the benchcomp visualizes that emit output (currently just one visualization, dump_yaml). This is to allow different visualizations to be written to different output files, including stdout. The intention (for a future commit) is that CI will save certain visualizations as artifacts, which users can then download.
1 parent f80a8ab commit 6f57d12

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

tools/benchcomp/benchcomp/visualizers/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import yaml
88

9+
import benchcomp
910
import benchcomp.visualizers.utils as viz_utils
1011

1112

@@ -54,15 +55,24 @@ def __call__(self, results):
5455

5556

5657

57-
@dataclasses.dataclass
5858
class dump_yaml:
59-
"""Print the YAML-formatted results to stdout
59+
"""Print the YAML-formatted results to a file.
60+
61+
The 'out_file' key is mandatory; specify '-' to print to stdout.
6062
6163
Sample configuration:
6264
6365
visualize:
6466
- type: dump_yaml
67+
out_file: '-'
6568
"""
6669

70+
71+
def __init__(self, out_file):
72+
self.get_out_file = benchcomp.Outfile(out_file)
73+
74+
6775
def __call__(self, results):
68-
print(yaml.dump(results, default_flow_style=False))
76+
with self.get_out_file() as handle:
77+
print(
78+
yaml.dump(results, default_flow_style=False), file=handle)

tools/benchcomp/configs/perf-regression.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ run:
2929

3030
visualize:
3131
- type: dump_yaml
32+
out_file: '/tmp/result.yaml'
3233

3334
- type: error_on_regression
3435
variant_pairs: [[kani_old, kani_new]]

tools/benchcomp/test/test_regression.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def _run_kani_perf_test(self, command, expected_pass):
9595
}
9696
}
9797
},
98-
"visualize": [{"type": "dump_yaml"}],
98+
"visualize": [{
99+
"type": "dump_yaml",
100+
"out_file": "-"
101+
}],
99102
})
100103
run_bc()
101104
self.assertEqual(run_bc.proc.returncode, 0, msg=run_bc.stderr)
@@ -423,6 +426,7 @@ def test_only_dump_yaml(self):
423426
},
424427
"visualize": [{
425428
"type": "dump_yaml",
429+
"out_file": "-",
426430
}, {
427431
"type": "error_on_regression",
428432
"variant_pairs": [["passed", "failed"]],
@@ -471,6 +475,7 @@ def test_ignore_dump_yaml(self):
471475
},
472476
"visualize": [{
473477
"type": "dump_yaml",
478+
"out_file": "-",
474479
}],
475480
})
476481
run_bc(flags=["--except", "dump_yaml"])

0 commit comments

Comments
 (0)