@@ -7,8 +7,21 @@ use std::rc::Rc;
7
7
use std:: sync:: Mutex ;
8
8
use std:: time:: Duration ;
9
9
10
- use piet_common:: { kurbo , Color , RenderContext , Text , TextLayout , TextLayoutBuilder } ;
10
+ use piet_common:: { Color , RenderContext , Text , TextLayout , TextLayoutBuilder , kurbo } ;
11
11
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
+ }
12
25
fn read_u128 ( inf : & mut File ) -> Result < u128 , std:: io:: Error > {
13
26
let mut bytes: [ u8 ; 16 ] = [ 0 ; 16 ] ;
14
27
inf. read_exact ( & mut bytes) ?;
@@ -76,6 +89,19 @@ fn dump_free(
76
89
Some ( ( ) )
77
90
}
78
91
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
+
79
105
// todo: this should use something more reasonable than a hash table
80
106
// for each node. let's measure the out-degree and see if a small
81
107
// array is better, to start.
@@ -526,19 +552,31 @@ fn render_free(
526
552
Some ( ( ) )
527
553
}
528
554
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 > (
530
566
state : & mut State ,
531
567
mut handle_state : S ,
532
568
handle_ident : I ,
533
569
handle_unwind : U ,
534
570
handle_alloc : A ,
535
571
handle_free : F ,
572
+ handle_trace_record : T ,
536
573
) -> Option < ( ) >
537
574
where
538
575
I : Fn ( & mut State , & mut S , Duration , blake3:: Hash ) -> Option < ( ) > ,
539
576
U : Fn ( & mut State , & mut S , Duration , Rc < [ u64 ] > ) -> Option < ( ) > ,
540
577
A : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
541
578
F : Fn ( & mut State , & mut S , Duration , u64 , u64 , Rc < [ u64 ] > ) -> Option < ( ) > ,
579
+ T : Fn ( & mut State , & mut S , Duration , u64 , Rc < [ u8 ] > ) -> Option < ( ) > ,
542
580
{
543
581
loop {
544
582
let time = match read_u128 ( & mut state. inf ) {
@@ -584,6 +622,10 @@ where
584
622
let trace = amt_trace. 1 . clone ( ) ;
585
623
state. total -= amt;
586
624
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) ?;
587
629
} else {
588
630
return None ;
589
631
}
@@ -683,6 +725,7 @@ fn spawn_render_thread(
683
725
render_unwind,
684
726
render_alloc,
685
727
render_free,
728
+ render_trace_record,
686
729
) ?;
687
730
bar_ffmpeg. wait ( ) . ok ( ) ?;
688
731
flame_ffmpeg. wait ( ) . ok ( ) ?;
@@ -739,6 +782,7 @@ fn dump_trace(mut state: State) {
739
782
dump_unwind,
740
783
dump_alloc,
741
784
dump_free,
785
+ dump_trace_record,
742
786
) ;
743
787
}
744
788
@@ -755,6 +799,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
755
799
|_, _, _, _| Some ( ( ) ) ,
756
800
|_, _, _, _, _, _| Some ( ( ) ) ,
757
801
|_, _, _, _, _, _| Some ( ( ) ) ,
802
+ |_, _, _, _, _| Some ( ( ) ) ,
758
803
) {
759
804
Some ( ( ) ) => ( ) ,
760
805
None => {
@@ -794,6 +839,7 @@ fn plot_mem(args: Vec<String>, mut state: State) {
794
839
|_, _, _, _| Some ( ( ) ) ,
795
840
count_frame,
796
841
count_frame,
842
+ |_, _, _, _, _| Some ( ( ) ) ,
797
843
) ;
798
844
if state. num_durations > 0 {
799
845
( * jobs. lock ( ) . unwrap ( ) ) . push ( ( * start_duration. lock ( ) . unwrap ( ) , state. max_duration ) ) ;
0 commit comments