Skip to content

Commit 177776d

Browse files
committed
Basic incremental stats
1 parent 45482c6 commit 177776d

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

src/librustc/ty/query/plumbing.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
118118
let mut lock = cache.borrow_mut();
119119
if let Some(value) = lock.results.get(key) {
120120
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
121+
tcx.sess.profiler(|p| {
122+
p.record_query(Q::CATEGORY);
123+
p.record_query_hit(Q::CATEGORY);
124+
});
125+
121126
let result = Ok((value.value.clone(), value.index));
122127
return TryGetJob::JobCompleted(result);
123128
}
@@ -379,7 +384,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
379384

380385
if dep_node.kind.is_anon() {
381386
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
382-
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
387+
self.sess.profiler(|p| {
388+
p.start_activity(Q::CATEGORY);
389+
p.record_query(Q::CATEGORY);
390+
});
383391

384392
let res = job.start(self, |tcx| {
385393
tcx.dep_graph.with_anon_task(dep_node.kind, || {
@@ -404,6 +412,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
404412
if !dep_node.kind.is_input() {
405413
if let Some(dep_node_index) = self.try_mark_green_and_read(&dep_node) {
406414
profq_msg!(self, ProfileQueriesMsg::CacheHit);
415+
self.sess.profiler(|p| p.record_query_hit(Q::CATEGORY));
416+
407417
return self.load_from_disk_and_cache_in_memory::<Q>(key,
408418
job,
409419
dep_node_index,
@@ -525,7 +535,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
525535
key, dep_node);
526536

527537
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
528-
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
538+
self.sess.profiler(|p| {
539+
p.start_activity(Q::CATEGORY);
540+
p.record_query(Q::CATEGORY);
541+
});
529542

530543
let res = job.start(self, |tcx| {
531544
if dep_node.kind.is_eval_always() {

src/librustc/util/profiling.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,46 @@ impl<T> Categories<T> {
7676

7777
struct CategoryData {
7878
times: Categories<u64>,
79+
query_counts: Categories<(u64, u64)>,
7980
}
8081

8182
impl CategoryData {
8283
fn new() -> CategoryData {
8384
CategoryData {
8485
times: Categories::new(),
86+
query_counts: Categories::new(),
8587
}
8688
}
8789

8890
fn print(&self, lock: &mut StdoutLock) {
89-
writeln!(lock, "{0: <15} \t\t {1: <15}", "Parsing", self.times.parsing / 1_000_000).unwrap();
90-
writeln!(lock, "{0: <15} \t\t {1: <15}", "Expansion", self.times.expansion / 1_000_000).unwrap();
91-
writeln!(lock, "{0: <15} \t\t {1: <15}", "TypeChecking", self.times.type_checking / 1_000_000).unwrap();
92-
writeln!(lock, "{0: <15} \t\t {1: <15}", "BorrowChecking", self.times.borrow_checking / 1_000_000).unwrap();
93-
writeln!(lock, "{0: <15} \t\t {1: <15}", "Codegen", self.times.codegen / 1_000_000).unwrap();
94-
writeln!(lock, "{0: <15} \t\t {1: <15}", "Linking", self.times.linking / 1_000_000).unwrap();
95-
writeln!(lock, "{0: <15} \t\t {1: <15}", "Other", self.times.other / 1_000_000).unwrap();
91+
macro_rules! p {
92+
($name:tt, $rustic_name:ident) => {
93+
writeln!(
94+
lock,
95+
"{0: <15} \t\t {1: <15}",
96+
$name,
97+
self.times.$rustic_name / 1_000_000
98+
).unwrap();
99+
100+
let (hits, total) = self.query_counts.$rustic_name;
101+
if total > 0 {
102+
writeln!(
103+
lock,
104+
"\t{} hits {} queries",
105+
hits,
106+
total
107+
).unwrap();
108+
}
109+
};
110+
}
111+
112+
p!("Parsing", parsing);
113+
p!("Expansion", expansion);
114+
p!("TypeChecking", type_checking);
115+
p!("BorrowChecking", borrow_checking);
116+
p!("Codegen", codegen);
117+
p!("Linking", linking);
118+
p!("Other", other);
96119
}
97120
}
98121

@@ -147,6 +170,16 @@ impl SelfProfiler {
147170
self.timer_stack.push(category);
148171
}
149172

173+
pub fn record_query(&mut self, category: ProfileCategory) {
174+
let (hits, total) = *self.data.query_counts.get(category);
175+
self.data.query_counts.set(category, (hits, total + 1));
176+
}
177+
178+
pub fn record_query_hit(&mut self, category: ProfileCategory) {
179+
let (hits, total) = *self.data.query_counts.get(category);
180+
self.data.query_counts.set(category, (hits + 1, total));
181+
}
182+
150183
pub fn end_activity(&mut self, category: ProfileCategory) {
151184
match self.timer_stack.pop() {
152185
None => bug!("end_activity() was called but there was no running activity"),

0 commit comments

Comments
 (0)