Skip to content

Commit

Permalink
Basic incremental stats
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Aug 2, 2018
1 parent 45482c6 commit 177776d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
17 changes: 15 additions & 2 deletions src/librustc/ty/query/plumbing.rs
Expand Up @@ -118,6 +118,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
let mut lock = cache.borrow_mut();
if let Some(value) = lock.results.get(key) {
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
tcx.sess.profiler(|p| {
p.record_query(Q::CATEGORY);
p.record_query_hit(Q::CATEGORY);
});

let result = Ok((value.value.clone(), value.index));
return TryGetJob::JobCompleted(result);
}
Expand Down Expand Up @@ -379,7 +384,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

if dep_node.kind.is_anon() {
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
self.sess.profiler(|p| {
p.start_activity(Q::CATEGORY);
p.record_query(Q::CATEGORY);
});

let res = job.start(self, |tcx| {
tcx.dep_graph.with_anon_task(dep_node.kind, || {
Expand All @@ -404,6 +412,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
if !dep_node.kind.is_input() {
if let Some(dep_node_index) = self.try_mark_green_and_read(&dep_node) {
profq_msg!(self, ProfileQueriesMsg::CacheHit);
self.sess.profiler(|p| p.record_query_hit(Q::CATEGORY));

return self.load_from_disk_and_cache_in_memory::<Q>(key,
job,
dep_node_index,
Expand Down Expand Up @@ -525,7 +535,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
key, dep_node);

profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
self.sess.profiler(|p| {
p.start_activity(Q::CATEGORY);
p.record_query(Q::CATEGORY);
});

let res = job.start(self, |tcx| {
if dep_node.kind.is_eval_always() {
Expand Down
47 changes: 40 additions & 7 deletions src/librustc/util/profiling.rs
Expand Up @@ -76,23 +76,46 @@ impl<T> Categories<T> {

struct CategoryData {
times: Categories<u64>,
query_counts: Categories<(u64, u64)>,
}

impl CategoryData {
fn new() -> CategoryData {
CategoryData {
times: Categories::new(),
query_counts: Categories::new(),
}
}

fn print(&self, lock: &mut StdoutLock) {
writeln!(lock, "{0: <15} \t\t {1: <15}", "Parsing", self.times.parsing / 1_000_000).unwrap();
writeln!(lock, "{0: <15} \t\t {1: <15}", "Expansion", self.times.expansion / 1_000_000).unwrap();
writeln!(lock, "{0: <15} \t\t {1: <15}", "TypeChecking", self.times.type_checking / 1_000_000).unwrap();
writeln!(lock, "{0: <15} \t\t {1: <15}", "BorrowChecking", self.times.borrow_checking / 1_000_000).unwrap();
writeln!(lock, "{0: <15} \t\t {1: <15}", "Codegen", self.times.codegen / 1_000_000).unwrap();
writeln!(lock, "{0: <15} \t\t {1: <15}", "Linking", self.times.linking / 1_000_000).unwrap();
writeln!(lock, "{0: <15} \t\t {1: <15}", "Other", self.times.other / 1_000_000).unwrap();
macro_rules! p {
($name:tt, $rustic_name:ident) => {
writeln!(
lock,
"{0: <15} \t\t {1: <15}",
$name,
self.times.$rustic_name / 1_000_000
).unwrap();

let (hits, total) = self.query_counts.$rustic_name;
if total > 0 {
writeln!(
lock,
"\t{} hits {} queries",
hits,
total
).unwrap();
}
};
}

p!("Parsing", parsing);
p!("Expansion", expansion);
p!("TypeChecking", type_checking);
p!("BorrowChecking", borrow_checking);
p!("Codegen", codegen);
p!("Linking", linking);
p!("Other", other);
}
}

Expand Down Expand Up @@ -147,6 +170,16 @@ impl SelfProfiler {
self.timer_stack.push(category);
}

pub fn record_query(&mut self, category: ProfileCategory) {
let (hits, total) = *self.data.query_counts.get(category);
self.data.query_counts.set(category, (hits, total + 1));
}

pub fn record_query_hit(&mut self, category: ProfileCategory) {
let (hits, total) = *self.data.query_counts.get(category);
self.data.query_counts.set(category, (hits + 1, total));
}

pub fn end_activity(&mut self, category: ProfileCategory) {
match self.timer_stack.pop() {
None => bug!("end_activity() was called but there was no running activity"),
Expand Down

0 comments on commit 177776d

Please sign in to comment.