@@ -94,31 +94,34 @@ use std::process;
94
94
use std:: sync:: Arc ;
95
95
use std:: time:: { Duration , Instant } ;
96
96
97
- use measureme:: { EventId , EventIdBuilder , Profiler , SerializableString , StringId } ;
97
+ pub use measureme:: EventId ;
98
+ use measureme:: { EventIdBuilder , Profiler , SerializableString , StringId } ;
98
99
use parking_lot:: RwLock ;
99
100
100
101
bitflags:: bitflags! {
101
102
struct EventFilter : u32 {
102
- const GENERIC_ACTIVITIES = 1 << 0 ;
103
- const QUERY_PROVIDERS = 1 << 1 ;
104
- const QUERY_CACHE_HITS = 1 << 2 ;
105
- const QUERY_BLOCKED = 1 << 3 ;
106
- const INCR_CACHE_LOADS = 1 << 4 ;
103
+ const GENERIC_ACTIVITIES = 1 << 0 ;
104
+ const QUERY_PROVIDERS = 1 << 1 ;
105
+ const QUERY_CACHE_HITS = 1 << 2 ;
106
+ const QUERY_BLOCKED = 1 << 3 ;
107
+ const INCR_CACHE_LOADS = 1 << 4 ;
107
108
108
- const QUERY_KEYS = 1 << 5 ;
109
- const FUNCTION_ARGS = 1 << 6 ;
110
- const LLVM = 1 << 7 ;
109
+ const QUERY_KEYS = 1 << 5 ;
110
+ const FUNCTION_ARGS = 1 << 6 ;
111
+ const LLVM = 1 << 7 ;
112
+ const INCR_RESULT_HASHING = 1 << 8 ;
111
113
112
114
const DEFAULT = Self :: GENERIC_ACTIVITIES . bits |
113
115
Self :: QUERY_PROVIDERS . bits |
114
116
Self :: QUERY_BLOCKED . bits |
115
- Self :: INCR_CACHE_LOADS . bits;
117
+ Self :: INCR_CACHE_LOADS . bits |
118
+ Self :: INCR_RESULT_HASHING . bits;
116
119
117
120
const ARGS = Self :: QUERY_KEYS . bits | Self :: FUNCTION_ARGS . bits;
118
121
}
119
122
}
120
123
121
- // keep this in sync with the `-Z self-profile-events` help message in librustc_session /options.rs
124
+ // keep this in sync with the `-Z self-profile-events` help message in rustc_session /options.rs
122
125
const EVENT_FILTERS_BY_NAME : & [ ( & str , EventFilter ) ] = & [
123
126
( "none" , EventFilter :: empty ( ) ) ,
124
127
( "all" , EventFilter :: all ( ) ) ,
@@ -132,6 +135,7 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
132
135
( "function-args" , EventFilter :: FUNCTION_ARGS ) ,
133
136
( "args" , EventFilter :: ARGS ) ,
134
137
( "llvm" , EventFilter :: LLVM ) ,
138
+ ( "incr-result-hashing" , EventFilter :: INCR_RESULT_HASHING ) ,
135
139
] ;
136
140
137
141
/// Something that uniquely identifies a query invocation.
@@ -248,6 +252,15 @@ impl SelfProfilerRef {
248
252
} )
249
253
}
250
254
255
+ /// Start profiling with some event filter for a given event. Profiling continues until the
256
+ /// TimingGuard returned from this call is dropped.
257
+ #[ inline( always) ]
258
+ pub fn generic_activity_with_event_id ( & self , event_id : EventId ) -> TimingGuard < ' _ > {
259
+ self . exec ( EventFilter :: GENERIC_ACTIVITIES , |profiler| {
260
+ TimingGuard :: start ( profiler, profiler. generic_activity_event_kind , event_id)
261
+ } )
262
+ }
263
+
251
264
/// Start profiling a generic activity. Profiling continues until the
252
265
/// TimingGuard returned from this call is dropped.
253
266
#[ inline( always) ]
@@ -337,6 +350,19 @@ impl SelfProfilerRef {
337
350
} )
338
351
}
339
352
353
+ /// Start profiling how long it takes to hash query results for incremental compilation.
354
+ /// Profiling continues until the TimingGuard returned from this call is dropped.
355
+ #[ inline( always) ]
356
+ pub fn incr_result_hashing ( & self ) -> TimingGuard < ' _ > {
357
+ self . exec ( EventFilter :: INCR_RESULT_HASHING , |profiler| {
358
+ TimingGuard :: start (
359
+ profiler,
360
+ profiler. incremental_result_hashing_event_kind ,
361
+ EventId :: INVALID ,
362
+ )
363
+ } )
364
+ }
365
+
340
366
#[ inline( always) ]
341
367
fn instant_query_event (
342
368
& self ,
@@ -364,6 +390,14 @@ impl SelfProfilerRef {
364
390
}
365
391
}
366
392
393
+ /// Gets a `StringId` for the given string. This method makes sure that
394
+ /// any strings going through it will only be allocated once in the
395
+ /// profiling data.
396
+ /// Returns `None` if the self-profiling is not enabled.
397
+ pub fn get_or_alloc_cached_string ( & self , s : & str ) -> Option < StringId > {
398
+ self . profiler . as_ref ( ) . map ( |p| p. get_or_alloc_cached_string ( s) )
399
+ }
400
+
367
401
#[ inline]
368
402
pub fn enabled ( & self ) -> bool {
369
403
self . profiler . is_some ( )
@@ -388,6 +422,7 @@ pub struct SelfProfiler {
388
422
query_event_kind : StringId ,
389
423
generic_activity_event_kind : StringId ,
390
424
incremental_load_result_event_kind : StringId ,
425
+ incremental_result_hashing_event_kind : StringId ,
391
426
query_blocked_event_kind : StringId ,
392
427
query_cache_hit_event_kind : StringId ,
393
428
}
@@ -408,6 +443,8 @@ impl SelfProfiler {
408
443
let query_event_kind = profiler. alloc_string ( "Query" ) ;
409
444
let generic_activity_event_kind = profiler. alloc_string ( "GenericActivity" ) ;
410
445
let incremental_load_result_event_kind = profiler. alloc_string ( "IncrementalLoadResult" ) ;
446
+ let incremental_result_hashing_event_kind =
447
+ profiler. alloc_string ( "IncrementalResultHashing" ) ;
411
448
let query_blocked_event_kind = profiler. alloc_string ( "QueryBlocked" ) ;
412
449
let query_cache_hit_event_kind = profiler. alloc_string ( "QueryCacheHit" ) ;
413
450
@@ -451,6 +488,7 @@ impl SelfProfiler {
451
488
query_event_kind,
452
489
generic_activity_event_kind,
453
490
incremental_load_result_event_kind,
491
+ incremental_result_hashing_event_kind,
454
492
query_blocked_event_kind,
455
493
query_cache_hit_event_kind,
456
494
} )
0 commit comments