@@ -25,6 +25,7 @@ use crate::values::layout::heap::profile::aggregated::AggregateHeapProfileInfo;
25
25
use crate :: values:: layout:: heap:: profile:: aggregated:: StackFrame ;
26
26
use crate :: values:: layout:: heap:: profile:: alloc_counts:: AllocCounts ;
27
27
use crate :: values:: layout:: heap:: profile:: string_index:: StringId ;
28
+ use crate :: values:: layout:: heap:: profile:: string_index:: StringIndexMap ;
28
29
29
30
/// Information relating to a function.
30
31
#[ derive( Default , Debug , Clone ) ]
@@ -65,19 +66,14 @@ impl FuncInfo {
65
66
/// so pull out top_stack/top_info as a cache.
66
67
pub ( crate ) struct HeapSummaryByFunction {
67
68
/// Information about all functions. Map from `StringId`.
68
- info : Vec < FuncInfo > ,
69
+ info : StringIndexMap < FuncInfo > ,
69
70
}
70
71
71
72
impl HeapSummaryByFunction {
72
- fn ensure ( & mut self , x : StringId ) -> & mut FuncInfo {
73
- if self . info . len ( ) <= x. 0 {
74
- self . info . resize ( x. 0 + 1 , FuncInfo :: default ( ) ) ;
75
- }
76
- & mut self . info [ x. 0 ]
77
- }
78
-
79
73
pub ( crate ) fn init ( stacks : & AggregateHeapProfileInfo ) -> HeapSummaryByFunction {
80
- let mut info = HeapSummaryByFunction { info : Vec :: new ( ) } ;
74
+ let mut info = HeapSummaryByFunction {
75
+ info : StringIndexMap :: default ( ) ,
76
+ } ;
81
77
info. init_children ( & stacks. root , stacks. root_id ) ;
82
78
info
83
79
}
@@ -96,28 +92,24 @@ impl HeapSummaryByFunction {
96
92
frame : & StackFrame ,
97
93
caller : StringId ,
98
94
) -> SmallDuration {
99
- self . ensure ( func) . time += frame. time_x2 ;
100
- self . ensure ( func) . calls += frame. calls_x2 as usize ;
101
- * self . ensure ( func) . callers . entry ( caller) . or_insert ( 0 ) += 1 ;
95
+ self . info . or_insert ( func) . time += frame. time_x2 ;
96
+ self . info . or_insert ( func) . calls += frame. calls_x2 as usize ;
97
+ * self . info . or_insert ( func) . callers . entry ( caller) . or_insert ( 0 ) += 1 ;
102
98
for ( t, allocs) in & frame. allocs . summary {
103
- * self . ensure ( func) . alloc . entry ( t) . or_default ( ) += * allocs;
99
+ * self . info . or_insert ( func) . alloc . entry ( t) . or_default ( ) += * allocs;
104
100
}
105
101
106
102
let time_rec = frame. time_x2 + self . init_children ( frame, func) ;
107
- self . ensure ( func) . time_rec += time_rec;
103
+ self . info . or_insert ( func) . time_rec += time_rec;
108
104
time_rec
109
105
}
110
106
111
107
fn totals ( & self ) -> FuncInfo {
112
- FuncInfo :: merge ( self . info . iter ( ) )
108
+ FuncInfo :: merge ( self . info . values ( ) )
113
109
}
114
110
115
111
fn info ( & self ) -> Vec < ( StringId , & FuncInfo ) > {
116
- self . info
117
- . iter ( )
118
- . enumerate ( )
119
- . map ( |( id, x) | ( StringId ( id) , x) )
120
- . collect :: < Vec < _ > > ( )
112
+ self . info . iter ( ) . collect :: < Vec < _ > > ( )
121
113
}
122
114
123
115
pub ( crate ) fn gen_csv ( & self , stacks : & AggregateHeapProfileInfo ) -> String {
@@ -216,7 +208,7 @@ _ignore = str([1]) # allocate a string in non_drop
216
208
217
209
let info = HeapSummaryByFunction :: init ( & stacks) ;
218
210
219
- let total = FuncInfo :: merge ( info. info . iter ( ) ) ;
211
+ let total = FuncInfo :: merge ( info. info . values ( ) ) ;
220
212
// from non-drop heap
221
213
assert_eq ! ( total. alloc. get( "string" ) . unwrap( ) . count, 1 ) ;
222
214
// from drop heap
0 commit comments