|
1 | 1 | use crate::{Event, EventPayload, ProfilingData, Timestamp}; |
2 | 2 | use measureme::rustc::*; |
3 | | -use rustc_hash::FxHashMap; |
| 3 | +use rustc_hash::{FxHashMap, FxHashSet}; |
4 | 4 | use serde::{Deserialize, Serialize}; |
5 | 5 | use std::borrow::Cow; |
6 | | -use std::collections::BTreeMap; |
| 6 | +use std::collections::{BTreeMap}; |
7 | 7 | use std::time::Duration; |
8 | 8 | use std::time::SystemTime; |
9 | 9 |
|
@@ -133,12 +133,19 @@ impl ProfilingData { |
133 | 133 | } |
134 | 134 | }; |
135 | 135 |
|
| 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 | + |
136 | 141 | for current_event in self.iter_full().rev() { |
137 | 142 | match current_event.payload { |
138 | 143 | EventPayload::Timestamp(Timestamp::Instant(_)) => { |
139 | 144 | if ¤t_event.event_kind[..] == QUERY_CACHE_HIT_EVENT_KIND { |
140 | 145 | record_event_data(¤t_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 | + } |
142 | 149 | data.invocation_count += 1; |
143 | 150 | }); |
144 | 151 | } |
@@ -254,12 +261,23 @@ impl ProfilingData { |
254 | 261 | thread.stack.push(current_event) |
255 | 262 | } |
256 | 263 | 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(¤t_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 | + _ => {} |
263 | 281 | } |
264 | 282 | } |
265 | 283 | } |
|
0 commit comments