Skip to content

Add support for reading aggregated query cache hit counts #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions analyzeme/src/analysis.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<String> = Default::default();

for current_event in self.iter_full().rev() {
match current_event.payload {
EventPayload::Timestamp(Timestamp::Instant(_)) => {
if &current_event.event_kind[..] == QUERY_CACHE_HIT_EVENT_KIND {
record_event_data(&current_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;
});
}
Expand Down Expand Up @@ -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(&current_event.label, &|data| {
assert_eq!(data.number_of_cache_hits, 0);
data.number_of_cache_hits = value as usize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we assert that it was zero before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. All the cache counts should be at the end, and we read in .rev() order, but it would be better to check. That being said, the aggregated and per-query-invocation counters should be the same; if not, something is very wrong.. 😆 Added an assert.

});
query_cache_hit_counts_found.insert(current_event.label.into_owned());
}
_ => {}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions measureme/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";