@@ -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,13 @@ fn dump_free(
92
105
Some ( ( ) )
93
106
}
94
107
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
+
95
115
// todo: this should use something more reasonable than a hash table
96
116
// for each node. let's measure the out-degree and see if a small
97
117
// array is better, to start.
@@ -542,19 +562,30 @@ fn render_free(
542
562
Some ( ( ) )
543
563
}
544
564
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 > (
546
575
state : & mut State ,
547
576
mut handle_state : S ,
548
577
handle_ident : I ,
549
578
handle_unwind : U ,
550
579
handle_alloc : A ,
551
580
handle_free : F ,
581
+ handle_trace_record : T ,
552
582
) -> Option < ( ) >
553
583
where
554
584
I : Fn ( & mut State , & mut S , Duration , blake3:: Hash ) -> Option < ( ) > ,
555
585
U : Fn ( & mut State , & mut S , Duration , Rc < [ u64 ] > ) -> Option < ( ) > ,
556
586
A : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
557
587
F : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
588
+ T : Fn ( & mut State , & mut S , Duration , Rc < [ u8 ] > ) -> Option < ( ) > ,
558
589
{
559
590
loop {
560
591
let time = match read_u128 ( & mut state. inf ) {
@@ -600,6 +631,9 @@ where
600
631
let trace = amt_trace. 1 . clone ( ) ;
601
632
state. total -= amt;
602
633
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) ?;
603
637
} else {
604
638
return None ;
605
639
}
@@ -699,6 +733,7 @@ fn spawn_render_thread(
699
733
render_unwind,
700
734
render_alloc,
701
735
render_free,
736
+ render_trace_record,
702
737
) ?;
703
738
bar_ffmpeg. wait ( ) . ok ( ) ?;
704
739
flame_ffmpeg. wait ( ) . ok ( ) ?;
@@ -755,6 +790,7 @@ fn dump_trace(mut state: State) {
755
790
dump_unwind,
756
791
dump_alloc,
757
792
dump_free,
793
+ dump_trace_record,
758
794
) ;
759
795
}
760
796
@@ -771,6 +807,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
771
807
|_, _, _, _| Some ( ( ) ) ,
772
808
|_, _, _, _, _, _| Some ( ( ) ) ,
773
809
|_, _, _, _, _, _| Some ( ( ) ) ,
810
+ |_, _, _, _| Some ( ( ) ) ,
774
811
) {
775
812
Some ( ( ) ) => ( ) ,
776
813
None => {
@@ -810,6 +847,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
810
847
|_, _, _, _| Some ( ( ) ) ,
811
848
count_frame,
812
849
count_frame,
850
+ |_, _, _, _| Some ( ( ) ) ,
813
851
) ;
814
852
if state. num_durations > 0 {
815
853
( * jobs. lock ( ) . unwrap ( ) ) . push ( ( * start_duration. lock ( ) . unwrap ( ) , state. max_duration ) ) ;
0 commit comments