Skip to content

Commit ca0f287

Browse files
Make output of mmview more readable.
1 parent 560162a commit ca0f287

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

mmview/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ edition = "2018"
66
license = "MIT OR Apache-2.0"
77

88
[dependencies]
9-
measureme = { path = "../measureme" }
109
analyzeme = { path = "../analyzeme" }
10+
measureme = { path = "../measureme" }
1111
structopt = "0.2"

mmview/src/main.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use analyzeme::ProfilingData;
1+
use analyzeme::{Event, ProfilingData, Timestamp};
22
use std::error::Error;
33
use std::path::PathBuf;
4-
4+
use std::time::{Duration, SystemTime};
55
use structopt::StructOpt;
66

77
#[derive(StructOpt, Debug)]
@@ -18,15 +18,49 @@ fn main() -> Result<(), Box<dyn Error>> {
1818

1919
let data = ProfilingData::new(&opt.file_prefix)?;
2020

21+
let global_start_time = data.iter().map(|e| e.timestamp.start()).min().unwrap();
22+
2123
for event in data.iter() {
2224
if let Some(thread_id) = opt.thread_id {
2325
if event.thread_id != thread_id {
2426
continue;
2527
}
2628
}
2729

28-
println!("{:?}", event);
30+
print_event(&event.to_event(), global_start_time);
2931
}
3032

3133
Ok(())
3234
}
35+
36+
fn system_time_to_micros_since(t: SystemTime, since: SystemTime) -> u128 {
37+
t.duration_since(since)
38+
.unwrap_or(Duration::from_nanos(0))
39+
.as_micros()
40+
}
41+
42+
fn print_event(event: &Event<'_>, global_start_time: SystemTime) {
43+
let additional_data = event.additional_data.join(",");
44+
45+
let timestamp = match event.timestamp {
46+
Timestamp::Instant(t) => {
47+
format!("{} μs", system_time_to_micros_since(t, global_start_time))
48+
}
49+
Timestamp::Interval { start, end } => format!(
50+
"{} μs - {} μs",
51+
system_time_to_micros_since(start, global_start_time),
52+
system_time_to_micros_since(end, global_start_time)
53+
),
54+
};
55+
56+
println!(
57+
r#"{{
58+
kind: {},
59+
label: {},
60+
additional_data: [{}],
61+
timestamp: {},
62+
thread_id: {},
63+
}}"#,
64+
event.event_kind, event.label, additional_data, timestamp, event.thread_id
65+
);
66+
}

0 commit comments

Comments
 (0)