diff --git a/analyzeme/src/analysis.rs b/analyzeme/src/analysis.rs index 2d1948a..d7abb2d 100644 --- a/analyzeme/src/analysis.rs +++ b/analyzeme/src/analysis.rs @@ -1,9 +1,9 @@ use crate::{Event, EventPayload, ProfilingData, Timestamp}; use measureme::rustc::*; -use rustc_hash::FxHashMap; +use rustc_hash::{FxHashMap, FxHashSet}; use serde::{Deserialize, Serialize}; use std::borrow::Cow; -use std::collections::BTreeMap; +use std::collections::{BTreeMap}; use std::time::Duration; use std::time::SystemTime; @@ -133,12 +133,19 @@ impl ProfilingData { } }; + // Remember if we found a `QUERY_CACHE_HIT_COUNT_EVENT_KIND` event at the end of the event + // log for a given query. If yes, we need to avoid incrementing the query cache counts + // if we encounter `QUERY_CACHE_HIT_EVENT_KIND`, to avoid double counting. + let mut query_cache_hit_counts_found: FxHashSet = Default::default(); + for current_event in self.iter_full().rev() { match current_event.payload { EventPayload::Timestamp(Timestamp::Instant(_)) => { if ¤t_event.event_kind[..] == QUERY_CACHE_HIT_EVENT_KIND { record_event_data(¤t_event.label, &|data| { - data.number_of_cache_hits += 1; + if !query_cache_hit_counts_found.contains(current_event.label.as_ref()) { + data.number_of_cache_hits += 1; + } data.invocation_count += 1; }); } @@ -254,12 +261,23 @@ impl ProfilingData { thread.stack.push(current_event) } EventPayload::Integer(value) => { - if current_event.event_kind == ARTIFACT_SIZE_EVENT_KIND { - // Dedup artifact size events according to their label - artifact_sizes - .entry(current_event.label.clone()) - .or_insert_with(|| ArtifactSize::new(current_event.label.into_owned())) - .add_value(value); + match current_event.event_kind.as_ref() { + ARTIFACT_SIZE_EVENT_KIND => { + // Dedup artifact size events according to their label + artifact_sizes + .entry(current_event.label.clone()) + .or_insert_with(|| ArtifactSize::new(current_event.label.into_owned())) + .add_value(value); + } + // Aggregated query cache hit counts + QUERY_CACHE_HIT_COUNT_EVENT_KIND => { + record_event_data(¤t_event.label, &|data| { + assert_eq!(data.number_of_cache_hits, 0); + data.number_of_cache_hits = value as usize; + }); + query_cache_hit_counts_found.insert(current_event.label.into_owned()); + } + _ => {} } } } diff --git a/measureme/src/rustc.rs b/measureme/src/rustc.rs index 1198656..c3a4417 100644 --- a/measureme/src/rustc.rs +++ b/measureme/src/rustc.rs @@ -12,4 +12,7 @@ pub const QUERY_BLOCKED_EVENT_KIND: &str = "QueryBlocked"; pub const QUERY_CACHE_HIT_EVENT_KIND: &str = "QueryCacheHit"; +/// Aggregated count of query cache hits, stored as an integer event. +pub const QUERY_CACHE_HIT_COUNT_EVENT_KIND: &str = "QueryCacheHitCount"; + pub const ARTIFACT_SIZE_EVENT_KIND: &str = "ArtifactSize";