Skip to content

Store and expose self profile cache metrics #1752

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
Nov 24, 2023
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
39 changes: 38 additions & 1 deletion site/src/self_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,60 @@ pub struct SelfProfileKey {
pub scenario: database::Scenario,
}

#[derive(Default)]
pub struct SelfProfileCacheStats {
hits: u64,
misses: u64,
}

impl SelfProfileCacheStats {
pub fn get_hits(&self) -> u64 {
self.hits
}
pub fn get_misses(&self) -> u64 {
self.misses
}

fn hit(&mut self) {
self.hits += 1;
}
fn miss(&mut self) {
self.misses += 1;
}
}

/// Stores a cache of N most recently used self profiles.
/// The profiles are downloaded from S3 and analysed on each request to the detailed compare result
/// page, but the post-processed results aren't very large in memory (~50 KiB), so it makes sense
/// to cache them.
pub struct SelfProfileCache {
profiles: LruCache<SelfProfileKey, SelfProfileWithAnalysis>,
stats: SelfProfileCacheStats,
}

impl SelfProfileCache {
pub fn new(cache_size: usize) -> Self {
Self {
profiles: LruCache::new(NonZeroUsize::new(cache_size).unwrap()),
stats: Default::default(),
}
}

pub fn get_stats(&self) -> &SelfProfileCacheStats {
&self.stats
}

pub fn get(&mut self, key: &SelfProfileKey) -> Option<SelfProfileWithAnalysis> {
self.profiles.get(key).cloned()
match self.profiles.get(key) {
Some(value) => {
self.stats.hit();
Some(value.clone())
}
None => {
self.stats.miss();
None
}
}
}

pub fn insert(&mut self, key: SelfProfileKey, profile: SelfProfileWithAnalysis) {
Expand Down
20 changes: 20 additions & 0 deletions site/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ impl Server {
queue_try_commits.set(missing_commits.iter().filter(|(c, _)| c.is_try()).count() as i64);
r.register(Box::new(queue_try_commits)).unwrap();

// Stores cache hits and misses of the self profile cache
{
let cache = ctxt.self_profile_cache.lock();
let self_profile_stats = cache.get_stats();
let self_profile_cache_hits = prometheus::IntGauge::new(
"rustc_perf_queue_self_profile_cache_hits",
"self profile cache hits",
)
.unwrap();
self_profile_cache_hits.set(self_profile_stats.get_hits() as i64);
r.register(Box::new(self_profile_cache_hits)).unwrap();

let self_profile_cache_misses = prometheus::IntGauge::new(
"rustc_perf_queue_self_profile_cache_misses",
"self profile cache misses",
)
.unwrap();
self_profile_cache_misses.set(self_profile_stats.get_misses() as i64);
r.register(Box::new(self_profile_cache_misses)).unwrap();
}
if let Some(last_commit) = idx.commits().last().cloned() {
let conn = ctxt.conn().await;
let steps = conn.in_progress_steps(&ArtifactId::from(last_commit)).await;
Expand Down