@@ -7,8 +7,21 @@ use std::rc::Rc;
77use std:: sync:: Mutex ;
88use std:: time:: Duration ;
99
10- use piet_common:: { kurbo , Color , RenderContext , Text , TextLayout , TextLayoutBuilder } ;
10+ use piet_common:: { Color , RenderContext , Text , TextLayout , TextLayoutBuilder , kurbo } ;
1111
12+ fn read_u8_vec ( inf : & mut File ) -> Option < Vec < u8 > > {
13+ let len = read_u64 ( inf) ?;
14+ let mut vec = Vec :: with_capacity ( len as usize ) ;
15+ for _ in 0 ..len {
16+ vec. push ( read_u8 ( inf) ?) ;
17+ }
18+ Some ( vec)
19+ }
20+ fn read_u8 ( inf : & mut File ) -> Option < u8 > {
21+ let mut bytes: [ u8 ; 1 ] = [ 0 ; 1 ] ;
22+ inf. read_exact ( & mut bytes) . ok ( ) ?;
23+ Some ( u8:: from_ne_bytes ( bytes) )
24+ }
1225fn read_u128 ( inf : & mut File ) -> Result < u128 , std:: io:: Error > {
1326 let mut bytes: [ u8 ; 16 ] = [ 0 ; 16 ] ;
1427 inf. read_exact ( & mut bytes) ?;
@@ -76,6 +89,19 @@ fn dump_free(
7689 Some ( ( ) )
7790}
7891
92+ fn dump_trace_record (
93+ _state : & mut State ,
94+ _rs : & mut ( ) ,
95+ now : Duration ,
96+ cycles : u64 ,
97+ msg : Rc < [ u8 ] > ,
98+ ) -> Option < ( ) > {
99+ let msg = String :: from_utf8_lossy ( & msg) ;
100+ println ! ( "\n [{:9?}] Cycles: {}, Message: {}" , now, cycles, msg) ;
101+
102+ Some ( ( ) )
103+ }
104+
79105// todo: this should use something more reasonable than a hash table
80106// for each node. let's measure the out-degree and see if a small
81107// array is better, to start.
@@ -526,19 +552,31 @@ fn render_free(
526552 Some ( ( ) )
527553}
528554
529- fn read_file < I , U , A , F , S > (
555+ fn render_trace_record (
556+ _state : & mut State ,
557+ _rs : & mut RenderState ,
558+ _now : Duration ,
559+ _cycles : u64 ,
560+ _msg : Rc < [ u8 ] > ,
561+ ) -> Option < ( ) > {
562+ Some ( ( ) )
563+ }
564+
565+ fn read_file < I , U , A , F , T , S > (
530566 state : & mut State ,
531567 mut handle_state : S ,
532568 handle_ident : I ,
533569 handle_unwind : U ,
534570 handle_alloc : A ,
535571 handle_free : F ,
572+ handle_trace_record : T ,
536573) -> Option < ( ) >
537574where
538575 I : Fn ( & mut State , & mut S , Duration , blake3:: Hash ) -> Option < ( ) > ,
539576 U : Fn ( & mut State , & mut S , Duration , Rc < [ u64 ] > ) -> Option < ( ) > ,
540577 A : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
541578 F : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
579+ T : Fn ( & mut State , & mut S , Duration , u64 , Rc < [ u8 ] > ) -> Option < ( ) > ,
542580{
543581 loop {
544582 let time = match read_u128 ( & mut state. inf ) {
@@ -584,6 +622,10 @@ where
584622 let trace = amt_trace. 1 . clone ( ) ;
585623 state. total -= amt;
586624 handle_free ( state, & mut handle_state, now, ptr, amt, trace) ?;
625+ } else if frame_id == 4 {
626+ let cycles = read_u64 ( & mut state. inf ) ?;
627+ let msg = read_u8_vec ( & mut state. inf ) ?. into ( ) ;
628+ handle_trace_record ( state, & mut handle_state, now, cycles, msg) ?;
587629 } else {
588630 return None ;
589631 }
@@ -683,6 +725,7 @@ fn spawn_render_thread(
683725 render_unwind,
684726 render_alloc,
685727 render_free,
728+ render_trace_record,
686729 ) ?;
687730 bar_ffmpeg. wait ( ) . ok ( ) ?;
688731 flame_ffmpeg. wait ( ) . ok ( ) ?;
@@ -739,6 +782,7 @@ fn dump_trace(mut state: State) {
739782 dump_unwind,
740783 dump_alloc,
741784 dump_free,
785+ dump_trace_record,
742786 ) ;
743787}
744788
@@ -755,6 +799,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
755799 |_, _, _, _| Some ( ( ) ) ,
756800 |_, _, _, _, _, _| Some ( ( ) ) ,
757801 |_, _, _, _, _, _| Some ( ( ) ) ,
802+ |_, _, _, _, _| Some ( ( ) ) ,
758803 ) {
759804 Some ( ( ) ) => ( ) ,
760805 None => {
@@ -794,6 +839,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
794839 |_, _, _, _| Some ( ( ) ) ,
795840 count_frame,
796841 count_frame,
842+ |_, _, _, _, _| Some ( ( ) ) ,
797843 ) ;
798844 if state. num_durations > 0 {
799845 ( * jobs. lock ( ) . unwrap ( ) ) . push ( ( * start_duration. lock ( ) . unwrap ( ) , state. max_duration ) ) ;
0 commit comments