@@ -23,8 +23,21 @@ use std::rc::Rc;
2323use std:: sync:: Mutex ;
2424use 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+ }
2841fn 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,13 @@ fn dump_free(
92105 Some ( ( ) )
93106}
94107
108+ fn dump_trace_record ( _state : & mut State , _rs : & mut ( ) , now : Duration , msg : Rc < [ u8 ] > ) -> Option < ( ) > {
109+ let msg = String :: from_utf8_lossy ( & msg) ;
110+ println ! ( "\n [{:9?}] {}" , now, msg) ;
111+
112+ Some ( ( ) )
113+ }
114+
95115// todo: this should use something more reasonable than a hash table
96116// for each node. let's measure the out-degree and see if a small
97117// array is better, to start.
@@ -542,19 +562,30 @@ fn render_free(
542562 Some ( ( ) )
543563}
544564
545- fn read_file < I , U , A , F , S > (
565+ fn render_trace_record (
566+ _state : & mut State ,
567+ _rs : & mut RenderState ,
568+ _now : Duration ,
569+ _msg : Rc < [ u8 ] > ,
570+ ) -> Option < ( ) > {
571+ Some ( ( ) )
572+ }
573+
574+ fn read_file < I , U , A , F , T , S > (
546575 state : & mut State ,
547576 mut handle_state : S ,
548577 handle_ident : I ,
549578 handle_unwind : U ,
550579 handle_alloc : A ,
551580 handle_free : F ,
581+ handle_trace_record : T ,
552582) -> Option < ( ) >
553583where
554584 I : Fn ( & mut State , & mut S , Duration , blake3:: Hash ) -> Option < ( ) > ,
555585 U : Fn ( & mut State , & mut S , Duration , Rc < [ u64 ] > ) -> Option < ( ) > ,
556586 A : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
557587 F : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
588+ T : Fn ( & mut State , & mut S , Duration , Rc < [ u8 ] > ) -> Option < ( ) > ,
558589{
559590 loop {
560591 let time = match read_u128 ( & mut state. inf ) {
@@ -600,6 +631,9 @@ where
600631 let trace = amt_trace. 1 . clone ( ) ;
601632 state. total -= amt;
602633 handle_free ( state, & mut handle_state, now, ptr, amt, trace) ?;
634+ } else if frame_id == 4 {
635+ let msg = read_u8_vec ( & mut state. inf ) ?. into ( ) ;
636+ handle_trace_record ( state, & mut handle_state, now, msg) ?;
603637 } else {
604638 return None ;
605639 }
@@ -699,6 +733,7 @@ fn spawn_render_thread(
699733 render_unwind,
700734 render_alloc,
701735 render_free,
736+ render_trace_record,
702737 ) ?;
703738 bar_ffmpeg. wait ( ) . ok ( ) ?;
704739 flame_ffmpeg. wait ( ) . ok ( ) ?;
@@ -755,6 +790,7 @@ fn dump_trace(mut state: State) {
755790 dump_unwind,
756791 dump_alloc,
757792 dump_free,
793+ dump_trace_record,
758794 ) ;
759795}
760796
@@ -771,6 +807,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
771807 |_, _, _, _| Some ( ( ) ) ,
772808 |_, _, _, _, _, _| Some ( ( ) ) ,
773809 |_, _, _, _, _, _| Some ( ( ) ) ,
810+ |_, _, _, _| Some ( ( ) ) ,
774811 ) {
775812 Some ( ( ) ) => ( ) ,
776813 None => {
@@ -810,6 +847,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
810847 |_, _, _, _| Some ( ( ) ) ,
811848 count_frame,
812849 count_frame,
850+ |_, _, _, _| Some ( ( ) ) ,
813851 ) ;
814852 if state. num_durations > 0 {
815853 ( * jobs. lock ( ) . unwrap ( ) ) . push ( ( * start_duration. lock ( ) . unwrap ( ) , state. max_duration ) ) ;
0 commit comments