@@ -10,8 +10,8 @@ use collector::benchmark::scenario::Scenario;
10
10
use collector:: benchmark:: {
11
11
compile_benchmark_dir, get_compile_benchmarks, runtime_benchmark_dir, Benchmark , BenchmarkName ,
12
12
} ;
13
- use collector:: utils;
14
- use database:: { ArtifactId , Commit , CommitType , Pool } ;
13
+ use collector:: { runtime , utils, CollectorCtx , CollectorStepBuilder } ;
14
+ use database:: { ArtifactId , Commit , CommitType , Connection , Pool } ;
15
15
use rayon:: iter:: { IndexedParallelIterator , IntoParallelRefIterator , ParallelIterator } ;
16
16
use std:: ffi:: OsStr ;
17
17
use std:: fs;
@@ -59,21 +59,19 @@ impl BenchmarkErrors {
59
59
60
60
fn bench (
61
61
rt : & mut Runtime ,
62
- pool : database:: Pool ,
63
- artifact_id : & ArtifactId ,
62
+ mut conn : Box < dyn Connection > ,
64
63
profiles : & [ Profile ] ,
65
64
scenarios : & [ Scenario ] ,
66
- bench_rustc : bool ,
67
65
compiler : Compiler < ' _ > ,
68
66
benchmarks : & [ Benchmark ] ,
69
67
iterations : Option < usize > ,
70
68
is_self_profile : bool ,
69
+ mut collector : CollectorCtx ,
71
70
) -> BenchmarkErrors {
72
- let mut conn = rt. block_on ( pool. connection ( ) ) ;
73
71
let mut errors = BenchmarkErrors :: new ( ) ;
74
72
eprintln ! (
75
73
"Benchmarking {} for triple {}" ,
76
- artifact_id, compiler. triple
74
+ collector . artifact_id, compiler. triple
77
75
) ;
78
76
79
77
if is_self_profile {
@@ -82,24 +80,7 @@ fn bench(
82
80
}
83
81
}
84
82
85
- let mut steps = benchmarks
86
- . iter ( )
87
- . map ( |b| b. name . to_string ( ) )
88
- . collect :: < Vec < _ > > ( ) ;
89
- if bench_rustc {
90
- steps. push ( "rustc" . to_string ( ) ) ;
91
- }
92
-
93
- // Make sure there is no observable time when the artifact ID is available
94
- // but the in-progress steps are not.
95
- let artifact_row_id = {
96
- let mut tx = rt. block_on ( conn. transaction ( ) ) ;
97
- let artifact_row_id = rt. block_on ( tx. conn ( ) . artifact_id ( & artifact_id) ) ;
98
- rt. block_on ( tx. conn ( ) . collector_start ( artifact_row_id, & steps) ) ;
99
-
100
- rt. block_on ( tx. commit ( ) ) . unwrap ( ) ;
101
- artifact_row_id
102
- } ;
83
+ let bench_rustc = collector. bench_rustc ;
103
84
104
85
let start = Instant :: now ( ) ;
105
86
let mut skipped = false ;
@@ -109,8 +90,7 @@ fn bench(
109
90
category : Category ,
110
91
print_intro : & dyn Fn ( ) ,
111
92
measure : & dyn Fn ( & mut BenchProcessor ) -> anyhow:: Result < ( ) > | {
112
- let is_fresh =
113
- rt. block_on ( conn. collector_start_step ( artifact_row_id, & benchmark_name. 0 ) ) ;
93
+ let is_fresh = rt. block_on ( collector. start_compile_step ( conn. as_mut ( ) , benchmark_name) ) ;
114
94
if !is_fresh {
115
95
skipped = true ;
116
96
eprintln ! ( "skipping {} -- already benchmarked" , benchmark_name) ;
@@ -129,8 +109,8 @@ fn bench(
129
109
rt,
130
110
tx. conn ( ) ,
131
111
benchmark_name,
132
- & artifact_id,
133
- artifact_row_id,
112
+ & collector . artifact_id ,
113
+ collector . artifact_row_id ,
134
114
is_self_profile,
135
115
) ;
136
116
let result = measure ( & mut processor) ;
@@ -141,15 +121,12 @@ fn bench(
141
121
) ;
142
122
errors. incr ( ) ;
143
123
rt. block_on ( tx. conn ( ) . record_error (
144
- artifact_row_id,
124
+ collector . artifact_row_id ,
145
125
& benchmark_name. 0 ,
146
126
& format ! ( "{:?}" , s) ,
147
127
) ) ;
148
128
} ;
149
- rt. block_on (
150
- tx. conn ( )
151
- . collector_end_step ( artifact_row_id, & benchmark_name. 0 ) ,
152
- ) ;
129
+ rt. block_on ( collector. end_compile_step ( tx. conn ( ) , benchmark_name) ) ;
153
130
rt. block_on ( tx. commit ( ) ) . expect ( "committed" ) ;
154
131
} ;
155
132
@@ -188,7 +165,7 @@ fn bench(
188
165
if skipped {
189
166
log:: info!( "skipping duration record -- skipped parts of run" ) ;
190
167
} else {
191
- rt. block_on ( conn. record_duration ( artifact_row_id, end) ) ;
168
+ rt. block_on ( conn. record_duration ( collector . artifact_row_id , end) ) ;
192
169
}
193
170
194
171
rt. block_on ( async move {
@@ -733,12 +710,21 @@ fn main_result() -> anyhow::Result<i32> {
733
710
) ?;
734
711
let pool = Pool :: open ( & db. db ) ;
735
712
713
+ let suite = runtime:: discover_benchmarks ( & toolchain, & runtime_benchmark_dir) ?;
714
+ let artifact_id = ArtifactId :: Tag ( toolchain. id . clone ( ) ) ;
715
+ let ( conn, collector) = rt. block_on ( async {
716
+ let mut conn = pool. connection ( ) . await ;
717
+ let collector = CollectorStepBuilder :: default ( )
718
+ . record_runtime_benchmarks ( & suite)
719
+ . start_collection ( conn. as_mut ( ) , artifact_id)
720
+ . await ;
721
+ ( conn, collector)
722
+ } ) ;
736
723
let fut = bench_runtime (
737
- pool ,
738
- ArtifactId :: Tag ( toolchain . id . clone ( ) ) ,
739
- toolchain ,
724
+ conn ,
725
+ suite ,
726
+ collector ,
740
727
BenchmarkFilter :: new ( local. exclude , local. include ) ,
741
- runtime_benchmark_dir,
742
728
iterations,
743
729
) ;
744
730
rt. block_on ( fut) ?;
@@ -774,17 +760,24 @@ fn main_result() -> anyhow::Result<i32> {
774
760
) ?;
775
761
benchmarks. retain ( |b| b. category ( ) . is_primary_or_secondary ( ) ) ;
776
762
763
+ let artifact_id = ArtifactId :: Tag ( toolchain. id . clone ( ) ) ;
764
+ let ( conn, collector) = rt. block_on ( init_compile_collector (
765
+ & pool,
766
+ & benchmarks,
767
+ bench_rustc. bench_rustc ,
768
+ artifact_id,
769
+ ) ) ;
770
+
777
771
let res = bench (
778
772
& mut rt,
779
- pool,
780
- & ArtifactId :: Tag ( toolchain. id . clone ( ) ) ,
773
+ conn,
781
774
& profiles,
782
775
& scenarios,
783
- bench_rustc. bench_rustc ,
784
776
Compiler :: from_toolchain ( & toolchain, & target_triple) ,
785
777
& benchmarks,
786
778
Some ( iterations) ,
787
779
self_profile. self_profile ,
780
+ collector,
788
781
) ;
789
782
res. fail_if_nonzero ( ) ?;
790
783
Ok ( 0 )
@@ -841,17 +834,23 @@ fn main_result() -> anyhow::Result<i32> {
841
834
) ?;
842
835
benchmarks. retain ( |b| b. category ( ) . is_primary_or_secondary ( ) ) ;
843
836
837
+ let artifact_id = ArtifactId :: Commit ( commit) ;
838
+ let ( conn, collector) = rt. block_on ( init_compile_collector (
839
+ & pool,
840
+ & benchmarks,
841
+ bench_rustc. bench_rustc ,
842
+ artifact_id,
843
+ ) ) ;
844
844
let res = bench (
845
845
& mut rt,
846
- pool,
847
- & ArtifactId :: Commit ( commit) ,
846
+ conn,
848
847
& Profile :: all ( ) ,
849
848
& Scenario :: all ( ) ,
850
- bench_rustc. bench_rustc ,
851
849
Compiler :: from_sysroot ( & sysroot) ,
852
850
& benchmarks,
853
851
runs. map ( |v| v as usize ) ,
854
852
self_profile. self_profile ,
853
+ collector,
855
854
) ;
856
855
857
856
client. post ( & format ! ( "{}/perf/onpush" , site_url) ) . send ( ) ?;
@@ -1014,6 +1013,20 @@ fn main_result() -> anyhow::Result<i32> {
1014
1013
}
1015
1014
}
1016
1015
1016
+ async fn init_compile_collector (
1017
+ pool : & database:: Pool ,
1018
+ benchmarks : & [ Benchmark ] ,
1019
+ bench_rustc : bool ,
1020
+ artifact_id : ArtifactId ,
1021
+ ) -> ( Box < dyn Connection > , CollectorCtx ) {
1022
+ let mut conn = pool. connection ( ) . await ;
1023
+ let collector = CollectorStepBuilder :: default ( )
1024
+ . record_compile_benchmarks ( & benchmarks, bench_rustc)
1025
+ . start_collection ( conn. as_mut ( ) , artifact_id)
1026
+ . await ;
1027
+ ( conn, collector)
1028
+ }
1029
+
1017
1030
fn bench_published_artifact (
1018
1031
toolchain : String ,
1019
1032
pool : Pool ,
@@ -1061,13 +1074,18 @@ fn bench_published_artifact(
1061
1074
let mut benchmarks = get_compile_benchmarks ( & benchmark_dir, None , None , None ) ?;
1062
1075
benchmarks. retain ( |b| b. category ( ) . is_stable ( ) ) ;
1063
1076
1077
+ let artifact_id = ArtifactId :: Tag ( toolchain) ;
1078
+ let ( conn, collector) = rt. block_on ( init_compile_collector (
1079
+ & pool,
1080
+ & benchmarks,
1081
+ /* bench_rustc */ false ,
1082
+ artifact_id,
1083
+ ) ) ;
1064
1084
let res = bench (
1065
1085
rt,
1066
- pool,
1067
- & ArtifactId :: Tag ( toolchain) ,
1086
+ conn,
1068
1087
& profiles,
1069
1088
& scenarios,
1070
- /* bench_rustc */ false ,
1071
1089
Compiler {
1072
1090
rustc : Path :: new ( rustc. trim ( ) ) ,
1073
1091
rustdoc : Some ( Path :: new ( rustdoc. trim ( ) ) ) ,
@@ -1078,6 +1096,7 @@ fn bench_published_artifact(
1078
1096
& benchmarks,
1079
1097
Some ( 3 ) ,
1080
1098
/* is_self_profile */ false ,
1099
+ collector,
1081
1100
) ;
1082
1101
res. fail_if_nonzero ( ) ?;
1083
1102
Ok ( ( ) )
0 commit comments