@@ -209,24 +209,36 @@ pub(crate) struct StackFrame {
209
209
pub ( crate ) calls_x2 : u32 ,
210
210
}
211
211
212
- impl StackFrame {
212
+ struct StackFrameWithContext < ' c > {
213
+ frame : & ' c StackFrame ,
214
+ strings : & ' c StringIndex ,
215
+ }
216
+
217
+ impl < ' c > StackFrameWithContext < ' c > {
218
+ fn callees ( & self ) -> impl Iterator < Item = ( & ' c str , StackFrameWithContext < ' c > ) > + ' _ {
219
+ self . frame . callees . iter ( ) . map ( move |( id, callee) | {
220
+ (
221
+ self . strings . get ( * id) ,
222
+ StackFrameWithContext {
223
+ frame : callee,
224
+ strings : self . strings ,
225
+ } ,
226
+ )
227
+ } )
228
+ }
229
+
213
230
/// Write this stack frame's data to a file in flamegraph.pl format.
214
- fn write_flame_graph < ' a > (
215
- & self ,
216
- file : & mut FlameGraphWriter ,
217
- stack : & ' _ mut Vec < & ' a str > ,
218
- ids : & ' a StringIndex ,
219
- ) {
220
- for ( k, v) in & self . allocs . summary {
231
+ fn write_flame_graph ( & self , file : & mut FlameGraphWriter , stack : & ' _ mut Vec < & ' c str > ) {
232
+ for ( k, v) in & self . frame . allocs . summary {
221
233
file. write (
222
234
stack. iter ( ) . copied ( ) . chain ( std:: iter:: once ( * k) ) ,
223
235
v. bytes as u64 ,
224
236
) ;
225
237
}
226
238
227
- for ( id, frame) in & self . callees {
228
- stack. push ( ids . get ( * id ) ) ;
229
- frame. write_flame_graph ( file, stack, ids ) ;
239
+ for ( id, frame) in self . callees ( ) {
240
+ stack. push ( id ) ;
241
+ frame. write_flame_graph ( file, stack) ;
230
242
stack. pop ( ) ;
231
243
}
232
244
}
@@ -273,11 +285,17 @@ impl AggregateHeapProfileInfo {
273
285
}
274
286
}
275
287
288
+ fn root ( & self ) -> StackFrameWithContext {
289
+ StackFrameWithContext {
290
+ frame : & self . root ,
291
+ strings : & self . strings ,
292
+ }
293
+ }
294
+
276
295
/// Write this out recursively to a file.
277
296
pub ( crate ) fn gen_flame_graph ( & self ) -> String {
278
297
let mut writer = FlameGraphWriter :: new ( ) ;
279
- self . root
280
- . write_flame_graph ( & mut writer, & mut vec ! [ ] , & self . strings ) ;
298
+ self . root ( ) . write_flame_graph ( & mut writer, & mut vec ! [ ] ) ;
281
299
writer. finish ( )
282
300
}
283
301
0 commit comments