Skip to content

Commit 2b8c513

Browse files
committed
Update trace_dump to handle trace records
- Supports only list_frames for now Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
1 parent ce9266a commit 2b8c513

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

src/trace_dump/main.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,21 @@ use std::rc::Rc;
2323
use std::sync::Mutex;
2424
use std::time::Duration;
2525

26-
use piet_common::{kurbo, Color, RenderContext, Text, TextLayout, TextLayoutBuilder};
26+
use piet_common::{Color, RenderContext, Text, TextLayout, TextLayoutBuilder, kurbo};
2727

28+
fn read_u8_vec(inf: &mut File) -> Option<Vec<u8>> {
29+
let len = read_u64(inf)?;
30+
let mut vec = Vec::with_capacity(len as usize);
31+
for _ in 0..len {
32+
vec.push(read_u8(inf)?);
33+
}
34+
Some(vec)
35+
}
36+
fn read_u8(inf: &mut File) -> Option<u8> {
37+
let mut bytes: [u8; 1] = [0; 1];
38+
inf.read_exact(&mut bytes).ok()?;
39+
Some(u8::from_ne_bytes(bytes))
40+
}
2841
fn read_u128(inf: &mut File) -> Result<u128, std::io::Error> {
2942
let mut bytes: [u8; 16] = [0; 16];
3043
inf.read_exact(&mut bytes)?;
@@ -92,6 +105,19 @@ fn dump_free(
92105
Some(())
93106
}
94107

108+
fn dump_trace_record(
109+
_state: &mut State,
110+
_rs: &mut (),
111+
now: Duration,
112+
cycles: u64,
113+
msg: Rc<[u8]>,
114+
) -> Option<()> {
115+
let msg = String::from_utf8_lossy(&msg);
116+
println!("\n[{:9?}] Cycles: {}, Message: {}", now, cycles, msg);
117+
118+
Some(())
119+
}
120+
95121
// todo: this should use something more reasonable than a hash table
96122
// for each node. let's measure the out-degree and see if a small
97123
// array is better, to start.
@@ -542,19 +568,31 @@ fn render_free(
542568
Some(())
543569
}
544570

545-
fn read_file<I, U, A, F, S>(
571+
fn render_trace_record(
572+
_state: &mut State,
573+
_rs: &mut RenderState,
574+
_now: Duration,
575+
_cycles: u64,
576+
_msg: Rc<[u8]>,
577+
) -> Option<()> {
578+
Some(())
579+
}
580+
581+
fn read_file<I, U, A, F, T, S>(
546582
state: &mut State,
547583
mut handle_state: S,
548584
handle_ident: I,
549585
handle_unwind: U,
550586
handle_alloc: A,
551587
handle_free: F,
588+
handle_trace_record: T,
552589
) -> Option<()>
553590
where
554591
I: Fn(&mut State, &mut S, Duration, blake3::Hash) -> Option<()>,
555592
U: Fn(&mut State, &mut S, Duration, Rc<[u64]>) -> Option<()>,
556593
A: Fn(&mut State, &mut S, Duration, u64, u64, Rc<[u64]>) -> Option<()>,
557594
F: Fn(&mut State, &mut S, Duration, u64, u64, Rc<[u64]>) -> Option<()>,
595+
T: Fn(&mut State, &mut S, Duration, u64, Rc<[u8]>) -> Option<()>,
558596
{
559597
loop {
560598
let time = match read_u128(&mut state.inf) {
@@ -600,6 +638,10 @@ where
600638
let trace = amt_trace.1.clone();
601639
state.total -= amt;
602640
handle_free(state, &mut handle_state, now, ptr, amt, trace)?;
641+
} else if frame_id == 4 {
642+
let cycles = read_u64(&mut state.inf)?;
643+
let msg = read_u8_vec(&mut state.inf)?.into();
644+
handle_trace_record(state, &mut handle_state, now, cycles, msg)?;
603645
} else {
604646
return None;
605647
}
@@ -699,6 +741,7 @@ fn spawn_render_thread(
699741
render_unwind,
700742
render_alloc,
701743
render_free,
744+
render_trace_record,
702745
)?;
703746
bar_ffmpeg.wait().ok()?;
704747
flame_ffmpeg.wait().ok()?;
@@ -755,6 +798,7 @@ fn dump_trace(mut state: State) {
755798
dump_unwind,
756799
dump_alloc,
757800
dump_free,
801+
dump_trace_record,
758802
);
759803
}
760804

@@ -771,6 +815,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
771815
|_, _, _, _| Some(()),
772816
|_, _, _, _, _, _| Some(()),
773817
|_, _, _, _, _, _| Some(()),
818+
|_, _, _, _, _| Some(()),
774819
) {
775820
Some(()) => (),
776821
None => {
@@ -810,6 +855,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
810855
|_, _, _, _| Some(()),
811856
count_frame,
812857
count_frame,
858+
|_, _, _, _, _| Some(()),
813859
);
814860
if state.num_durations > 0 {
815861
(*jobs.lock().unwrap()).push((*start_duration.lock().unwrap(), state.max_duration));

0 commit comments

Comments
 (0)