@@ -94,31 +94,34 @@ use std::process;
9494use std:: sync:: Arc ;
9595use std:: time:: { Duration , Instant } ;
9696
97- use measureme:: { EventId , EventIdBuilder , Profiler , SerializableString , StringId } ;
97+ pub use measureme:: EventId ;
98+ use measureme:: { EventIdBuilder , Profiler , SerializableString , StringId } ;
9899use parking_lot:: RwLock ;
99100
100101bitflags:: bitflags! {
101102 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 ;
107108
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 ;
111113
112114 const DEFAULT = Self :: GENERIC_ACTIVITIES . bits |
113115 Self :: QUERY_PROVIDERS . bits |
114116 Self :: QUERY_BLOCKED . bits |
115- Self :: INCR_CACHE_LOADS . bits;
117+ Self :: INCR_CACHE_LOADS . bits |
118+ Self :: INCR_RESULT_HASHING . bits;
116119
117120 const ARGS = Self :: QUERY_KEYS . bits | Self :: FUNCTION_ARGS . bits;
118121 }
119122}
120123
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
122125const EVENT_FILTERS_BY_NAME : & [ ( & str , EventFilter ) ] = & [
123126 ( "none" , EventFilter :: empty ( ) ) ,
124127 ( "all" , EventFilter :: all ( ) ) ,
@@ -132,6 +135,7 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
132135 ( "function-args" , EventFilter :: FUNCTION_ARGS ) ,
133136 ( "args" , EventFilter :: ARGS ) ,
134137 ( "llvm" , EventFilter :: LLVM ) ,
138+ ( "incr-result-hashing" , EventFilter :: INCR_RESULT_HASHING ) ,
135139] ;
136140
137141/// Something that uniquely identifies a query invocation.
@@ -248,6 +252,15 @@ impl SelfProfilerRef {
248252 } )
249253 }
250254
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+
251264 /// Start profiling a generic activity. Profiling continues until the
252265 /// TimingGuard returned from this call is dropped.
253266 #[ inline( always) ]
@@ -337,6 +350,19 @@ impl SelfProfilerRef {
337350 } )
338351 }
339352
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+
340366 #[ inline( always) ]
341367 fn instant_query_event (
342368 & self ,
@@ -364,6 +390,14 @@ impl SelfProfilerRef {
364390 }
365391 }
366392
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+
367401 #[ inline]
368402 pub fn enabled ( & self ) -> bool {
369403 self . profiler . is_some ( )
@@ -388,6 +422,7 @@ pub struct SelfProfiler {
388422 query_event_kind : StringId ,
389423 generic_activity_event_kind : StringId ,
390424 incremental_load_result_event_kind : StringId ,
425+ incremental_result_hashing_event_kind : StringId ,
391426 query_blocked_event_kind : StringId ,
392427 query_cache_hit_event_kind : StringId ,
393428}
@@ -408,6 +443,8 @@ impl SelfProfiler {
408443 let query_event_kind = profiler. alloc_string ( "Query" ) ;
409444 let generic_activity_event_kind = profiler. alloc_string ( "GenericActivity" ) ;
410445 let incremental_load_result_event_kind = profiler. alloc_string ( "IncrementalLoadResult" ) ;
446+ let incremental_result_hashing_event_kind =
447+ profiler. alloc_string ( "IncrementalResultHashing" ) ;
411448 let query_blocked_event_kind = profiler. alloc_string ( "QueryBlocked" ) ;
412449 let query_cache_hit_event_kind = profiler. alloc_string ( "QueryCacheHit" ) ;
413450
@@ -451,6 +488,7 @@ impl SelfProfiler {
451488 query_event_kind,
452489 generic_activity_event_kind,
453490 incremental_load_result_event_kind,
491+ incremental_result_hashing_event_kind,
454492 query_blocked_event_kind,
455493 query_cache_hit_event_kind,
456494 } )
0 commit comments