Skip to content

Commit

Permalink
internal: make non-zero times stand out in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jul 31, 2021
1 parent 0875601 commit a5049e1
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions crates/profile/src/hprof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{
cell::RefCell,
collections::{BTreeMap, HashSet},
env,
env, fmt,
io::{stderr, Write},
sync::{
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -278,9 +278,9 @@ fn print(
let detail = tree[curr].detail.as_ref().map(|it| format!(" @ {}", it)).unwrap_or_default();
writeln!(
out,
"{}{:5}ms - {}{}",
"{}{} - {}{}",
current_indent,
tree[curr].duration.as_millis(),
ms(tree[curr].duration),
tree[curr].label,
detail,
)
Expand All @@ -302,14 +302,25 @@ fn print(
}

for (child_msg, (duration, count)) in short_children.iter() {
let millis = duration.as_millis();
writeln!(out, " {}{:5}ms - {} ({} calls)", current_indent, millis, child_msg, count)
writeln!(out, " {}{} - {} ({} calls)", current_indent, ms(*duration), child_msg, count)
.expect("printing profiling info");
}

let unaccounted = tree[curr].duration - accounted_for;
if tree.children(curr).next().is_some() && unaccounted > longer_than {
writeln!(out, " {}{:5}ms - ???", current_indent, unaccounted.as_millis())
writeln!(out, " {}{} - ???", current_indent, ms(unaccounted))
.expect("printing profiling info");
}
}

#[allow(non_camel_case_types)]
struct ms(Duration);

impl fmt::Display for ms {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0.as_millis() {
0 => f.write_str(" 0 "),
n => write!(f, "{:5}ms", n),
}
}
}

0 comments on commit a5049e1

Please sign in to comment.