1+ use std:: collections:: HashMap ;
2+ use std:: ffi:: OsStr ;
3+
14use pprof:: { ProfilerGuard , ProfilerGuardBuilder } ;
25
36use crate :: types:: { Report , StackFrame , StackTrace } ;
@@ -117,21 +120,20 @@ impl Backend for Pprof<'_> {
117120 return Err ( BackendError :: new ( "Pprof Backend is not Running" ) ) ;
118121 }
119122
120- let mut buffer = Vec :: new ( ) ;
121123 let report = self
122124 . guard
123125 . as_ref ( )
124126 . ok_or_else ( || BackendError :: new ( "pprof-rs: ProfilerGuard report error" ) ) ?
125127 . report ( )
126128 . build ( ) ?;
127129
128- fold ( & report , true , & mut buffer ) ? ;
130+ let new_report = Into :: < Report > :: into ( report ) . to_string ( ) . into_bytes ( ) ;
129131
130132 // Restart Profiler
131133 self . stop ( ) ?;
132134 self . start ( ) ?;
133135
134- Ok ( buffer )
136+ Ok ( new_report )
135137 }
136138}
137139
@@ -171,7 +173,13 @@ where
171173
172174impl From < pprof:: Report > for Report {
173175 fn from ( report : pprof:: Report ) -> Self {
174- Report { data : report. data }
176+ //convert report to Report
177+ let report_data: HashMap < StackTrace , usize > = report
178+ . data
179+ . iter ( )
180+ . map ( |( key, value) | ( key. to_owned ( ) . into ( ) , value. to_owned ( ) as usize ) )
181+ . collect ( ) ;
182+ Report :: new ( report_data)
175183 }
176184}
177185
@@ -181,7 +189,12 @@ impl From<pprof::Frames> for StackTrace {
181189 None ,
182190 Some ( frames. thread_id ) ,
183191 Some ( frames. thread_name ) ,
184- frames. frames . iter ( ) . map ( |frame| frame. into ( ) ) . collect ( ) ,
192+ frames
193+ . frames
194+ . concat ( )
195+ . iter ( )
196+ . map ( |frame| frame. to_owned ( ) . into ( ) )
197+ . collect ( ) ,
185198 )
186199 }
187200}
@@ -190,7 +203,18 @@ impl From<pprof::Symbol> for StackFrame {
190203 fn from ( symbol : pprof:: Symbol ) -> Self {
191204 StackFrame :: new (
192205 None ,
193- Some ( String :: from_utf8 ( symbol. name . unwrap_or ( vec ! [ ] ) ) . unwrap_or ( "" . to_string ( ) ) ) ,
206+ Some ( symbol. name ( ) ) ,
207+ Some (
208+ symbol
209+ . filename
210+ . clone ( )
211+ . unwrap_or ( std:: path:: PathBuf :: new ( ) )
212+ . file_name ( )
213+ . unwrap_or ( OsStr :: new ( "" ) )
214+ . to_str ( )
215+ . unwrap_or ( "" )
216+ . to_string ( ) ,
217+ ) ,
194218 Some (
195219 symbol
196220 . filename
@@ -199,7 +223,6 @@ impl From<pprof::Symbol> for StackFrame {
199223 . unwrap_or ( "" )
200224 . to_string ( ) ,
201225 ) ,
202- None ,
203226 None ,
204227 symbol. lineno ,
205228 )
0 commit comments