Skip to content
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

Implement a self profiler #51657

Merged
merged 14 commits into from
Aug 3, 2018
Prev Previous commit
Next Next commit
Switch to markdown output
  • Loading branch information
wesleywiser committed Aug 2, 2018
commit 0f43800d10efd4e6255d375dad00be6b8ab6b5d7
27 changes: 15 additions & 12 deletions src/librustc/util/profiling.rs
Original file line number Diff line number Diff line change
@@ -90,25 +90,27 @@ impl CategoryData {
fn print(&self, lock: &mut StdoutLock) {
macro_rules! p {
($name:tt, $rustic_name:ident) => {
let (hits, total) = self.query_counts.$rustic_name;
let (hits, total) = if total > 0 {
(format!("{:.2}%", (((hits as f32) / (total as f32)) * 100.0)), total.to_string())
} else {
("".into(), "".into())
};

writeln!(
lock,
"{0: <15} \t\t {1: <15}ms",
"| {0: <16} | {1: <14} | {2: <14} | {3: <8} |",
$name,
self.times.$rustic_name / 1_000_000
self.times.$rustic_name / 1_000_000,
total,
hits
).unwrap();

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

writeln!(lock, "| Phase | Time (ms) | Queries | Hits (%) |").unwrap();
writeln!(lock, "| ---------------- | -------------- | -------------- | -------- |").unwrap();

p!("Parsing", parsing);
p!("Expansion", expansion);
p!("TypeChecking", type_checking);
@@ -222,6 +224,7 @@ impl SelfProfiler {
let crate_name = opts.crate_name.as_ref().map(|n| format!(" for {}", n)).unwrap_or_default();

writeln!(lock, "Self profiling results{}:", crate_name).unwrap();
writeln!(lock).unwrap();

self.data.print(&mut lock);