Skip to content

Commit

Permalink
Add self profiler events for loading incremental query results from disk
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Feb 11, 2019
1 parent 57d7cfc commit ae044ee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/librustc/ty/query/plumbing.rs
Expand Up @@ -436,7 +436,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// First we try to load the result from the on-disk cache
let result = if Q::cache_on_disk(self.global_tcx(), key.clone()) &&
self.sess.opts.debugging_opts.incremental_queries {
self.sess.profiler(|p| p.incremental_load_result_start(Q::NAME));
let result = Q::try_load_from_disk(self.global_tcx(), prev_dep_node_index);
self.sess.profiler(|p| p.incremental_load_result_end(Q::NAME));

// We always expect to find a cached result for things that
// can be forced from DepNode.
Expand Down
32 changes: 29 additions & 3 deletions src/librustc/util/profiling.rs
Expand Up @@ -25,16 +25,24 @@ pub enum ProfilerEvent {
GenericActivityEnd { category: ProfileCategory, time: Instant },
QueryCacheHit { query_name: &'static str, category: ProfileCategory },
QueryCount { query_name: &'static str, category: ProfileCategory, count: usize },
IncrementalLoadResultStart { query_name: &'static str, time: Instant },
IncrementalLoadResultEnd { query_name: &'static str, time: Instant },
}

impl ProfilerEvent {
fn is_start_event(&self) -> bool {
use self::ProfilerEvent::*;

match self {
QueryStart { .. } | GenericActivityStart { .. } => true,
QueryEnd { .. } | GenericActivityEnd { .. } |
QueryCacheHit { .. } | QueryCount { .. } => false,
QueryStart { .. } |
GenericActivityStart { .. } |
IncrementalLoadResultStart { .. } => true,

QueryEnd { .. } |
GenericActivityEnd { .. } |
QueryCacheHit { .. } |
QueryCount { .. } |
IncrementalLoadResultEnd { .. } => false,
}
}
}
Expand Down Expand Up @@ -225,6 +233,22 @@ impl SelfProfiler {
})
}

#[inline]
pub fn incremental_load_result_start(&mut self, query_name: &'static str) {
self.record(ProfilerEvent::IncrementalLoadResultStart {
query_name,
time: Instant::now(),
})
}

#[inline]
pub fn incremental_load_result_end(&mut self, query_name: &'static str) {
self.record(ProfilerEvent::IncrementalLoadResultEnd {
query_name,
time: Instant::now(),
})
}

#[inline]
fn record(&mut self, event: ProfilerEvent) {
let thread_id = std::thread::current().id();
Expand Down Expand Up @@ -317,6 +341,8 @@ impl SelfProfiler {
result_data.query_cache_stats.entry(query_name).or_insert((0, 0));
*totals += *count as u64;
},
//we don't summarize incremental load result events in the simple output mode
IncrementalLoadResultStart { .. } | IncrementalLoadResultEnd { .. } => { },
}
}

Expand Down

0 comments on commit ae044ee

Please sign in to comment.