diff options
| author | Ryan Levick <me@ryanlevick.com> | 2021-06-25 13:17:52 +0200 |
|---|---|---|
| committer | Ryan Levick <me@ryanlevick.com> | 2021-07-07 10:43:30 +0200 |
| commit | 6e33dce9c2d549f0c32f7940ffccd0f0de8af74e (patch) | |
| tree | 9a72ba9d8e4e317b71e409554ad8718848eca835 /compiler/rustc_data_structures/src | |
| parent | c5e344f7747dbd7e7d4b209e3c480deb5979a56f (diff) | |
| download | rust-6e33dce9c2d549f0c32f7940ffccd0f0de8af74e.tar.gz rust-6e33dce9c2d549f0c32f7940ffccd0f0de8af74e.zip | |
Profile incremental hashing
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/profiling.rs | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index 51f851dc946..531214bc40e 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -94,31 +94,34 @@ use std::process; use std::sync::Arc; use std::time::{Duration, Instant}; -use measureme::{EventId, EventIdBuilder, Profiler, SerializableString, StringId}; +pub use measureme::EventId; +use measureme::{EventIdBuilder, Profiler, SerializableString, StringId}; use parking_lot::RwLock; bitflags::bitflags! { struct EventFilter: u32 { - const GENERIC_ACTIVITIES = 1 << 0; - const QUERY_PROVIDERS = 1 << 1; - const QUERY_CACHE_HITS = 1 << 2; - const QUERY_BLOCKED = 1 << 3; - const INCR_CACHE_LOADS = 1 << 4; + const GENERIC_ACTIVITIES = 1 << 0; + const QUERY_PROVIDERS = 1 << 1; + const QUERY_CACHE_HITS = 1 << 2; + const QUERY_BLOCKED = 1 << 3; + const INCR_CACHE_LOADS = 1 << 4; - const QUERY_KEYS = 1 << 5; - const FUNCTION_ARGS = 1 << 6; - const LLVM = 1 << 7; + const QUERY_KEYS = 1 << 5; + const FUNCTION_ARGS = 1 << 6; + const LLVM = 1 << 7; + const INCR_RESULT_HASHING = 1 << 8; const DEFAULT = Self::GENERIC_ACTIVITIES.bits | Self::QUERY_PROVIDERS.bits | Self::QUERY_BLOCKED.bits | - Self::INCR_CACHE_LOADS.bits; + Self::INCR_CACHE_LOADS.bits | + Self::INCR_RESULT_HASHING.bits; const ARGS = Self::QUERY_KEYS.bits | Self::FUNCTION_ARGS.bits; } } -// keep this in sync with the `-Z self-profile-events` help message in librustc_session/options.rs +// keep this in sync with the `-Z self-profile-events` help message in rustc_session/options.rs const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[ ("none", EventFilter::empty()), ("all", EventFilter::all()), @@ -132,6 +135,7 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[ ("function-args", EventFilter::FUNCTION_ARGS), ("args", EventFilter::ARGS), ("llvm", EventFilter::LLVM), + ("incr-result-hashing", EventFilter::INCR_RESULT_HASHING), ]; /// Something that uniquely identifies a query invocation. @@ -248,6 +252,15 @@ impl SelfProfilerRef { }) } + /// Start profiling with some event filter for a given event. Profiling continues until the + /// TimingGuard returned from this call is dropped. + #[inline(always)] + pub fn generic_activity_with_event(&self, event_id: EventId) -> TimingGuard<'_> { + self.exec(EventFilter::GENERIC_ACTIVITIES, |profiler| { + TimingGuard::start(profiler, profiler.generic_activity_event_kind, event_id) + }) + } + /// Start profiling a generic activity. Profiling continues until the /// TimingGuard returned from this call is dropped. #[inline(always)] @@ -337,6 +350,19 @@ impl SelfProfilerRef { }) } + /// Start profiling how long it takes to hash query results for incremental compilation. + /// Profiling continues until the TimingGuard returned from this call is dropped. + #[inline(always)] + pub fn incr_result_hashing(&self) -> TimingGuard<'_> { + self.exec(EventFilter::INCR_RESULT_HASHING, |profiler| { + TimingGuard::start( + profiler, + profiler.incremental_result_hashing_event_kind, + EventId::INVALID, + ) + }) + } + #[inline(always)] fn instant_query_event( &self, @@ -364,6 +390,10 @@ impl SelfProfilerRef { } } + pub fn get_or_alloc_cached_string(&self, s: &'static str) -> Option<StringId> { + self.profiler.as_ref().map(|p| p.get_or_alloc_cached_string(s)) + } + #[inline] pub fn enabled(&self) -> bool { self.profiler.is_some() @@ -388,6 +418,7 @@ pub struct SelfProfiler { query_event_kind: StringId, generic_activity_event_kind: StringId, incremental_load_result_event_kind: StringId, + incremental_result_hashing_event_kind: StringId, query_blocked_event_kind: StringId, query_cache_hit_event_kind: StringId, } @@ -408,6 +439,8 @@ impl SelfProfiler { let query_event_kind = profiler.alloc_string("Query"); let generic_activity_event_kind = profiler.alloc_string("GenericActivity"); let incremental_load_result_event_kind = profiler.alloc_string("IncrementalLoadResult"); + let incremental_result_hashing_event_kind = + profiler.alloc_string("IncrementalResultHashing"); let query_blocked_event_kind = profiler.alloc_string("QueryBlocked"); let query_cache_hit_event_kind = profiler.alloc_string("QueryCacheHit"); @@ -451,6 +484,7 @@ impl SelfProfiler { query_event_kind, generic_activity_event_kind, incremental_load_result_event_kind, + incremental_result_hashing_event_kind, query_blocked_event_kind, query_cache_hit_event_kind, }) |
