@@ -5,25 +5,19 @@ use std::collections::HashMap;
55use std:: collections:: HashSet ;
66use std:: io:: Write ;
77
8+ use indexmap:: IndexMap ;
89use itertools:: Itertools as _;
910
1011use crate :: CargoResult ;
1112use crate :: core:: compiler:: Unit ;
1213
14+ use super :: CompilationSection ;
1315use super :: UnitData ;
1416use super :: UnitTime ;
1517
16- /// Contains post-processed data of individual compilation sections.
17- enum AggregatedSections {
18- /// We know the names and durations of individual compilation sections
19- Sections ( Vec < ( SectionName , SectionData ) > ) ,
20- /// We know only the total duration
21- OnlyTotalDuration ,
22- }
23-
2418/// Name of an individual compilation section.
2519#[ derive( Clone , Hash , Eq , PartialEq ) ]
26- pub ( super ) enum SectionName {
20+ pub enum SectionName {
2721 Frontend ,
2822 Codegen ,
2923 Named ( String ) ,
@@ -67,11 +61,11 @@ impl serde::ser::Serialize for SectionName {
6761
6862/// Postprocessed section data that has both start and an end.
6963#[ derive( Copy , Clone , serde:: Serialize ) ]
70- pub ( super ) struct SectionData {
64+ pub struct SectionData {
7165 /// Start (relative to the start of the unit)
72- start : f64 ,
66+ pub start : f64 ,
7367 /// End (relative to the start of the unit)
74- end : f64 ,
68+ pub end : f64 ,
7569}
7670
7771impl SectionData {
@@ -96,13 +90,13 @@ pub struct Concurrency {
9690
9791pub struct RenderContext < ' a > {
9892 /// A rendered string of when compilation started.
99- pub start_str : & ' a str ,
93+ pub start_str : String ,
10094 /// A summary of the root units.
10195 ///
10296 /// Tuples of `(package_description, target_descriptions)`.
10397 pub root_units : & ' a [ ( String , Vec < String > ) ] ,
10498 /// The build profile.
105- pub profile : & ' a str ,
99+ pub profile : String ,
106100 /// Total number of fresh units.
107101 pub total_fresh : u32 ,
108102 /// Total number of dirty units.
@@ -117,9 +111,9 @@ pub struct RenderContext<'a> {
117111 /// system.
118112 pub cpu_usage : & ' a [ ( f64 , f64 ) ] ,
119113 /// Compiler version info, i.e., `rustc 1.92.0-beta.2 (0a411606e 2025-10-31)`.
120- pub rustc_version : & ' a str ,
114+ pub rustc_version : String ,
121115 /// The host triple (arch-platform-OS).
122- pub host : & ' a str ,
116+ pub host : String ,
123117 /// The requested target platforms of compilation for this build.
124118 pub requested_targets : & ' a [ & ' a str ] ,
125119 /// The number of jobs specified for this build.
@@ -131,7 +125,7 @@ pub struct RenderContext<'a> {
131125}
132126
133127/// Writes an HTML report.
134- pub ( super ) fn write_html ( ctx : RenderContext < ' _ > , f : & mut impl Write ) -> CargoResult < ( ) > {
128+ pub fn write_html ( ctx : RenderContext < ' _ > , f : & mut impl Write ) -> CargoResult < ( ) > {
135129 // The last concurrency record should equal to the last unit finished time.
136130 let duration = ctx. concurrency . last ( ) . map ( |c| c. t ) . unwrap_or ( 0.0 ) ;
137131 let roots: Vec < & str > = ctx
@@ -384,10 +378,7 @@ pub(super) fn to_unit_data(
384378 . iter ( )
385379 . filter_map ( |unit| unit_map. get ( unit) . copied ( ) )
386380 . collect ( ) ;
387- let sections = match aggregate_sections ( ut) {
388- AggregatedSections :: Sections ( sections) => Some ( sections) ,
389- AggregatedSections :: OnlyTotalDuration => None ,
390- } ;
381+ let sections = aggregate_sections ( ut. sections . clone ( ) , ut. duration , ut. rmeta_time ) ;
391382
392383 UnitData {
393384 i,
@@ -407,7 +398,7 @@ pub(super) fn to_unit_data(
407398}
408399
409400/// Derives concurrency information from unit timing data.
410- pub ( super ) fn compute_concurrency ( unit_data : & [ UnitData ] ) -> Vec < Concurrency > {
401+ pub fn compute_concurrency ( unit_data : & [ UnitData ] ) -> Vec < Concurrency > {
411402 if unit_data. is_empty ( ) {
412403 return Vec :: new ( ) ;
413404 }
@@ -539,16 +530,17 @@ pub(super) fn compute_concurrency(unit_data: &[UnitData]) -> Vec<Concurrency> {
539530/// in which case we use them to determine the headers.
540531/// - We have at least one rmeta time, so we hard-code Frontend and Codegen headers.
541532/// - We only have total durations, so we don't add any additional headers.
542- fn aggregate_sections ( unit_time : & UnitTime ) -> AggregatedSections {
543- let end = unit_time. duration ;
544-
545- if !unit_time. sections . is_empty ( ) {
533+ pub fn aggregate_sections (
534+ sections : IndexMap < String , CompilationSection > ,
535+ end : f64 ,
536+ rmeta_time : Option < f64 > ,
537+ ) -> Option < Vec < ( SectionName , SectionData ) > > {
538+ if !sections. is_empty ( ) {
546539 // We have some detailed compilation section timings, so we postprocess them
547540 // Since it is possible that we do not have an end timestamp for a given compilation
548541 // section, we need to iterate them and if an end is missing, we assign the end of
549542 // the section to the start of the following section.
550-
551- let mut sections = unit_time. sections . clone ( ) . into_iter ( ) . fold (
543+ let mut sections = sections. into_iter ( ) . fold (
552544 // The frontend section is currently implicit in rustc.
553545 // It is assumed to start at compilation start and end when codegen starts,
554546 // So we hard-code it here.
@@ -593,11 +585,10 @@ fn aggregate_sections(unit_time: &UnitTime) -> AggregatedSections {
593585 } ,
594586 ) ) ;
595587 }
596-
597- AggregatedSections :: Sections ( sections)
598- } else if let Some ( rmeta) = unit_time. rmeta_time {
588+ Some ( sections)
589+ } else if let Some ( rmeta) = rmeta_time {
599590 // We only know when the rmeta time was generated
600- AggregatedSections :: Sections ( vec ! [
591+ Some ( vec ! [
601592 (
602593 SectionName :: Frontend ,
603594 SectionData {
@@ -614,13 +605,13 @@ fn aggregate_sections(unit_time: &UnitTime) -> AggregatedSections {
614605 ) ,
615606 ] )
616607 } else {
617- // We only know the total duration
618- AggregatedSections :: OnlyTotalDuration
608+ // No section data provided. We only know the total duration.
609+ None
619610 }
620611}
621612
622613/// Rounds seconds to 0.01s precision.
623- fn round_to_centisecond ( x : f64 ) -> f64 {
614+ pub fn round_to_centisecond ( x : f64 ) -> f64 {
624615 ( x * 100.0 ) . round ( ) / 100.0
625616}
626617
0 commit comments