@@ -25,16 +25,28 @@ pub enum ProfilerEvent {
2525 GenericActivityEnd { category : ProfileCategory , time : Instant } ,
2626 QueryCacheHit { query_name : & ' static str , category : ProfileCategory } ,
2727 QueryCount { query_name : & ' static str , category : ProfileCategory , count : usize } ,
28+ IncrementalLoadResultStart { query_name : & ' static str , time : Instant } ,
29+ IncrementalLoadResultEnd { query_name : & ' static str , time : Instant } ,
30+ QueryBlockedStart { query_name : & ' static str , category : ProfileCategory , time : Instant } ,
31+ QueryBlockedEnd { query_name : & ' static str , category : ProfileCategory , time : Instant } ,
2832}
2933
3034impl ProfilerEvent {
3135 fn is_start_event ( & self ) -> bool {
3236 use self :: ProfilerEvent :: * ;
3337
3438 match self {
35- QueryStart { .. } | GenericActivityStart { .. } => true ,
36- QueryEnd { .. } | GenericActivityEnd { .. } |
37- QueryCacheHit { .. } | QueryCount { .. } => false ,
39+ QueryStart { .. } |
40+ GenericActivityStart { .. } |
41+ IncrementalLoadResultStart { .. } |
42+ QueryBlockedStart { .. } => true ,
43+
44+ QueryEnd { .. } |
45+ GenericActivityEnd { .. } |
46+ QueryCacheHit { .. } |
47+ QueryCount { .. } |
48+ IncrementalLoadResultEnd { .. } |
49+ QueryBlockedEnd { .. } => false ,
3850 }
3951 }
4052}
@@ -57,12 +69,7 @@ impl CategoryResultData {
5769 }
5870
5971 fn total_time ( & self ) -> u64 {
60- let mut total = 0 ;
61- for ( _, time) in & self . query_times {
62- total += time;
63- }
64-
65- total
72+ self . query_times . iter ( ) . map ( |( _, time) | time) . sum ( )
6673 }
6774
6875 fn total_cache_data ( & self ) -> ( u64 , u64 ) {
@@ -121,13 +128,7 @@ impl CalculatedResults {
121128 }
122129
123130 fn total_time ( & self ) -> u64 {
124- let mut total = 0 ;
125-
126- for ( _, data) in & self . categories {
127- total += data. total_time ( ) ;
128- }
129-
130- total
131+ self . categories . iter ( ) . map ( |( _, data) | data. total_time ( ) ) . sum ( )
131132 }
132133
133134 fn with_options ( mut self , opts : & Options ) -> CalculatedResults {
@@ -225,6 +226,40 @@ impl SelfProfiler {
225226 } )
226227 }
227228
229+ #[ inline]
230+ pub fn incremental_load_result_start ( & mut self , query_name : & ' static str ) {
231+ self . record ( ProfilerEvent :: IncrementalLoadResultStart {
232+ query_name,
233+ time : Instant :: now ( ) ,
234+ } )
235+ }
236+
237+ #[ inline]
238+ pub fn incremental_load_result_end ( & mut self , query_name : & ' static str ) {
239+ self . record ( ProfilerEvent :: IncrementalLoadResultEnd {
240+ query_name,
241+ time : Instant :: now ( ) ,
242+ } )
243+ }
244+
245+ #[ inline]
246+ pub fn query_blocked_start ( & mut self , query_name : & ' static str , category : ProfileCategory ) {
247+ self . record ( ProfilerEvent :: QueryBlockedStart {
248+ query_name,
249+ category,
250+ time : Instant :: now ( ) ,
251+ } )
252+ }
253+
254+ #[ inline]
255+ pub fn query_blocked_end ( & mut self , query_name : & ' static str , category : ProfileCategory ) {
256+ self . record ( ProfilerEvent :: QueryBlockedEnd {
257+ query_name,
258+ category,
259+ time : Instant :: now ( ) ,
260+ } )
261+ }
262+
228263 #[ inline]
229264 fn record ( & mut self , event : ProfilerEvent ) {
230265 let thread_id = std:: thread:: current ( ) . id ( ) ;
@@ -317,6 +352,10 @@ impl SelfProfiler {
317352 result_data. query_cache_stats . entry ( query_name) . or_insert ( ( 0 , 0 ) ) ;
318353 * totals += * count as u64 ;
319354 } ,
355+ //we don't summarize incremental load result events in the simple output mode
356+ IncrementalLoadResultStart { .. } | IncrementalLoadResultEnd { .. } => { } ,
357+ //we don't summarize parallel query blocking in the simple output mode
358+ QueryBlockedStart { .. } | QueryBlockedEnd { .. } => { } ,
320359 }
321360 }
322361
@@ -361,9 +400,9 @@ impl SelfProfiler {
361400 . unwrap ( ) ;
362401
363402 let mut categories: Vec < _ > = results. categories . iter ( ) . collect ( ) ;
364- categories. sort_by ( |( _, data1 ) , ( _ , data2 ) | data2 . total_time ( ) . cmp ( & data1 . total_time ( ) ) ) ;
403+ categories. sort_by_cached_key ( |( _, d ) | d . total_time ( ) ) ;
365404
366- for ( category, data) in categories {
405+ for ( category, data) in categories. iter ( ) . rev ( ) {
367406 let ( category_hits, category_total) = data. total_cache_data ( ) ;
368407 let category_hit_percent = calculate_percent ( category_hits, category_total) ;
369408
0 commit comments