@@ -12,6 +12,7 @@ use crate::util::style;
12
12
use crate :: util:: { CargoResult , GlobalContext } ;
13
13
use anyhow:: Context as _;
14
14
use cargo_util:: paths;
15
+ use indexmap:: IndexMap ;
15
16
use std:: collections:: HashMap ;
16
17
use std:: io:: { BufWriter , Write } ;
17
18
use std:: thread:: available_parallelism;
@@ -64,8 +65,9 @@ pub struct Timings<'gctx> {
64
65
cpu_usage : Vec < ( f64 , f64 ) > ,
65
66
}
66
67
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 {
69
71
/// Start of the section, as an offset in seconds from `UnitTime::start`.
70
72
start : f64 ,
71
73
/// End of the section, as an offset in seconds from `UnitTime::start`.
@@ -89,7 +91,10 @@ struct UnitTime {
89
91
/// Same as `unlocked_units`, but unlocked by rmeta.
90
92
unlocked_rmeta_units : Vec < Unit > ,
91
93
/// Individual compilation section durations, gathered from `--json=timings`.
92
- sections : HashMap < String , TimingSection > ,
94
+ ///
95
+ /// IndexMap is used to keep original insertion order, we want to be able to tell which
96
+ /// sections were started in which order.
97
+ sections : IndexMap < String , CompilationSection > ,
93
98
}
94
99
95
100
/// Periodic concurrency tracking information.
@@ -238,6 +243,7 @@ impl<'gctx> Timings<'gctx> {
238
243
mode : unit_time. unit . mode ,
239
244
duration : unit_time. duration ,
240
245
rmeta_time : unit_time. rmeta_time ,
246
+ sections : unit_time. sections . clone ( ) . into_iter ( ) . collect ( ) ,
241
247
}
242
248
. to_json_string ( ) ;
243
249
crate :: drop_println!( self . gctx, "{}" , msg) ;
@@ -616,20 +622,20 @@ impl UnitTime {
616
622
. sections
617
623
. insert (
618
624
name. to_string ( ) ,
619
- TimingSection {
625
+ CompilationSection {
620
626
start : now - self . start ,
621
627
end : None ,
622
628
} ,
623
629
)
624
630
. is_some ( )
625
631
{
626
- warn ! ( "Compilation section {name} started more than once" ) ;
632
+ warn ! ( "compilation section {name} started more than once" ) ;
627
633
}
628
634
}
629
635
630
636
fn end_section ( & mut self , name : & str , now : f64 ) {
631
637
let Some ( section) = self . sections . get_mut ( name) else {
632
- warn ! ( "Compilation section {name} ended, but it has no start recorded" ) ;
638
+ warn ! ( "compilation section {name} ended, but it has no start recorded" ) ;
633
639
return ;
634
640
} ;
635
641
section. end = Some ( now - self . start ) ;
0 commit comments