@@ -76,7 +76,7 @@ pub struct CommandCacheKey {
7676#[ derive( Default , Clone ) ]
7777pub struct CommandProfile {
7878 pub count : usize ,
79- pub max_duration : Duration ,
79+ pub durations : Vec < Duration > ,
8080}
8181
8282#[ derive( Default ) ]
@@ -89,42 +89,7 @@ impl CommandProfiler {
8989 let mut stats = self . stats . lock ( ) . unwrap ( ) ;
9090 let entry = stats. entry ( key) . or_default ( ) ;
9191 entry. count += 1 ;
92- entry. max_duration = std:: cmp:: max ( entry. max_duration , duration) ;
93- }
94-
95- pub fn report_slowest ( & self , top_n : usize ) {
96- let stats = self . stats . lock ( ) . unwrap ( ) ;
97- let mut entries: Vec < _ > = stats. iter ( ) . collect ( ) ;
98- entries. sort_by_key ( |( _, stat) | std:: cmp:: Reverse ( stat. max_duration ) ) ;
99-
100- println ! ( "\n Top {top_n} slowest commands:" ) ;
101- for ( key, profile) in entries. into_iter ( ) . take ( top_n) {
102- println ! (
103- "- {:?} (count: {}, max_duration: {:.2?})" ,
104- key. program, profile. count, profile. max_duration,
105- ) ;
106- }
107- }
108-
109- pub fn to_json ( & self ) -> serde_json:: Value {
110- use serde_json:: json;
111-
112- let stats = self . stats . lock ( ) . unwrap ( ) ;
113- let entries: Vec < _ > = stats
114- . iter ( )
115- . map ( |( key, profile) | {
116- json ! ( {
117- "program" : key. program,
118- "args" : key. args,
119- "envs" : key. envs,
120- "cwd" : key. cwd,
121- "count" : profile. count,
122- "max_duration_ms" : profile. max_duration. as_millis( ) ,
123- } )
124- } )
125- . collect ( ) ;
126-
127- json ! ( { "commands" : entries } )
92+ entry. durations . push ( duration) ;
12893 }
12994}
13095
0 commit comments