1
+ mod benchmark;
2
+
1
3
use crate :: benchmark:: profile:: Profile ;
2
4
use crate :: toolchain:: { get_local_toolchain, LocalToolchain } ;
3
- use benchlib:: benchmark:: passes_filter;
4
5
use benchlib:: comm:: messages:: BenchmarkMessage ;
5
- use cargo_metadata:: Message ;
6
6
use std:: io:: { BufRead , BufReader } ;
7
7
use std:: path:: { Path , PathBuf } ;
8
8
use std:: process:: { Command , Stdio } ;
9
9
10
- #[ derive( Debug ) ]
11
- struct BenchmarkBinary {
12
- path : PathBuf ,
13
- benchmark_names : Vec < String > ,
14
- }
15
-
16
- impl BenchmarkBinary {
17
- fn name ( & self ) -> & str {
18
- self . path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( )
19
- }
20
- }
21
-
22
- #[ derive( Debug ) ]
23
- struct BenchmarkDatabase {
24
- binaries : Vec < BenchmarkBinary > ,
25
- }
26
-
27
- impl BenchmarkDatabase {
28
- fn benchmark_names ( & self ) -> impl Iterator < Item = & str > {
29
- self . binaries
30
- . iter ( )
31
- . flat_map ( |binary| binary. benchmark_names . iter ( ) . map ( |n| n. as_ref ( ) ) )
32
- }
33
-
34
- fn total_benchmark_count ( & self ) -> u64 {
35
- self . benchmark_names ( ) . count ( ) as u64
36
- }
37
- fn filtered_benchmark_count ( & self , filter : & BenchmarkFilter ) -> u64 {
38
- self . benchmark_names ( )
39
- . filter ( |benchmark| {
40
- passes_filter (
41
- & benchmark,
42
- filter. exclude . as_deref ( ) ,
43
- filter. include . as_deref ( ) ,
44
- )
45
- } )
46
- . count ( ) as u64
47
- }
48
- }
49
-
50
- pub struct BenchmarkFilter {
51
- exclude : Option < String > ,
52
- include : Option < String > ,
53
- }
54
-
55
- impl BenchmarkFilter {
56
- pub fn new ( exclude : Option < String > , include : Option < String > ) -> BenchmarkFilter {
57
- Self { exclude, include }
58
- }
59
- }
10
+ pub use benchmark:: BenchmarkFilter ;
60
11
61
12
/// Perform a series of runtime benchmarks using the provided `rustc` compiler.
62
13
/// The runtime benchmarks are looked up in `benchmark_dir`, which is expected to be a path
@@ -70,7 +21,7 @@ pub fn bench_runtime(
70
21
) -> anyhow:: Result < ( ) > {
71
22
let toolchain = get_local_toolchain ( & [ Profile :: Opt ] , rustc, None , None , id, "" ) ?;
72
23
let output = compile_runtime_benchmarks ( & toolchain, & benchmark_dir) ?;
73
- let benchmark_db = discover_benchmarks ( & output) ?;
24
+ let benchmark_db = benchmark :: discover_benchmarks ( & output) ?;
74
25
75
26
let total_benchmark_count = benchmark_db. total_benchmark_count ( ) ;
76
27
let filtered = benchmark_db. filtered_benchmark_count ( & filter) ;
@@ -162,44 +113,3 @@ fn compile_runtime_benchmarks(toolchain: &LocalToolchain, dir: &Path) -> anyhow:
162
113
return Ok ( result. stdout ) ;
163
114
}
164
115
}
165
-
166
- /// Parse Cargo JSON output and find all compiled binaries.
167
- /// Then execute each benchmark with the `list-benchmarks` command to find out its benchmark names.
168
- fn discover_benchmarks ( cargo_stdout : & [ u8 ] ) -> anyhow:: Result < BenchmarkDatabase > {
169
- let mut binaries = vec ! [ ] ;
170
-
171
- for message in Message :: parse_stream ( cargo_stdout) {
172
- let message = message?;
173
- match message {
174
- Message :: CompilerArtifact ( artifact) => {
175
- if let Some ( ref executable) = artifact. executable {
176
- if artifact. target . kind . iter ( ) . any ( |k| k == "bin" ) {
177
- let path = executable. as_std_path ( ) . to_path_buf ( ) ;
178
- let benchmarks = gather_benchmarks ( & path) . map_err ( |err| {
179
- anyhow:: anyhow!(
180
- "Cannot gather benchmarks from `{}`: {err:?}" ,
181
- path. display( )
182
- )
183
- } ) ?;
184
- binaries. push ( BenchmarkBinary {
185
- path,
186
- benchmark_names : benchmarks,
187
- } ) ;
188
- }
189
- }
190
- }
191
- _ => { }
192
- }
193
- }
194
-
195
- log:: debug!( "Found binaries: {:?}" , binaries) ;
196
-
197
- Ok ( BenchmarkDatabase { binaries } )
198
- }
199
-
200
- /// Uses the `list-benchmarks` command from `benchlib` to find the benchmark names from the given
201
- /// benchmark binary.
202
- fn gather_benchmarks ( binary : & Path ) -> anyhow:: Result < Vec < String > > {
203
- let output = Command :: new ( binary) . arg ( "list-benchmarks" ) . output ( ) ?;
204
- Ok ( serde_json:: from_slice ( & output. stdout ) ?)
205
- }
0 commit comments