@@ -76,7 +76,7 @@ pub struct CommandCacheKey {
76
76
#[ derive( Default , Clone ) ]
77
77
pub struct CommandProfile {
78
78
pub count : usize ,
79
- pub max_duration : Duration ,
79
+ pub durations : Vec < Duration > ,
80
80
}
81
81
82
82
#[ derive( Default ) ]
@@ -89,42 +89,7 @@ impl CommandProfiler {
89
89
let mut stats = self . stats . lock ( ) . unwrap ( ) ;
90
90
let entry = stats. entry ( key) . or_default ( ) ;
91
91
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) ;
128
93
}
129
94
}
130
95
0 commit comments