Skip to content

Commit 8384a39

Browse files
committed
Add support for reading aggregated query cache hit counts
1 parent 59ea13c commit 8384a39

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

analyzeme/src/analysis.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{Event, EventPayload, ProfilingData, Timestamp};
22
use measureme::rustc::*;
3-
use rustc_hash::FxHashMap;
3+
use rustc_hash::{FxHashMap, FxHashSet};
44
use serde::{Deserialize, Serialize};
55
use std::borrow::Cow;
6-
use std::collections::BTreeMap;
6+
use std::collections::{BTreeMap};
77
use std::time::Duration;
88
use std::time::SystemTime;
99

@@ -133,12 +133,19 @@ impl ProfilingData {
133133
}
134134
};
135135

136+
// Remember if we found a `QUERY_CACHE_HIT_COUNT_EVENT_KIND` event at the end of the event
137+
// log for a given query. If yes, we need to avoid incrementing the query cache counts
138+
// if we encounter `QUERY_CACHE_HIT_EVENT_KIND`, to avoid double counting.
139+
let mut query_cache_hit_counts_found: FxHashSet<String> = Default::default();
140+
136141
for current_event in self.iter_full().rev() {
137142
match current_event.payload {
138143
EventPayload::Timestamp(Timestamp::Instant(_)) => {
139144
if &current_event.event_kind[..] == QUERY_CACHE_HIT_EVENT_KIND {
140145
record_event_data(&current_event.label, &|data| {
141-
data.number_of_cache_hits += 1;
146+
if !query_cache_hit_counts_found.contains(current_event.label.as_ref()) {
147+
data.number_of_cache_hits += 1;
148+
}
142149
data.invocation_count += 1;
143150
});
144151
}
@@ -254,12 +261,23 @@ impl ProfilingData {
254261
thread.stack.push(current_event)
255262
}
256263
EventPayload::Integer(value) => {
257-
if current_event.event_kind == ARTIFACT_SIZE_EVENT_KIND {
258-
// Dedup artifact size events according to their label
259-
artifact_sizes
260-
.entry(current_event.label.clone())
261-
.or_insert_with(|| ArtifactSize::new(current_event.label.into_owned()))
262-
.add_value(value);
264+
match current_event.event_kind.as_ref() {
265+
ARTIFACT_SIZE_EVENT_KIND => {
266+
// Dedup artifact size events according to their label
267+
artifact_sizes
268+
.entry(current_event.label.clone())
269+
.or_insert_with(|| ArtifactSize::new(current_event.label.into_owned()))
270+
.add_value(value);
271+
}
272+
// Aggregated query cache hit counts
273+
QUERY_CACHE_HIT_COUNT_EVENT_KIND => {
274+
record_event_data(&current_event.label, &|data| {
275+
assert_eq!(data.number_of_cache_hits, 0);
276+
data.number_of_cache_hits = value as usize;
277+
});
278+
query_cache_hit_counts_found.insert(current_event.label.into_owned());
279+
}
280+
_ => {}
263281
}
264282
}
265283
}

measureme/src/rustc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ pub const QUERY_BLOCKED_EVENT_KIND: &str = "QueryBlocked";
1212

1313
pub const QUERY_CACHE_HIT_EVENT_KIND: &str = "QueryCacheHit";
1414

15+
/// Aggregated count of query cache hits, stored as an integer event.
16+
pub const QUERY_CACHE_HIT_COUNT_EVENT_KIND: &str = "QueryCacheHitCount";
17+
1518
pub const ARTIFACT_SIZE_EVENT_KIND: &str = "ArtifactSize";

0 commit comments

Comments
 (0)