@@ -25,16 +25,28 @@ pub enum ProfilerEvent {
25
25
GenericActivityEnd { category : ProfileCategory , time : Instant } ,
26
26
QueryCacheHit { query_name : & ' static str , category : ProfileCategory } ,
27
27
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 } ,
28
32
}
29
33
30
34
impl ProfilerEvent {
31
35
fn is_start_event ( & self ) -> bool {
32
36
use self :: ProfilerEvent :: * ;
33
37
34
38
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 ,
38
50
}
39
51
}
40
52
}
@@ -57,12 +69,7 @@ impl CategoryResultData {
57
69
}
58
70
59
71
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 ( )
66
73
}
67
74
68
75
fn total_cache_data ( & self ) -> ( u64 , u64 ) {
@@ -121,13 +128,7 @@ impl CalculatedResults {
121
128
}
122
129
123
130
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 ( )
131
132
}
132
133
133
134
fn with_options ( mut self , opts : & Options ) -> CalculatedResults {
@@ -225,6 +226,40 @@ impl SelfProfiler {
225
226
} )
226
227
}
227
228
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
+
228
263
#[ inline]
229
264
fn record ( & mut self , event : ProfilerEvent ) {
230
265
let thread_id = std:: thread:: current ( ) . id ( ) ;
@@ -317,6 +352,10 @@ impl SelfProfiler {
317
352
result_data. query_cache_stats . entry ( query_name) . or_insert ( ( 0 , 0 ) ) ;
318
353
* totals += * count as u64 ;
319
354
} ,
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 { .. } => { } ,
320
359
}
321
360
}
322
361
@@ -361,9 +400,9 @@ impl SelfProfiler {
361
400
. unwrap ( ) ;
362
401
363
402
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 ( ) ) ;
365
404
366
- for ( category, data) in categories {
405
+ for ( category, data) in categories. iter ( ) . rev ( ) {
367
406
let ( category_hits, category_total) = data. total_cache_data ( ) ;
368
407
let category_hit_percent = calculate_percent ( category_hits, category_total) ;
369
408
0 commit comments