@@ -104,14 +104,19 @@ pub struct PprofBuilder<'a> {
104
104
state : PprofBuilderState < ' a > ,
105
105
}
106
106
107
+ struct ProfileWithUpscaling < ' a > {
108
+ profile : & ' a Profile ,
109
+ upscalings : Vec < UpscalingRule > ,
110
+ }
111
+
107
112
enum PprofBuilderState < ' a > {
108
113
Initialized ,
109
114
Configured {
110
115
options : PprofOptions ,
111
116
} ,
112
117
AddingProfiles {
113
118
options : PprofOptions ,
114
- profiles : Vec < ( & ' a Profile , Vec < UpscalingRule > ) > ,
119
+ profiles : Vec < ProfileWithUpscaling < ' a > > ,
115
120
string_table : StringTable < ' a > ,
116
121
} ,
117
122
}
@@ -222,9 +227,11 @@ impl<'a> PprofBuilder<'a> {
222
227
} ;
223
228
new_rules. push ( UpscalingRule :: ProportionalUpscalingRule ( rule) ) ;
224
229
}
225
-
226
230
profiles
227
- . try_push ( ( profile, new_rules) )
231
+ . try_push ( ProfileWithUpscaling {
232
+ profile,
233
+ upscalings : new_rules,
234
+ } )
228
235
. map_err ( |_| TryAddProfileError :: OutOfMemoryProportionalUpscaling )
229
236
}
230
237
@@ -239,34 +246,34 @@ impl<'a> PprofBuilder<'a> {
239
246
return Err ( TryAddProfileError :: WrongSampleTypeCountForPoisson ) ;
240
247
}
241
248
242
- let mut new_rules = Vec :: new ( ) ;
243
- new_rules
249
+ let mut upscaling_rules = Vec :: new ( ) ;
250
+ upscaling_rules
244
251
. try_reserve_exact ( 1 )
245
252
. map_err ( |_| TryAddProfileError :: OutOfMemoryPoissonUpscaling ) ?;
246
- new_rules . push ( UpscalingRule :: PoissonUpscalingRule ( upscaling_rule) ) ;
253
+ upscaling_rules . push ( UpscalingRule :: PoissonUpscalingRule ( upscaling_rule) ) ;
247
254
248
255
profiles
249
- . try_push ( ( profile, new_rules) )
256
+ . try_push ( ProfileWithUpscaling {
257
+ profile,
258
+ upscalings : upscaling_rules,
259
+ } )
250
260
. map_err ( |_| TryAddProfileError :: OutOfMemoryPoissonUpscaling )
251
261
}
252
262
253
263
pub fn try_add_profile ( & mut self , profile : & ' a Profile ) -> Result < ( ) , TryAddProfileError > {
254
264
let ( profiles, _) = self . transition_to_adding_profiles ( ) ?;
255
-
256
265
profiles
257
- . try_push ( ( profile, Vec :: new ( ) ) )
266
+ . try_push ( ProfileWithUpscaling {
267
+ profile,
268
+ upscalings : Vec :: new ( ) ,
269
+ } )
258
270
. map_err ( |_| TryAddProfileError :: OutOfMemoryWithoutUpscaling )
259
271
}
260
272
261
273
fn transition_to_adding_profiles (
262
274
& mut self ,
263
- ) -> Result <
264
- (
265
- & mut Vec < ( & ' a Profile , Vec < UpscalingRule > ) > ,
266
- & mut StringTable < ' a > ,
267
- ) ,
268
- TryAddProfileError ,
269
- > {
275
+ ) -> Result < ( & mut Vec < ProfileWithUpscaling < ' a > > , & mut StringTable < ' a > ) , TryAddProfileError >
276
+ {
270
277
if matches ! ( self . state, Initialized ) {
271
278
let options = PprofOptions :: default ( ) ;
272
279
self . state = Configured { options } ;
@@ -324,14 +331,17 @@ impl<'a> PprofBuilder<'a> {
324
331
let dict_strings = dict. strings ( ) ;
325
332
326
333
// --- unify sample types across profiles and emit ---
327
- let n_sample_types = profiles. iter ( ) . map ( |( p, _) | p. sample_type . len ( ) ) . sum ( ) ;
334
+ let n_sample_types = profiles
335
+ . iter ( )
336
+ . map ( |pwu| pwu. profile . sample_type . len ( ) )
337
+ . sum ( ) ;
328
338
let n_profiles = profiles. len ( ) ;
329
339
330
340
let mut remaps: Vec < ArrayVec < usize , MAX_SAMPLE_TYPES > > = Vec :: new ( ) ;
331
341
{
332
342
let mut remapper = Remapper :: new ( dict_strings, & mut string_table, n_sample_types) ?;
333
343
remaps. try_reserve_exact ( n_profiles) ?;
334
- for profile in profiles. iter ( ) . map ( |( p , _ ) | p ) {
344
+ for profile in profiles. iter ( ) . map ( |pwu| pwu . profile ) {
335
345
let mut offsets = ArrayVec :: new ( ) ;
336
346
for sample_type in profile. sample_type . iter ( ) {
337
347
if offsets
@@ -378,9 +388,9 @@ impl<'a> PprofBuilder<'a> {
378
388
let mut values_buf: Vec < i64 > = Vec :: new ( ) ;
379
389
let mut labels_buf: Vec < pprof:: Record < pprof:: Label , 3 , { pprof:: NO_OPT_ZERO } > > =
380
390
Vec :: new ( ) ;
381
- for ( i, ( prof , upscaling_rules ) ) in profiles. iter ( ) . enumerate ( ) {
391
+ for ( i, pwu ) in profiles. iter ( ) . enumerate ( ) {
382
392
let remap = & remaps[ i] ;
383
- for sample in & prof . samples {
393
+ for sample in & pwu . profile . samples {
384
394
// location ids from stack
385
395
let stack = sample. stack_id . as_slice ( ) ;
386
396
let mut locs_out: Vec < u64 > = Vec :: with_capacity ( stack. len ( ) ) ;
@@ -496,7 +506,7 @@ impl<'a> PprofBuilder<'a> {
496
506
}
497
507
498
508
// Apply upscaling
499
- for rule in upscaling_rules {
509
+ for rule in & pwu . upscalings {
500
510
rule. scale ( & mut values_buf, & labels_buf) ;
501
511
}
502
512
0 commit comments