@@ -23,8 +23,21 @@ use std::rc::Rc;
23
23
use std:: sync:: Mutex ;
24
24
use std:: time:: Duration ;
25
25
26
- use piet_common:: { kurbo , Color , RenderContext , Text , TextLayout , TextLayoutBuilder } ;
26
+ use piet_common:: { Color , RenderContext , Text , TextLayout , TextLayoutBuilder , kurbo } ;
27
27
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
+ }
28
41
fn read_u128 ( inf : & mut File ) -> Result < u128 , std:: io:: Error > {
29
42
let mut bytes: [ u8 ; 16 ] = [ 0 ; 16 ] ;
30
43
inf. read_exact ( & mut bytes) ?;
@@ -92,6 +105,19 @@ fn dump_free(
92
105
Some ( ( ) )
93
106
}
94
107
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
+
95
121
// todo: this should use something more reasonable than a hash table
96
122
// for each node. let's measure the out-degree and see if a small
97
123
// array is better, to start.
@@ -542,19 +568,31 @@ fn render_free(
542
568
Some ( ( ) )
543
569
}
544
570
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 > (
546
582
state : & mut State ,
547
583
mut handle_state : S ,
548
584
handle_ident : I ,
549
585
handle_unwind : U ,
550
586
handle_alloc : A ,
551
587
handle_free : F ,
588
+ handle_trace_record : T ,
552
589
) -> Option < ( ) >
553
590
where
554
591
I : Fn ( & mut State , & mut S , Duration , blake3:: Hash ) -> Option < ( ) > ,
555
592
U : Fn ( & mut State , & mut S , Duration , Rc < [ u64 ] > ) -> Option < ( ) > ,
556
593
A : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
557
594
F : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
595
+ T : Fn ( & mut State , & mut S , Duration , u64 , Rc < [ u8 ] > ) -> Option < ( ) > ,
558
596
{
559
597
loop {
560
598
let time = match read_u128 ( & mut state. inf ) {
@@ -600,6 +638,10 @@ where
600
638
let trace = amt_trace. 1 . clone ( ) ;
601
639
state. total -= amt;
602
640
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) ?;
603
645
} else {
604
646
return None ;
605
647
}
@@ -699,6 +741,7 @@ fn spawn_render_thread(
699
741
render_unwind,
700
742
render_alloc,
701
743
render_free,
744
+ render_trace_record,
702
745
) ?;
703
746
bar_ffmpeg. wait ( ) . ok ( ) ?;
704
747
flame_ffmpeg. wait ( ) . ok ( ) ?;
@@ -755,6 +798,7 @@ fn dump_trace(mut state: State) {
755
798
dump_unwind,
756
799
dump_alloc,
757
800
dump_free,
801
+ dump_trace_record,
758
802
) ;
759
803
}
760
804
@@ -771,6 +815,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
771
815
|_, _, _, _| Some ( ( ) ) ,
772
816
|_, _, _, _, _, _| Some ( ( ) ) ,
773
817
|_, _, _, _, _, _| Some ( ( ) ) ,
818
+ |_, _, _, _, _| Some ( ( ) ) ,
774
819
) {
775
820
Some ( ( ) ) => ( ) ,
776
821
None => {
@@ -810,6 +855,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
810
855
|_, _, _, _| Some ( ( ) ) ,
811
856
count_frame,
812
857
count_frame,
858
+ |_, _, _, _, _| Some ( ( ) ) ,
813
859
) ;
814
860
if state. num_durations > 0 {
815
861
( * jobs. lock ( ) . unwrap ( ) ) . push ( ( * start_duration. lock ( ) . unwrap ( ) , state. max_duration ) ) ;
0 commit comments