Skip to content

Commit e45f1cf

Browse files
committed
Move logic to stats service
1 parent 6f9fb30 commit e45f1cf

File tree

3 files changed

+185
-146
lines changed

3 files changed

+185
-146
lines changed

src/app/app.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
</button>
66
<form>
77
<mat-form-field>
8-
<input matInput placeholder="Bss section filter" [value]="bssSectionNames" (input)="bssSectionNames = $event.target.value">
8+
<input matInput placeholder="Bss section filter" [value]="statsParams.bssSectionNames" (input)="statsParams.bssSectionNames = $event.target.value">
99
</mat-form-field>
1010
<mat-form-field>
11-
<input matInput placeholder="Data section filter" [value]="dataSectionNames" (input)="dataSectionNames = $event.target.value">
11+
<input matInput placeholder="Data section filter" [value]="statsParams.dataSectionNames" (input)="statsParams.dataSectionNames = $event.target.value">
1212
</mat-form-field>
1313
<mat-form-field>
14-
<input matInput placeholder="Text section filter" [value]="textSectionNames" (input)="textSectionNames = $event.target.value">
14+
<input matInput placeholder="Text section filter" [value]="statsParams.textSectionNames" (input)="statsParams.textSectionNames = $event.target.value">
1515
</mat-form-field>
1616
</form>
1717
</div>

src/app/app.component.ts

Lines changed: 32 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { HotTableRegisterer } from '@handsontable/angular';
33
import * as Handsontable from 'handsontable';
44

55
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';
87

98
@Component({
109
selector: 'app-root',
@@ -14,18 +13,13 @@ import { LinkerMap, LinkRecord, SectionType, LocateRecord } from '../../common/i
1413
export class AppComponent implements OnInit {
1514
title = 'map-viewer';
1615
filePath: string;
17-
linkerMap: LinkerMap;
18-
dataset = [];
1916
showProgressBar: boolean;
2017
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();
2719

2820
private hotRegisterer = new HotTableRegisterer();
21+
22+
dataset = [];
2923
modulesTableId = 'modules-table-id';
3024
tableSettings: Handsontable.default.GridSettings = {
3125
rowHeaders: false,
@@ -83,10 +77,27 @@ export class AppComponent implements OnInit {
8377
constructor(private fileService: FileService, private statsService: StatsService, private cd: ChangeDetectorRef) {
8478
this.showProgressBar = false;
8579
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);
8688
}
8789

8890
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+
});
90101
}
91102

92103
onSelect() {
@@ -98,9 +109,9 @@ export class AppComponent implements OnInit {
98109
}
99110

100111
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+
// }
104115
this.currentView = 'main';
105116
}
106117

@@ -125,133 +136,18 @@ export class AppComponent implements OnInit {
125136
}
126137

127138
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);
132141
}
133142

134143
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);
139146
}
140147

141148
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);
255151
}
256152

257153
loadFile(path?: string) {
@@ -261,11 +157,9 @@ export class AppComponent implements OnInit {
261157
this.cd.detectChanges(); // notify angular about view changes
262158
}).then(fileInfo => {
263159
this.filePath = fileInfo.path;
264-
this.linkerMap = fileInfo.payload as LinkerMap;
265-
this.dataset = this.prepareDataset(this.linkerMap);
266160
this.showProgressBar = false;
267161

268-
this.statsService.analyze(this.linkerMap);
162+
this.statsService.analyze(fileInfo.payload);
269163

270164
this.cd.detectChanges(); // notify angular about view changes
271165

0 commit comments

Comments
 (0)