@@ -16,6 +16,7 @@ use std::path::Path;
1616use std:: process:: {
1717 Child , ChildStderr , ChildStdout , Command , CommandArgs , CommandEnvs , ExitStatus , Output , Stdio ,
1818} ;
19+ use std:: time:: { Duration , Instant } ;
1920use std:: sync:: { Arc , Mutex } ;
2021
2122use build_helper:: ci:: CiEnv ;
@@ -75,7 +76,7 @@ pub struct CommandCacheKey {
7576#[ derive( Default , Clone ) ]
7677pub struct CommandProfile {
7778 pub count : usize ,
78- pub total_duration : Duration ,
79+ pub max_duration : Duration ,
7980}
8081
8182#[ derive( Default ) ]
@@ -89,22 +90,21 @@ impl CommandProfiler {
8990 let mut stats = self . stats . lock ( ) . unwrap ( ) ;
9091 let entry = stats. entry ( key) . or_default ( ) ;
9192 entry. count += 1 ;
92- entry. total_duration += duration;
93+ entry. max_duration = std :: cmp :: max ( entry . max_duration , duration) ;
9394 }
9495
9596 pub fn report_slowest ( & self , top_n : usize ) {
9697 let stats = self . stats . lock ( ) . unwrap ( ) ;
9798 let mut entries: Vec < _ > = stats. iter ( ) . collect ( ) ;
98- entries. sort_by_key ( |( _, stat) | std:: cmp:: Reverse ( stat. total_duration ) ) ;
99+ entries. sort_by_key ( |( _, stat) | std:: cmp:: Reverse ( stat. max_duration ) ) ;
99100
100101 println ! ( "\n Top {top_n} slowest commands:" ) ;
101102 for ( key, profile) in entries. into_iter ( ) . take ( top_n) {
102103 println ! (
103- "- {:?} (count: {}, total: {:.2?}, avg : {:.2?})" ,
104+ "- {:?} (count: {}, max_duration : {:.2?})" ,
104105 key. program,
105106 profile. count,
106- profile. total_duration,
107- profile. total_duration / profile. count as u32
107+ profile. max_duration,
108108 ) ;
109109 }
110110 }
@@ -122,7 +122,7 @@ impl CommandProfiler {
122122 "envs" : key. envs,
123123 "cwd" : key. cwd,
124124 "count" : profile. count,
125- "total_duration_ms " : profile. total_duration . as_millis( ) ,
125+ "max_duration_ms " : profile. max_duration . as_millis( ) ,
126126 } )
127127 } )
128128 . collect ( ) ;
0 commit comments