Skip to content

Commit a5049e1

Browse files
committed
internal: make non-zero times stand out in profile
1 parent 0875601 commit a5049e1

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

crates/profile/src/hprof.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::{
33
cell::RefCell,
44
collections::{BTreeMap, HashSet},
5-
env,
5+
env, fmt,
66
io::{stderr, Write},
77
sync::{
88
atomic::{AtomicBool, Ordering},
@@ -278,9 +278,9 @@ fn print(
278278
let detail = tree[curr].detail.as_ref().map(|it| format!(" @ {}", it)).unwrap_or_default();
279279
writeln!(
280280
out,
281-
"{}{:5}ms - {}{}",
281+
"{}{} - {}{}",
282282
current_indent,
283-
tree[curr].duration.as_millis(),
283+
ms(tree[curr].duration),
284284
tree[curr].label,
285285
detail,
286286
)
@@ -302,14 +302,25 @@ fn print(
302302
}
303303

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

310309
let unaccounted = tree[curr].duration - accounted_for;
311310
if tree.children(curr).next().is_some() && unaccounted > longer_than {
312-
writeln!(out, " {}{:5}ms - ???", current_indent, unaccounted.as_millis())
311+
writeln!(out, " {}{} - ???", current_indent, ms(unaccounted))
313312
.expect("printing profiling info");
314313
}
315314
}
315+
316+
#[allow(non_camel_case_types)]
317+
struct ms(Duration);
318+
319+
impl fmt::Display for ms {
320+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
321+
match self.0.as_millis() {
322+
0 => f.write_str(" 0 "),
323+
n => write!(f, "{:5}ms", n),
324+
}
325+
}
326+
}

0 commit comments

Comments
 (0)