@@ -59,11 +59,12 @@ impl<'a> Benchmark<'a> {
5959 command : & Command < ' _ > ,
6060 error_output : & ' static str ,
6161 output_policy : & CommandOutputPolicy ,
62+ iteration : & executor:: BenchmarkIteration ,
6263 ) -> Result < TimingResult > {
6364 self . executor
6465 . run_command_and_measure (
6566 command,
66- executor :: BenchmarkIteration :: NonBenchmarkRun ,
67+ iteration ,
6768 Some ( CmdFailureAction :: RaiseError ) ,
6869 output_policy,
6970 )
@@ -76,6 +77,7 @@ impl<'a> Benchmark<'a> {
7677 & self ,
7778 parameters : impl IntoIterator < Item = ParameterNameAndValue < ' a > > ,
7879 output_policy : & CommandOutputPolicy ,
80+ iteration : executor:: BenchmarkIteration ,
7981 ) -> Result < TimingResult > {
8082 let command = self
8183 . options
@@ -87,7 +89,7 @@ impl<'a> Benchmark<'a> {
8789 Append ' || true' to the command if you are sure that this can be ignored.";
8890
8991 Ok ( command
90- . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy) )
92+ . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy, & iteration ) )
9193 . transpose ( ) ?
9294 . unwrap_or_default ( ) )
9395 }
@@ -97,6 +99,7 @@ impl<'a> Benchmark<'a> {
9799 & self ,
98100 parameters : impl IntoIterator < Item = ParameterNameAndValue < ' a > > ,
99101 output_policy : & CommandOutputPolicy ,
102+ iteration : executor:: BenchmarkIteration ,
100103 ) -> Result < TimingResult > {
101104 let command = self
102105 . options
@@ -108,7 +111,7 @@ impl<'a> Benchmark<'a> {
108111 Append ' || true' to the command if you are sure that this can be ignored.";
109112
110113 Ok ( command
111- . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy) )
114+ . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy, & iteration ) )
112115 . transpose ( ) ?
113116 . unwrap_or_default ( ) )
114117 }
@@ -118,23 +121,25 @@ impl<'a> Benchmark<'a> {
118121 & self ,
119122 command : & Command < ' _ > ,
120123 output_policy : & CommandOutputPolicy ,
124+ iteration : & executor:: BenchmarkIteration ,
121125 ) -> Result < TimingResult > {
122126 let error_output = "The preparation command terminated with a non-zero exit code. \
123127 Append ' || true' to the command if you are sure that this can be ignored.";
124128
125- self . run_intermediate_command ( command, error_output, output_policy)
129+ self . run_intermediate_command ( command, error_output, output_policy, iteration )
126130 }
127131
128132 /// Run the command specified by `--conclude`.
129133 fn run_conclusion_command (
130134 & self ,
131135 command : & Command < ' _ > ,
132136 output_policy : & CommandOutputPolicy ,
137+ iteration : executor:: BenchmarkIteration ,
133138 ) -> Result < TimingResult > {
134139 let error_output = "The conclusion command terminated with a non-zero exit code. \
135140 Append ' || true' to the command if you are sure that this can be ignored.";
136141
137- self . run_intermediate_command ( command, error_output, output_policy)
142+ self . run_intermediate_command ( command, error_output, output_policy, & iteration )
138143 }
139144
140145 /// Run the benchmark for a single command
@@ -170,10 +175,10 @@ impl<'a> Benchmark<'a> {
170175 )
171176 } ) ;
172177
173- let run_preparation_command = || {
178+ let run_preparation_command = |iteration : & executor :: BenchmarkIteration | {
174179 preparation_command
175180 . as_ref ( )
176- . map ( |cmd| self . run_preparation_command ( cmd, output_policy) )
181+ . map ( |cmd| self . run_preparation_command ( cmd, output_policy, iteration ) )
177182 . transpose ( )
178183 } ;
179184
@@ -189,14 +194,18 @@ impl<'a> Benchmark<'a> {
189194 self . command . get_parameters ( ) . iter ( ) . cloned ( ) ,
190195 )
191196 } ) ;
192- let run_conclusion_command = || {
197+ let run_conclusion_command = |iteration : executor :: BenchmarkIteration | {
193198 conclusion_command
194199 . as_ref ( )
195- . map ( |cmd| self . run_conclusion_command ( cmd, output_policy) )
200+ . map ( |cmd| self . run_conclusion_command ( cmd, output_policy, iteration ) )
196201 . transpose ( )
197202 } ;
198203
199- self . run_setup_command ( self . command . get_parameters ( ) . iter ( ) . cloned ( ) , output_policy) ?;
204+ self . run_setup_command (
205+ self . command . get_parameters ( ) . iter ( ) . cloned ( ) ,
206+ output_policy,
207+ executor:: BenchmarkIteration :: NonBenchmarkRun ,
208+ ) ?;
200209
201210 // Warmup phase
202211 if self . options . warmup_count > 0 {
@@ -211,14 +220,15 @@ impl<'a> Benchmark<'a> {
211220 } ;
212221
213222 for i in 0 ..self . options . warmup_count {
214- let _ = run_preparation_command ( ) ?;
223+ let warmup_iteration = BenchmarkIteration :: Warmup ( i) ;
224+ let _ = run_preparation_command ( & warmup_iteration) ?;
215225 let _ = self . executor . run_command_and_measure (
216226 self . command ,
217- BenchmarkIteration :: Warmup ( i ) ,
227+ & warmup_iteration ,
218228 None ,
219229 output_policy,
220230 ) ?;
221- let _ = run_conclusion_command ( ) ?;
231+ let _ = run_conclusion_command ( warmup_iteration ) ?;
222232 if let Some ( bar) = progress_bar. as_ref ( ) {
223233 bar. inc ( 1 )
224234 }
@@ -239,20 +249,21 @@ impl<'a> Benchmark<'a> {
239249 None
240250 } ;
241251
242- let preparation_result = run_preparation_command ( ) ?;
252+ let benchmark_iteration = BenchmarkIteration :: Benchmark ( 0 ) ;
253+ let preparation_result = run_preparation_command ( & benchmark_iteration) ?;
243254 let preparation_overhead =
244255 preparation_result. map_or ( 0.0 , |res| res. time_real + self . executor . time_overhead ( ) ) ;
245256
246257 // Initial timing run
247258 let ( res, status) = self . executor . run_command_and_measure (
248259 self . command ,
249- BenchmarkIteration :: Benchmark ( 0 ) ,
260+ & benchmark_iteration ,
250261 None ,
251262 output_policy,
252263 ) ?;
253264 let success = status. success ( ) ;
254265
255- let conclusion_result = run_conclusion_command ( ) ?;
266+ let conclusion_result = run_conclusion_command ( benchmark_iteration ) ?;
256267 let conclusion_overhead =
257268 conclusion_result. map_or ( 0.0 , |res| res. time_real + self . executor . time_overhead ( ) ) ;
258269
@@ -295,7 +306,8 @@ impl<'a> Benchmark<'a> {
295306
296307 // Gather statistics (perform the actual benchmark)
297308 for i in 0 ..count_remaining {
298- run_preparation_command ( ) ?;
309+ let benchmark_iteration = BenchmarkIteration :: Benchmark ( i + 1 ) ;
310+ run_preparation_command ( & benchmark_iteration) ?;
299311
300312 let msg = {
301313 let mean = format_duration ( mean ( & times_real) , self . options . time_unit ) ;
@@ -308,7 +320,7 @@ impl<'a> Benchmark<'a> {
308320
309321 let ( res, status) = self . executor . run_command_and_measure (
310322 self . command ,
311- BenchmarkIteration :: Benchmark ( i + 1 ) ,
323+ & benchmark_iteration ,
312324 None ,
313325 output_policy,
314326 ) ?;
@@ -326,7 +338,7 @@ impl<'a> Benchmark<'a> {
326338 bar. inc ( 1 )
327339 }
328340
329- run_conclusion_command ( ) ?;
341+ run_conclusion_command ( benchmark_iteration ) ?;
330342 }
331343
332344 if let Some ( bar) = progress_bar. as_ref ( ) {
@@ -441,7 +453,11 @@ impl<'a> Benchmark<'a> {
441453 println ! ( " " ) ;
442454 }
443455
444- self . run_cleanup_command ( self . command . get_parameters ( ) . iter ( ) . cloned ( ) , output_policy) ?;
456+ self . run_cleanup_command (
457+ self . command . get_parameters ( ) . iter ( ) . cloned ( ) ,
458+ output_policy,
459+ executor:: BenchmarkIteration :: NonBenchmarkRun ,
460+ ) ?;
445461
446462 Ok ( BenchmarkResult {
447463 command : self . command . get_name ( ) ,
0 commit comments