@@ -4,7 +4,6 @@ use std::borrow::Cow;
44use std:: collections:: HashMap ;
55use std:: collections:: HashSet ;
66use std:: io:: Write ;
7- use std:: time:: Instant ;
87
98use itertools:: Itertools as _;
109
@@ -96,8 +95,6 @@ pub struct Concurrency {
9695}
9796
9897pub struct RenderContext < ' a > {
99- /// When Cargo started.
100- pub start : Instant ,
10198 /// A rendered string of when compilation started.
10299 pub start_str : & ' a str ,
103100 /// A summary of the root units.
@@ -127,13 +124,16 @@ pub struct RenderContext<'a> {
127124 pub requested_targets : & ' a [ & ' a str ] ,
128125 /// The number of jobs specified for this build.
129126 pub jobs : u32 ,
127+ /// Available parallelism of the compilation environment.
128+ pub num_cpus : Option < u64 > ,
130129 /// Fatal error during the build.
131130 pub error : & ' a Option < anyhow:: Error > ,
132131}
133132
134133/// Writes an HTML report.
135134pub ( super ) fn write_html ( ctx : RenderContext < ' _ > , f : & mut impl Write ) -> CargoResult < ( ) > {
136- let duration = ctx. start . elapsed ( ) . as_secs_f64 ( ) ;
135+ // The last concurrency record should equal to the last unit finished time.
136+ let duration = ctx. concurrency . last ( ) . map ( |c| c. t ) . unwrap_or ( 0.0 ) ;
137137 let roots: Vec < & str > = ctx
138138 . root_units
139139 . iter ( )
@@ -186,10 +186,11 @@ fn write_summary_table(
186186 } ;
187187 let total_time = format ! ( "{:.1}s{}" , duration, time_human) ;
188188
189- let max_concurrency = ctx. concurrency . iter ( ) . map ( |c| c. active ) . max ( ) . unwrap ( ) ;
190- let num_cpus = std:: thread:: available_parallelism ( )
191- . map ( |x| x. get ( ) . to_string ( ) )
192- . unwrap_or_else ( |_| "n/a" . into ( ) ) ;
189+ let max_concurrency = ctx. concurrency . iter ( ) . map ( |c| c. active ) . max ( ) . unwrap_or ( 0 ) ;
190+ let num_cpus = ctx
191+ . num_cpus
192+ . map ( |x| x. to_string ( ) )
193+ . unwrap_or_else ( || "n/a" . into ( ) ) ;
193194
194195 let requested_targets = ctx. requested_targets . join ( ", " ) ;
195196
0 commit comments