1
1
use std:: time:: Duration ;
2
2
3
- use build_helper:: metrics:: { JsonNode , JsonRoot } ;
3
+ use build_helper:: metrics:: { BuildStep , JsonRoot , format_build_steps } ;
4
4
use camino:: Utf8Path ;
5
5
6
6
use crate :: timer:: TimerSection ;
7
7
8
- #[ derive( Clone , Debug ) ]
9
- pub struct BuildStep {
10
- r#type : String ,
11
- children : Vec < BuildStep > ,
12
- duration : Duration ,
13
- }
14
-
15
- impl BuildStep {
16
- pub fn find_all_by_type ( & self , r#type : & str ) -> Vec < & BuildStep > {
17
- let mut result = Vec :: new ( ) ;
18
- self . find_by_type ( r#type, & mut result) ;
19
- result
20
- }
21
- fn find_by_type < ' a > ( & ' a self , r#type : & str , result : & mut Vec < & ' a BuildStep > ) {
22
- if self . r#type == r#type {
23
- result. push ( self ) ;
24
- }
25
- for child in & self . children {
26
- child. find_by_type ( r#type, result) ;
27
- }
28
- }
29
- }
30
-
31
8
/// Loads the metrics of the most recent bootstrap execution from a metrics.json file.
32
9
pub fn load_metrics ( path : & Utf8Path ) -> anyhow:: Result < BuildStep > {
33
10
let content = std:: fs:: read ( path. as_std_path ( ) ) ?;
@@ -37,30 +14,7 @@ pub fn load_metrics(path: &Utf8Path) -> anyhow::Result<BuildStep> {
37
14
. pop ( )
38
15
. ok_or_else ( || anyhow:: anyhow!( "No bootstrap invocation found in metrics file" ) ) ?;
39
16
40
- fn parse ( node : JsonNode ) -> Option < BuildStep > {
41
- match node {
42
- JsonNode :: RustbuildStep {
43
- type_ : kind,
44
- children,
45
- duration_excluding_children_sec,
46
- ..
47
- } => {
48
- let children: Vec < _ > = children. into_iter ( ) . filter_map ( parse) . collect ( ) ;
49
- let children_duration = children. iter ( ) . map ( |c| c. duration ) . sum :: < Duration > ( ) ;
50
- Some ( BuildStep {
51
- r#type : kind. to_string ( ) ,
52
- children,
53
- duration : children_duration
54
- + Duration :: from_secs_f64 ( duration_excluding_children_sec) ,
55
- } )
56
- }
57
- JsonNode :: TestSuite ( _) => None ,
58
- }
59
- }
60
-
61
- let duration = Duration :: from_secs_f64 ( invocation. duration_including_children_sec ) ;
62
- let children: Vec < _ > = invocation. children . into_iter ( ) . filter_map ( parse) . collect ( ) ;
63
- Ok ( BuildStep { r#type : "root" . to_string ( ) , children, duration } )
17
+ Ok ( BuildStep :: from_invocation ( & invocation) )
64
18
}
65
19
66
20
/// Logs the individual metrics in a table and add Rustc and LLVM durations to the passed
@@ -82,27 +36,6 @@ pub fn record_metrics(metrics: &BuildStep, timer: &mut TimerSection) {
82
36
timer. add_duration ( "Rustc" , rustc_duration) ;
83
37
}
84
38
85
- log_metrics ( metrics) ;
86
- }
87
-
88
- fn log_metrics ( metrics : & BuildStep ) {
89
- use std:: fmt:: Write ;
90
-
91
- let mut substeps: Vec < ( u32 , & BuildStep ) > = Vec :: new ( ) ;
92
-
93
- fn visit < ' a > ( step : & ' a BuildStep , level : u32 , substeps : & mut Vec < ( u32 , & ' a BuildStep ) > ) {
94
- substeps. push ( ( level, step) ) ;
95
- for child in & step. children {
96
- visit ( child, level + 1 , substeps) ;
97
- }
98
- }
99
-
100
- visit ( metrics, 0 , & mut substeps) ;
101
-
102
- let mut output = String :: new ( ) ;
103
- for ( level, step) in substeps {
104
- let label = format ! ( "{}{}" , "." . repeat( level as usize ) , step. r#type) ;
105
- writeln ! ( output, "{label:<65}{:>8.2}s" , step. duration. as_secs_f64( ) ) . unwrap ( ) ;
106
- }
39
+ let output = format_build_steps ( metrics) ;
107
40
log:: info!( "Build step durations\n {output}" ) ;
108
41
}
0 commit comments