@@ -16,6 +16,7 @@ use std::path::Path;
16
16
use std:: process:: {
17
17
Child , ChildStderr , ChildStdout , Command , CommandArgs , CommandEnvs , ExitStatus , Output , Stdio ,
18
18
} ;
19
+ use std:: time:: { Duration , Instant } ;
19
20
use std:: sync:: { Arc , Mutex } ;
20
21
21
22
use build_helper:: ci:: CiEnv ;
@@ -75,7 +76,7 @@ pub struct CommandCacheKey {
75
76
#[ derive( Default , Clone ) ]
76
77
pub struct CommandProfile {
77
78
pub count : usize ,
78
- pub total_duration : Duration ,
79
+ pub max_duration : Duration ,
79
80
}
80
81
81
82
#[ derive( Default ) ]
@@ -89,22 +90,21 @@ impl CommandProfiler {
89
90
let mut stats = self . stats . lock ( ) . unwrap ( ) ;
90
91
let entry = stats. entry ( key) . or_default ( ) ;
91
92
entry. count += 1 ;
92
- entry. total_duration += duration;
93
+ entry. max_duration = std :: cmp :: max ( entry . max_duration , duration) ;
93
94
}
94
95
95
96
pub fn report_slowest ( & self , top_n : usize ) {
96
97
let stats = self . stats . lock ( ) . unwrap ( ) ;
97
98
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 ) ) ;
99
100
100
101
println ! ( "\n Top {top_n} slowest commands:" ) ;
101
102
for ( key, profile) in entries. into_iter ( ) . take ( top_n) {
102
103
println ! (
103
- "- {:?} (count: {}, total: {:.2?}, avg : {:.2?})" ,
104
+ "- {:?} (count: {}, max_duration : {:.2?})" ,
104
105
key. program,
105
106
profile. count,
106
- profile. total_duration,
107
- profile. total_duration / profile. count as u32
107
+ profile. max_duration,
108
108
) ;
109
109
}
110
110
}
@@ -122,7 +122,7 @@ impl CommandProfiler {
122
122
"envs" : key. envs,
123
123
"cwd" : key. cwd,
124
124
"count" : profile. count,
125
- "total_duration_ms " : profile. total_duration . as_millis( ) ,
125
+ "max_duration_ms " : profile. max_duration . as_millis( ) ,
126
126
} )
127
127
} )
128
128
. collect ( ) ;
0 commit comments