1- use pprof:: { ProfilerGuard , ProfilerGuardBuilder , Report } ;
1+ use pprof:: { ProfilerGuard , ProfilerGuardBuilder } ;
2+
3+ use crate :: types:: { Report , StackFrame , StackTrace } ;
24
35use super :: error:: { BackendError , Result } ;
46use super :: types:: { Backend , State } ;
@@ -122,6 +124,7 @@ impl Backend for Pprof<'_> {
122124 . ok_or_else ( || BackendError :: new ( "pprof-rs: ProfilerGuard report error" ) ) ?
123125 . report ( )
124126 . build ( ) ?;
127+
125128 fold ( & report, true , & mut buffer) ?;
126129
127130 // Restart Profiler
@@ -133,7 +136,7 @@ impl Backend for Pprof<'_> {
133136}
134137
135138// Copyright: https://github.com/YangKeao
136- fn fold < W > ( report : & Report , with_thread_name : bool , mut writer : W ) -> Result < ( ) >
139+ fn fold < W > ( report : & pprof :: Report , with_thread_name : bool , mut writer : W ) -> Result < ( ) >
137140where
138141 W : std:: io:: Write ,
139142{
@@ -165,3 +168,40 @@ where
165168
166169 Ok ( ( ) )
167170}
171+
172+ impl From < pprof:: Report > for Report {
173+ fn from ( report : pprof:: Report ) -> Self {
174+ Report { data : report. data }
175+ }
176+ }
177+
178+ impl From < pprof:: Frames > for StackTrace {
179+ fn from ( frames : pprof:: Frames ) -> Self {
180+ StackTrace :: new (
181+ None ,
182+ Some ( frames. thread_id ) ,
183+ Some ( frames. thread_name ) ,
184+ frames. frames . iter ( ) . map ( |frame| frame. into ( ) ) . collect ( ) ,
185+ )
186+ }
187+ }
188+
189+ impl From < pprof:: Symbol > for StackFrame {
190+ fn from ( symbol : pprof:: Symbol ) -> Self {
191+ StackFrame :: new (
192+ None ,
193+ Some ( String :: from_utf8 ( symbol. name . unwrap_or ( vec ! [ ] ) ) . unwrap_or ( "" . to_string ( ) ) ) ,
194+ Some (
195+ symbol
196+ . filename
197+ . unwrap_or ( std:: path:: PathBuf :: new ( ) )
198+ . to_str ( )
199+ . unwrap_or ( "" )
200+ . to_string ( ) ,
201+ ) ,
202+ None ,
203+ None ,
204+ symbol. lineno ,
205+ )
206+ }
207+ }
0 commit comments