@@ -12,6 +12,7 @@ use crate::util::style;
1212use crate :: util:: { CargoResult , GlobalContext } ;
1313use anyhow:: Context as _;
1414use cargo_util:: paths;
15+ use indexmap:: IndexMap ;
1516use std:: collections:: HashMap ;
1617use std:: io:: { BufWriter , Write } ;
1718use std:: thread:: available_parallelism;
@@ -64,8 +65,9 @@ pub struct Timings<'gctx> {
6465 cpu_usage : Vec < ( f64 , f64 ) > ,
6566}
6667
67- /// Section of compilation.
68- struct TimingSection {
68+ /// Section of compilation (e.g. frontend, backend, linking).
69+ #[ derive( Copy , Clone , serde:: Serialize ) ]
70+ pub struct CompilationSection {
6971 /// Start of the section, as an offset in seconds from `UnitTime::start`.
7072 start : f64 ,
7173 /// End of the section, as an offset in seconds from `UnitTime::start`.
@@ -88,8 +90,9 @@ struct UnitTime {
8890 unlocked_units : Vec < Unit > ,
8991 /// Same as `unlocked_units`, but unlocked by rmeta.
9092 unlocked_rmeta_units : Vec < Unit > ,
91- /// Individual compilation section durations, gathered from `--json=timings`.
92- sections : HashMap < String , TimingSection > ,
93+ /// IndexMap is used to keep original insertion order, we want to be able to tell which
94+ /// sections were started in which order.
95+ sections : IndexMap < String , CompilationSection > ,
9396}
9497
9598/// Periodic concurrency tracking information.
@@ -238,6 +241,7 @@ impl<'gctx> Timings<'gctx> {
238241 mode : unit_time. unit . mode ,
239242 duration : unit_time. duration ,
240243 rmeta_time : unit_time. rmeta_time ,
244+ sections : unit_time. sections . clone ( ) . into_iter ( ) . collect ( ) ,
241245 }
242246 . to_json_string ( ) ;
243247 crate :: drop_println!( self . gctx, "{}" , msg) ;
@@ -616,20 +620,20 @@ impl UnitTime {
616620 . sections
617621 . insert (
618622 name. to_string ( ) ,
619- TimingSection {
623+ CompilationSection {
620624 start : now - self . start ,
621625 end : None ,
622626 } ,
623627 )
624628 . is_some ( )
625629 {
626- warn ! ( "Compilation section {name} started more than once" ) ;
630+ warn ! ( "compilation section {name} started more than once" ) ;
627631 }
628632 }
629633
630634 fn end_section ( & mut self , name : & str , now : f64 ) {
631635 let Some ( section) = self . sections . get_mut ( name) else {
632- warn ! ( "Compilation section {name} ended, but it has no start recorded" ) ;
636+ warn ! ( "compilation section {name} ended, but it has no start recorded" ) ;
633637 return ;
634638 } ;
635639 section. end = Some ( now - self . start ) ;
0 commit comments