@@ -3,8 +3,7 @@ import { HotTableRegisterer } from '@handsontable/angular';
3
3
import * as Handsontable from 'handsontable' ;
4
4
5
5
import { FileService , FileProgressCallback } from './file.service' ;
6
- import { StatsService } from './stats.service' ;
7
- import { LinkerMap , LinkRecord , SectionType , LocateRecord } from '../../common/interfaces/linkermap' ;
6
+ import { StatsService , StatsParams } from './stats.service' ;
8
7
9
8
@Component ( {
10
9
selector : 'app-root' ,
@@ -14,18 +13,13 @@ import { LinkerMap, LinkRecord, SectionType, LocateRecord } from '../../common/i
14
13
export class AppComponent implements OnInit {
15
14
title = 'map-viewer' ;
16
15
filePath : string ;
17
- linkerMap : LinkerMap ;
18
- dataset = [ ] ;
19
16
showProgressBar : boolean ;
20
17
currentView : string ;
21
- showObjectFiles = false ;
22
- groupByGroup = true ;
23
- groupByModule = true ;
24
- bssSectionNames = '.bss' ;
25
- dataSectionNames = '.data' ;
26
- textSectionNames = '.text' ;
18
+ statsParams : StatsParams = new StatsParams ( ) ;
27
19
28
20
private hotRegisterer = new HotTableRegisterer ( ) ;
21
+
22
+ dataset = [ ] ;
29
23
modulesTableId = 'modules-table-id' ;
30
24
tableSettings : Handsontable . default . GridSettings = {
31
25
rowHeaders : false ,
@@ -83,10 +77,27 @@ export class AppComponent implements OnInit {
83
77
constructor ( private fileService : FileService , private statsService : StatsService , private cd : ChangeDetectorRef ) {
84
78
this . showProgressBar = false ;
85
79
this . currentView = 'main' ;
80
+
81
+ this . statsParams . showObjectFiles = false ;
82
+ this . statsParams . groupByGroup = true ;
83
+ this . statsParams . groupByModule = true ;
84
+ this . statsParams . bssSectionNames = '.bss' ;
85
+ this . statsParams . dataSectionNames = '.data' ;
86
+ this . statsParams . textSectionNames = '.text' ;
87
+ this . statsService . setParams ( this . statsParams ) ;
86
88
}
87
89
88
90
ngOnInit ( ) {
89
- //
91
+ this . statsService . locationStats . subscribe ( res => {
92
+ this . locationTableDataset = Array . from ( res . values ( ) ) . map ( loc => {
93
+ loc . group = Array . from ( loc . group . values ( ) ) . join ( ', ' ) ;
94
+ loc . name = Array . from ( loc . name . values ( ) ) . join ( ', ' ) ;
95
+ return loc ;
96
+ } ) ;
97
+ } ) ;
98
+ this . statsService . dataStats . subscribe ( res => {
99
+ this . dataset = Array . from ( res . values ( ) ) ;
100
+ } ) ;
90
101
}
91
102
92
103
onSelect ( ) {
@@ -98,9 +109,9 @@ export class AppComponent implements OnInit {
98
109
}
99
110
100
111
onClose ( ) {
101
- if ( this . linkerMap ) {
102
- this . dataset = this . prepareDataset ( this . linkerMap ) ;
103
- }
112
+ // if (this.linkerMap) {
113
+ // this.dataset = this.prepareDataset(this.linkerMap);
114
+ // }
104
115
this . currentView = 'main' ;
105
116
}
106
117
@@ -125,133 +136,18 @@ export class AppComponent implements OnInit {
125
136
}
126
137
127
138
toggleShowObjectFilesCheckbox ( checked : boolean ) {
128
- this . showObjectFiles = checked ;
129
- if ( this . linkerMap ) {
130
- this . dataset = this . prepareDataset ( this . linkerMap ) ;
131
- }
139
+ this . statsParams . showObjectFiles = checked ;
140
+ this . statsService . setParams ( this . statsParams ) ;
132
141
}
133
142
134
143
checkGroupByGroup ( checked : boolean ) {
135
- this . groupByGroup = checked ;
136
- if ( this . linkerMap ) {
137
- this . dataset = this . prepareDataset ( this . linkerMap ) ;
138
- }
144
+ this . statsParams . groupByGroup = checked ;
145
+ this . statsService . setParams ( this . statsParams ) ;
139
146
}
140
147
141
148
checkGroupByModule ( checked : boolean ) {
142
- this . groupByModule = checked ;
143
- if ( this . linkerMap ) {
144
- this . dataset = this . prepareDataset ( this . linkerMap ) ;
145
- }
146
- }
147
-
148
- getSectionType ( section : string ) : SectionType {
149
- const name = section . substring ( 0 , section . indexOf ( '.' , 1 ) ) ;
150
- if ( this . bssSectionNames . split ( / \s * , \s * / ) . includes ( name ) ) {
151
- return SectionType . Bss ;
152
- } else if ( this . dataSectionNames . split ( / \s * , \s * / ) . includes ( name ) ) {
153
- return SectionType . Data ;
154
- } else if ( this . textSectionNames . split ( / \s * , \s * / ) . includes ( name ) ) {
155
- return SectionType . Text ;
156
- } else {
157
- return SectionType . Other ;
158
- }
159
- }
160
-
161
- calcTotalSectionSizes ( record : LinkRecord ) : Map < SectionType , number > {
162
- const result = new Map ( [
163
- [ SectionType . Bss , 0 ] ,
164
- [ SectionType . Data , 0 ] ,
165
- [ SectionType . Text , 0 ] ,
166
- [ SectionType . Other , 0 ] ,
167
- ] ) ;
168
-
169
- record . sections . forEach ( ( section ) => {
170
- section . type = this . getSectionType ( section . in . section ) ;
171
- result . set ( section . type , result . get ( section . type ) + section . in . size ) ;
172
- } ) ;
173
-
174
- return result ;
175
- }
176
-
177
- prepareDataset ( linkerMap : LinkerMap ) {
178
- const fileToArchive = new Map < string , string > ( ) ;
179
- const sectionLocationMapping = new Map < string , LocateRecord > ( ) ;
180
-
181
- linkerMap . locateResult . forEach ( ( locationRecord ) => {
182
- sectionLocationMapping . set ( locationRecord . section , locationRecord ) ;
183
- } ) ;
184
-
185
- linkerMap . processedFiles . forEach ( ( file ) => {
186
- if ( file . archiveName ) {
187
- fileToArchive . set ( file . name , file . archiveName ) ;
188
- }
189
- } ) ;
190
-
191
- const dataset = new Map ( ) ;
192
- const locationDataset = new Map ( ) ;
193
- linkerMap . linkResult . forEach ( ( record ) => {
194
- const archiveName = fileToArchive . get ( record . fileName ) ;
195
- const totalSize = this . calcTotalSectionSizes ( record ) ;
196
- const name = archiveName ? ( this . showObjectFiles ? archiveName + '(' + record . fileName + ')' : archiveName ) : record . fileName ;
197
-
198
- if ( ! dataset . has ( name ) ) {
199
- dataset . set ( name , {
200
- name,
201
- bssSize : totalSize . get ( SectionType . Bss ) ,
202
- dataSize : totalSize . get ( SectionType . Data ) ,
203
- textSize : totalSize . get ( SectionType . Text ) ,
204
- otherSize : totalSize . get ( SectionType . Other ) ,
205
- } ) ;
206
- } else {
207
- dataset . get ( name ) . bssSize += totalSize . get ( SectionType . Bss ) ;
208
- dataset . get ( name ) . dataSize += totalSize . get ( SectionType . Data ) ;
209
- dataset . get ( name ) . textSize += totalSize . get ( SectionType . Text ) ;
210
- dataset . get ( name ) . otherSize += totalSize . get ( SectionType . Other ) ;
211
- }
212
-
213
- // chip <-> size
214
- record . sections . forEach ( ( section ) => {
215
- const location = sectionLocationMapping . get ( section . out . section ) ;
216
- if ( location ) {
217
- let key = location . chip ;
218
- if ( this . groupByGroup ) {
219
- key += location . group ;
220
- }
221
- if ( this . groupByModule ) {
222
- key += name ;
223
- }
224
- if ( ! locationDataset . has ( key ) ) {
225
- locationDataset . set ( key , {
226
- name : new Set ( ) ,
227
- chip : location . chip ,
228
- group : new Set ( ) ,
229
- size : location . size ,
230
- actualSize : this . statsService . calcActualSize ( location )
231
- } ) ;
232
- locationDataset . get ( key ) . name . add ( name ) ;
233
- locationDataset . get ( key ) . group . add ( location . group ) ;
234
- } else {
235
- locationDataset . get ( key ) . size += location . size ;
236
- locationDataset . get ( key ) . actualSize += this . statsService . calcActualSize ( location ) ;
237
- if ( ! this . groupByGroup ) {
238
- locationDataset . get ( key ) . group . add ( location . group ) ;
239
- }
240
- if ( ! this . groupByModule ) {
241
- locationDataset . get ( key ) . name . add ( name ) ;
242
- }
243
- }
244
- }
245
- } ) ;
246
- } ) ;
247
-
248
- this . locationTableDataset = Array . from ( locationDataset . values ( ) ) . map ( loc => {
249
- loc . group = Array . from ( loc . group . values ( ) ) . join ( ', ' ) ;
250
- loc . name = Array . from ( loc . name . values ( ) ) . join ( ', ' ) ;
251
- return loc ;
252
- } ) ;
253
-
254
- return Array . from ( dataset . values ( ) ) ;
149
+ this . statsParams . groupByModule = checked ;
150
+ this . statsService . setParams ( this . statsParams ) ;
255
151
}
256
152
257
153
loadFile ( path ?: string ) {
@@ -261,11 +157,9 @@ export class AppComponent implements OnInit {
261
157
this . cd . detectChanges ( ) ; // notify angular about view changes
262
158
} ) . then ( fileInfo => {
263
159
this . filePath = fileInfo . path ;
264
- this . linkerMap = fileInfo . payload as LinkerMap ;
265
- this . dataset = this . prepareDataset ( this . linkerMap ) ;
266
160
this . showProgressBar = false ;
267
161
268
- this . statsService . analyze ( this . linkerMap ) ;
162
+ this . statsService . analyze ( fileInfo . payload ) ;
269
163
270
164
this . cd . detectChanges ( ) ; // notify angular about view changes
271
165
0 commit comments