Skip to content

Commit a713230

Browse files
authored
Merge pull request #1752 from Kobzol/self-profile-cache-metrics
Store and expose self profile cache metrics
2 parents 90a4cb0 + 59be9bb commit a713230

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

site/src/self_profile.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,60 @@ pub struct SelfProfileKey {
132132
pub scenario: database::Scenario,
133133
}
134134

135+
#[derive(Default)]
136+
pub struct SelfProfileCacheStats {
137+
hits: u64,
138+
misses: u64,
139+
}
140+
141+
impl SelfProfileCacheStats {
142+
pub fn get_hits(&self) -> u64 {
143+
self.hits
144+
}
145+
pub fn get_misses(&self) -> u64 {
146+
self.misses
147+
}
148+
149+
fn hit(&mut self) {
150+
self.hits += 1;
151+
}
152+
fn miss(&mut self) {
153+
self.misses += 1;
154+
}
155+
}
156+
135157
/// Stores a cache of N most recently used self profiles.
136158
/// The profiles are downloaded from S3 and analysed on each request to the detailed compare result
137159
/// page, but the post-processed results aren't very large in memory (~50 KiB), so it makes sense
138160
/// to cache them.
139161
pub struct SelfProfileCache {
140162
profiles: LruCache<SelfProfileKey, SelfProfileWithAnalysis>,
163+
stats: SelfProfileCacheStats,
141164
}
142165

143166
impl SelfProfileCache {
144167
pub fn new(cache_size: usize) -> Self {
145168
Self {
146169
profiles: LruCache::new(NonZeroUsize::new(cache_size).unwrap()),
170+
stats: Default::default(),
147171
}
148172
}
149173

174+
pub fn get_stats(&self) -> &SelfProfileCacheStats {
175+
&self.stats
176+
}
177+
150178
pub fn get(&mut self, key: &SelfProfileKey) -> Option<SelfProfileWithAnalysis> {
151-
self.profiles.get(key).cloned()
179+
match self.profiles.get(key) {
180+
Some(value) => {
181+
self.stats.hit();
182+
Some(value.clone())
183+
}
184+
None => {
185+
self.stats.miss();
186+
None
187+
}
188+
}
152189
}
153190

154191
pub fn insert(&mut self, key: SelfProfileKey, profile: SelfProfileWithAnalysis) {

site/src/server.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,26 @@ impl Server {
207207
queue_try_commits.set(missing_commits.iter().filter(|(c, _)| c.is_try()).count() as i64);
208208
r.register(Box::new(queue_try_commits)).unwrap();
209209

210+
// Stores cache hits and misses of the self profile cache
211+
{
212+
let cache = ctxt.self_profile_cache.lock();
213+
let self_profile_stats = cache.get_stats();
214+
let self_profile_cache_hits = prometheus::IntGauge::new(
215+
"rustc_perf_queue_self_profile_cache_hits",
216+
"self profile cache hits",
217+
)
218+
.unwrap();
219+
self_profile_cache_hits.set(self_profile_stats.get_hits() as i64);
220+
r.register(Box::new(self_profile_cache_hits)).unwrap();
221+
222+
let self_profile_cache_misses = prometheus::IntGauge::new(
223+
"rustc_perf_queue_self_profile_cache_misses",
224+
"self profile cache misses",
225+
)
226+
.unwrap();
227+
self_profile_cache_misses.set(self_profile_stats.get_misses() as i64);
228+
r.register(Box::new(self_profile_cache_misses)).unwrap();
229+
}
210230
if let Some(last_commit) = idx.commits().last().cloned() {
211231
let conn = ctxt.conn().await;
212232
let steps = conn.in_progress_steps(&ArtifactId::from(last_commit)).await;

0 commit comments

Comments
 (0)