@@ -9,8 +9,20 @@ use crate::encode::profiles::{Function, Label, Line, Location, Profile, Sample,
99struct PProfBuilder {
1010 profile : Profile ,
1111 strings : HashMap < String , i64 > ,
12- functions : HashMap < i64 , u64 > ,
13- locations : HashMap < u64 , u64 > ,
12+ functions : HashMap < FunctionMirror , u64 > ,
13+ locations : HashMap < LocationMirror , u64 > ,
14+ }
15+
16+ #[ derive( Hash , PartialEq , Eq , Clone ) ]
17+ pub struct LocationMirror {
18+ pub function_id : u64 ,
19+ pub line : i64 ,
20+ }
21+
22+ #[ derive( Hash , PartialEq , Eq , Clone ) ]
23+ pub struct FunctionMirror {
24+ pub name : i64 ,
25+ pub filename : i64 ,
1426}
1527
1628impl PProfBuilder {
@@ -26,27 +38,27 @@ impl PProfBuilder {
2638 id
2739 }
2840
29- fn add_function ( & mut self , name : i64 ) -> u64 {
30- let v = self . functions . get ( & name ) ;
41+ fn add_function ( & mut self , fm : FunctionMirror ) -> u64 {
42+ let v = self . functions . get ( & fm ) ;
3143 if v. is_some ( ) {
3244 return * v. unwrap ( ) ;
3345 }
3446 assert ! ( self . functions. len( ) != self . profile. function. len( ) + 1 ) ;
3547 let id: u64 = self . functions . len ( ) as u64 + 1 ;
3648 let f = Function {
3749 id : id,
38- name : name,
50+ name : fm . name ,
3951 system_name : 0 ,
40- filename : 0 ,
52+ filename : fm . filename ,
4153 start_line : 0 ,
4254 } ;
43- self . functions . insert ( name , id) ;
55+ self . functions . insert ( fm , id) ;
4456 self . profile . function . push ( f) ;
4557 id
4658 }
4759
48- fn add_location ( & mut self , function_id : u64 ) -> u64 {
49- let v = self . locations . get ( & function_id ) ;
60+ fn add_location ( & mut self , lm : LocationMirror ) -> u64 {
61+ let v = self . locations . get ( & lm ) ;
5062 if v. is_some ( ) {
5163 return * v. unwrap ( ) ;
5264 }
@@ -57,12 +69,12 @@ impl PProfBuilder {
5769 mapping_id : 0 ,
5870 address : 0 ,
5971 line : vec ! [ Line {
60- function_id: function_id,
61- line: 0 ,
72+ function_id: lm . function_id,
73+ line: lm . line ,
6274 } ] ,
6375 is_folded : false ,
6476 } ;
65- self . locations . insert ( function_id , id) ;
77+ self . locations . insert ( lm , id) ;
6678 self . profile . location . push ( l) ;
6779 id
6880 }
@@ -112,13 +124,17 @@ pub fn encode(reports: Vec<Report>, sample_rate: u32, start_time_nanos: u64, dur
112124 label : vec ! [ ] ,
113125 } ;
114126 for sf in & stacktrace. frames {
115- let name = format ! ( "{}:{} - {}" ,
116- sf. filename. as_ref( ) . unwrap_or( & "" . to_string( ) ) ,
117- sf. line. unwrap_or( 0 ) ,
118- sf. name. as_ref( ) . unwrap_or( & "" . to_string( ) ) ) ;
119- let name = b. add_string ( & name) ;
120- let function_id = b. add_function ( name) ;
121- let location_id = b. add_location ( function_id) ;
127+ let name = b. add_string ( & sf. name . as_ref ( ) . unwrap_or ( & "" . to_string ( ) ) ) ;
128+ let filename = b. add_string ( & sf. filename . as_ref ( ) . unwrap_or ( & "" . to_string ( ) ) ) ;
129+ let line = sf. line . unwrap_or ( 0 ) as i64 ;
130+ let function_id = b. add_function ( FunctionMirror {
131+ name : name,
132+ filename : filename,
133+ } ) ;
134+ let location_id = b. add_location ( LocationMirror {
135+ function_id : function_id,
136+ line : line,
137+ } ) ;
122138 sample. location_id . push ( location_id as u64 ) ;
123139 }
124140 let mut labels = HashMap :: new ( ) ;
0 commit comments