1
1
use serde:: ser:: { Serialize , SerializeMap , SerializeSeq , Serializer } ;
2
2
3
3
use crate :: category:: { CategoryHandle , SubcategoryHandle , SubcategoryIndex } ;
4
- use crate :: fast_hash_map:: FastHashMap ;
4
+ use crate :: fast_hash_map:: FastIndexSet ;
5
5
use crate :: frame:: FrameFlags ;
6
- use crate :: func_table:: { FuncIndex , FuncTable } ;
6
+ use crate :: func_table:: { FuncIndex , FuncKey , FuncTable } ;
7
7
use crate :: global_lib_table:: { GlobalLibIndex , GlobalLibTable } ;
8
8
use crate :: native_symbols:: NativeSymbolIndex ;
9
9
use crate :: resource_table:: ResourceTable ;
@@ -12,19 +12,19 @@ use crate::thread_string_table::{ThreadInternalStringIndex, ThreadStringTable};
12
12
13
13
#[ derive( Debug , Clone , Default ) ]
14
14
pub struct FrameTable {
15
- name_col : Vec < ThreadInternalStringIndex > ,
15
+ func_table : FuncTable ,
16
+ resource_table : ResourceTable ,
17
+
18
+ func_col : Vec < FuncIndex > ,
16
19
category_col : Vec < CategoryHandle > ,
17
20
subcategory_col : Vec < SubcategoryIndex > ,
18
- flags_col : Vec < FrameFlags > ,
19
- file_col : Vec < Option < ThreadInternalStringIndex > > ,
20
21
line_col : Vec < Option < u32 > > ,
21
22
column_col : Vec < Option < u32 > > ,
22
- lib_col : Vec < Option < GlobalLibIndex > > ,
23
23
address_col : Vec < Option < u32 > > ,
24
24
native_symbol_col : Vec < Option < NativeSymbolIndex > > ,
25
25
inline_depth_col : Vec < u16 > ,
26
- frame_key_to_frame_index : FastHashMap < InternalFrameKey , usize > ,
27
- contains_js_frame : bool ,
26
+
27
+ frame_key_set : FastIndexSet < InternalFrame > ,
28
28
}
29
29
30
30
impl FrameTable {
@@ -35,129 +35,88 @@ impl FrameTable {
35
35
pub fn index_for_frame (
36
36
& mut self ,
37
37
frame : InternalFrame ,
38
- global_lib_index_to_thread_string_index : & mut FastHashMap <
39
- GlobalLibIndex ,
40
- ThreadInternalStringIndex ,
41
- > ,
42
38
global_libs : & mut GlobalLibTable ,
43
39
string_table : & mut ThreadStringTable ,
44
40
) -> usize {
45
- if let Some ( index) = self . frame_key_to_frame_index . get ( & frame. key ) {
46
- return * index;
41
+ let ( frame_index, is_new) = self . frame_key_set . insert_full ( frame) ;
42
+
43
+ if !is_new {
44
+ return frame_index;
47
45
}
48
46
49
- let flags = frame. key . flags ;
47
+ let func_key = frame. func_key ( ) ;
48
+ let func = self . func_table . index_for_func (
49
+ func_key,
50
+ & mut self . resource_table ,
51
+ global_libs,
52
+ string_table,
53
+ ) ;
50
54
51
- let frame_index = self . name_col . len ( ) ;
52
- let SubcategoryHandle ( category, subcategory) = frame. key . subcategory ;
53
- self . name_col . push ( frame. name ) ;
55
+ self . func_col . push ( func) ;
56
+ let SubcategoryHandle ( category, subcategory) = frame. subcategory ;
54
57
self . category_col . push ( category) ;
55
58
self . subcategory_col . push ( subcategory) ;
56
- self . flags_col . push ( flags) ;
57
-
58
- match frame. key . variant {
59
- InternalFrameKeyVariant :: Label {
60
- file_path,
61
- line,
62
- col,
63
- ..
64
- } => {
65
- self . file_col . push ( file_path) ;
66
- self . line_col . push ( line) ;
67
- self . column_col . push ( col) ;
68
- self . lib_col . push ( None ) ;
59
+ self . line_col . push ( frame. line ) ;
60
+ self . column_col . push ( frame. col ) ;
61
+
62
+ match frame. variant {
63
+ InternalFrameVariant :: Label => {
69
64
self . address_col . push ( None ) ;
70
65
self . native_symbol_col . push ( None ) ;
71
66
self . inline_depth_col . push ( 0 ) ;
72
67
}
73
- InternalFrameKeyVariant :: Native {
68
+ InternalFrameVariant :: Native ( NativeFrameData {
74
69
lib,
70
+ native_symbol,
75
71
relative_address,
76
72
inline_depth,
77
- } => {
78
- self . file_col . push ( None ) ;
79
- self . line_col . push ( None ) ;
80
- self . column_col . push ( None ) ;
81
- self . lib_col . push ( Some ( lib) ) ;
82
- self . address_col . push ( Some ( relative_address) ) ;
83
- self . native_symbol_col . push ( frame. native_symbol ) ;
84
- self . inline_depth_col . push ( inline_depth) ;
85
-
73
+ } ) => {
86
74
global_libs. add_lib_used_rva ( lib, relative_address) ;
87
75
88
- global_lib_index_to_thread_string_index
89
- . entry ( lib)
90
- . or_insert_with ( || {
91
- let lib_name = & global_libs. get_lib ( lib) . unwrap ( ) . name ;
92
- string_table. index_for_string ( lib_name)
93
- } ) ;
76
+ self . address_col . push ( Some ( relative_address) ) ;
77
+ self . native_symbol_col . push ( native_symbol) ;
78
+ self . inline_depth_col . push ( inline_depth) ;
94
79
}
95
80
}
96
81
97
- self . frame_key_to_frame_index . insert ( frame. key , frame_index) ;
98
-
99
- if flags. intersects ( FrameFlags :: IS_JS | FrameFlags :: IS_RELEVANT_FOR_JS ) {
100
- self . contains_js_frame = true ;
101
- }
102
-
103
82
frame_index
104
83
}
105
84
106
85
pub fn contains_js_frame ( & self ) -> bool {
107
- self . contains_js_frame
86
+ self . func_table . contains_js_func ( )
108
87
}
109
88
110
89
pub fn get_serializable_tables (
111
90
& self ,
112
- global_lib_index_to_thread_string_index : & FastHashMap <
113
- GlobalLibIndex ,
114
- ThreadInternalStringIndex ,
115
- > ,
116
- ) -> ( SerializableFrameTable < ' _ > , FuncTable , ResourceTable ) {
117
- let mut func_table = FuncTable :: new ( ) ;
118
- let mut resource_table = ResourceTable :: new ( ) ;
119
- let func_col = self
120
- . name_col
121
- . iter ( )
122
- . cloned ( )
123
- . zip ( self . flags_col . iter ( ) . cloned ( ) )
124
- . zip ( self . lib_col . iter ( ) . cloned ( ) )
125
- . zip ( self . file_col . iter ( ) . cloned ( ) )
126
- . map ( |( ( ( name, flags) , lib) , file) | {
127
- let resource = lib. map ( |lib| {
128
- resource_table. resource_for_lib ( lib, global_lib_index_to_thread_string_index)
129
- } ) ;
130
- func_table. index_for_func ( name, file, resource, flags)
131
- } )
132
- . collect ( ) ;
91
+ ) -> ( SerializableFrameTable < ' _ > , & ' _ FuncTable , & ' _ ResourceTable ) {
133
92
(
134
- SerializableFrameTable ( self , func_col ) ,
135
- func_table,
136
- resource_table,
93
+ SerializableFrameTable ( self ) ,
94
+ & self . func_table ,
95
+ & self . resource_table ,
137
96
)
138
97
}
139
98
}
140
99
141
- pub struct SerializableFrameTable < ' a > ( & ' a FrameTable , Vec < FuncIndex > ) ;
100
+ pub struct SerializableFrameTable < ' a > ( & ' a FrameTable ) ;
142
101
143
102
impl Serialize for SerializableFrameTable < ' _ > {
144
103
fn serialize < S : Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
145
- let SerializableFrameTable ( table, func_col ) = self ;
146
- let len = table. name_col . len ( ) ;
104
+ let SerializableFrameTable ( table) = self ;
105
+ let len = table. func_col . len ( ) ;
147
106
let mut map = serializer. serialize_map ( None ) ?;
148
107
map. serialize_entry ( "length" , & len) ?;
108
+ map. serialize_entry ( "func" , & table. func_col ) ?;
109
+ map. serialize_entry ( "category" , & table. category_col ) ?;
110
+ map. serialize_entry ( "subcategory" , & table. subcategory_col ) ?;
111
+ map. serialize_entry ( "line" , & table. line_col ) ?;
112
+ map. serialize_entry ( "column" , & table. column_col ) ?;
149
113
map. serialize_entry (
150
114
"address" ,
151
115
& SerializableFrameTableAddressColumn ( & table. address_col ) ,
152
116
) ?;
153
- map. serialize_entry ( "inlineDepth" , & table. inline_depth_col ) ?;
154
- map. serialize_entry ( "category" , & table. category_col ) ?;
155
- map. serialize_entry ( "subcategory" , & table. subcategory_col ) ?;
156
- map. serialize_entry ( "func" , func_col) ?;
157
117
map. serialize_entry ( "nativeSymbol" , & table. native_symbol_col ) ?;
118
+ map. serialize_entry ( "inlineDepth" , & table. inline_depth_col ) ?;
158
119
map. serialize_entry ( "innerWindowID" , & SerializableSingleValueColumn ( 0 , len) ) ?;
159
- map. serialize_entry ( "line" , & table. line_col ) ?;
160
- map. serialize_entry ( "column" , & table. column_col ) ?;
161
120
map. end ( )
162
121
}
163
122
}
@@ -177,45 +136,49 @@ impl Serialize for SerializableFrameTableAddressColumn<'_> {
177
136
}
178
137
}
179
138
180
- #[ derive( Debug , Clone , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
139
+ #[ derive( Debug , Clone , Copy , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
181
140
pub struct InternalFrame {
182
- pub key : InternalFrameKey ,
183
141
pub name : ThreadInternalStringIndex ,
184
- pub native_symbol : Option < NativeSymbolIndex > , // only used when key.variant is InternalFrameKeyVariant::Native
142
+ pub variant : InternalFrameVariant ,
143
+ pub subcategory : SubcategoryHandle ,
185
144
pub file_path : Option < ThreadInternalStringIndex > ,
186
145
pub line : Option < u32 > ,
187
146
pub col : Option < u32 > ,
147
+ pub flags : FrameFlags ,
188
148
}
189
149
190
150
#[ derive( Debug , Clone , Copy , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
191
- pub struct InternalFrameKey {
192
- pub variant : InternalFrameKeyVariant ,
193
- pub subcategory : SubcategoryHandle ,
194
- pub flags : FrameFlags ,
151
+ pub struct NativeFrameData {
152
+ pub lib : GlobalLibIndex ,
153
+ pub native_symbol : Option < NativeSymbolIndex > ,
154
+ pub relative_address : u32 ,
155
+ pub inline_depth : u16 ,
195
156
}
196
157
197
158
#[ derive( Debug , Clone , Copy , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
198
- pub enum InternalFrameKeyVariant {
199
- Label {
200
- name : ThreadInternalStringIndex ,
201
- file_path : Option < ThreadInternalStringIndex > ,
202
- line : Option < u32 > ,
203
- col : Option < u32 > ,
204
- } ,
205
- Native {
206
- lib : GlobalLibIndex ,
207
- relative_address : u32 ,
208
- inline_depth : u16 ,
209
- } ,
159
+ pub enum InternalFrameVariant {
160
+ Label ,
161
+ Native ( NativeFrameData ) ,
210
162
}
211
163
212
- impl InternalFrameKeyVariant {
213
- pub fn new_label ( name : ThreadInternalStringIndex ) -> Self {
214
- InternalFrameKeyVariant :: Label {
164
+ impl InternalFrame {
165
+ pub fn func_key ( & self ) -> FuncKey {
166
+ let InternalFrame {
167
+ name,
168
+ variant,
169
+ file_path,
170
+ flags,
171
+ ..
172
+ } = * self ;
173
+ let lib = match variant {
174
+ InternalFrameVariant :: Label => None ,
175
+ InternalFrameVariant :: Native ( NativeFrameData { lib, .. } ) => Some ( lib) ,
176
+ } ;
177
+ FuncKey {
215
178
name,
216
- file_path : None ,
217
- line : None ,
218
- col : None ,
179
+ file_path,
180
+ lib ,
181
+ flags ,
219
182
}
220
183
}
221
184
}
0 commit comments