1
+ use std:: borrow:: Cow ;
1
2
use std:: fs;
2
3
use std:: io:: { BufWriter , Write } ;
3
4
use std:: mem;
@@ -20,12 +21,12 @@ pub enum ProfileCategory {
20
21
Other ,
21
22
}
22
23
23
- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
24
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
24
25
pub enum ProfilerEvent {
25
26
QueryStart { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
26
27
QueryEnd { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
27
- GenericActivityStart { category : ProfileCategory , time : u64 } ,
28
- GenericActivityEnd { category : ProfileCategory , time : u64 } ,
28
+ GenericActivityStart { category : ProfileCategory , label : Cow < ' static , str > , time : u64 } ,
29
+ GenericActivityEnd { category : ProfileCategory , label : Cow < ' static , str > , time : u64 } ,
29
30
IncrementalLoadResultStart { query_name : & ' static str , time : u64 } ,
30
31
IncrementalLoadResultEnd { query_name : & ' static str , time : u64 } ,
31
32
QueryCacheHit { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
@@ -75,17 +76,27 @@ impl SelfProfiler {
75
76
}
76
77
77
78
#[ inline]
78
- pub fn start_activity ( & mut self , category : ProfileCategory ) {
79
+ pub fn start_activity (
80
+ & mut self ,
81
+ category : ProfileCategory ,
82
+ label : impl Into < Cow < ' static , str > > ,
83
+ ) {
79
84
self . record ( ProfilerEvent :: GenericActivityStart {
80
85
category,
86
+ label : label. into ( ) ,
81
87
time : self . get_time_from_start ( ) ,
82
88
} )
83
89
}
84
90
85
91
#[ inline]
86
- pub fn end_activity ( & mut self , category : ProfileCategory ) {
92
+ pub fn end_activity (
93
+ & mut self ,
94
+ category : ProfileCategory ,
95
+ label : impl Into < Cow < ' static , str > > ,
96
+ ) {
87
97
self . record ( ProfilerEvent :: GenericActivityEnd {
88
98
category,
99
+ label : label. into ( ) ,
89
100
time : self . get_time_from_start ( ) ,
90
101
} )
91
102
}
@@ -273,11 +284,12 @@ impl SelfProfiler {
273
284
nanos,
274
285
thread_id,
275
286
) . unwrap ( ) ,
276
- GenericActivityStart { category, time : _ } =>
287
+ GenericActivityStart { category, label , time : _ } =>
277
288
write ! ( file,
278
289
"{{
279
290
\" GenericActivityStart\" : {{\
280
291
\" category\" : \" {:?}\" ,\
292
+ \" label\" : \" {}\" ,\
281
293
\" time\" : {{\
282
294
\" secs\" : {},\
283
295
\" nanos\" : {}\
@@ -286,15 +298,17 @@ impl SelfProfiler {
286
298
}}\
287
299
}}",
288
300
category,
301
+ label,
289
302
secs,
290
303
nanos,
291
304
thread_id,
292
305
) . unwrap ( ) ,
293
- GenericActivityEnd { category, time : _ } =>
306
+ GenericActivityEnd { category, label , time : _ } =>
294
307
write ! ( file,
295
308
"{{\
296
309
\" GenericActivityEnd\" : {{\
297
310
\" category\" : \" {:?}\" ,\
311
+ \" label\" : \" {}\" ,\
298
312
\" time\" : {{\
299
313
\" secs\" : {},\
300
314
\" nanos\" : {}\
@@ -303,6 +317,7 @@ impl SelfProfiler {
303
317
}}\
304
318
}}",
305
319
category,
320
+ label,
306
321
secs,
307
322
nanos,
308
323
thread_id,
@@ -418,7 +433,7 @@ impl SelfProfiler {
418
433
secs,
419
434
nanos,
420
435
thread_id,
421
- ) . unwrap ( )
436
+ ) . unwrap ( ) ,
422
437
}
423
438
}
424
439
}
0 commit comments