Skip to content

Commit 8a6f3e6

Browse files
committed
fix: timings in table visualizer being incorrect
1 parent 8b587c9 commit 8a6f3e6

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"type": "pwa-extensionHost",
1111
"request": "launch",
1212
"runtimeExecutable": "${execPath}",
13+
"debugWebviews": {
14+
"webRoot": "${workspaceFolder}/packages/vscode-js-profile-table"
15+
},
1316
"args": [
1417
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-js-profile-table",
1518
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-js-profile-flame",

packages/vscode-js-profile-core/src/cpu/bottomUpGraph.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class BottomUpNode implements IGraphNode {
4949
public addNode(node: IComputedNode) {
5050
this.selfTime += node.selfTime;
5151
this.aggregateTime += node.aggregateTime;
52-
this.parent?.addNode(node);
5352
}
5453

5554
public toJSON(): IGraphNode {
@@ -66,36 +65,35 @@ export class BottomUpNode implements IGraphNode {
6665
}
6766
}
6867

69-
const processNode = (aggregate: BottomUpNode, node: IComputedNode, model: IProfileModel) => {
68+
const processNode = (
69+
aggregate: BottomUpNode,
70+
node: IComputedNode,
71+
model: IProfileModel,
72+
initialNode = node,
73+
) => {
7074
let child = aggregate.children[node.locationId];
7175
if (!child) {
7276
child = new BottomUpNode(model.locations[node.locationId], aggregate);
7377
aggregate.childrenSize++;
7478
aggregate.children[node.locationId] = child;
7579
}
7680

77-
child.addNode(node);
81+
child.addNode(initialNode);
7882

7983
if (node.parent) {
80-
processNode(child, model.nodes[node.parent], model);
84+
processNode(child, model.nodes[node.parent], model, initialNode);
8185
}
8286
};
8387

8488
/**
8589
* Creates a bottom-up graph of the process information
8690
*/
8791
export const createBottomUpGraph = (model: IProfileModel) => {
88-
const byLocation: IComputedNode[][] = new Array(model.locations.length).fill([]);
89-
for (const node of model.nodes) {
90-
byLocation[node.locationId].push(node);
91-
}
92-
9392
const root = BottomUpNode.root();
9493

9594
for (const node of model.nodes) {
96-
if (node.children.length === 0) {
97-
processNode(root, node, model);
98-
}
95+
processNode(root, node, model);
96+
root.addNode(node);
9997
}
10098

10199
return root;

packages/vscode-js-profile-core/src/cpu/model.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export const buildModel = (profile: ICpuProfileRaw): IProfileModel => {
203203
};
204204
}
205205

206+
const { samples, timeDeltas } = profile;
206207
const sourceLocations = ensureSourceLocations(profile);
207208
const locations: ILocation[] = sourceLocations.map((l, id) => {
208209
const src = getBestLocation(profile, l.locations);
@@ -260,8 +261,8 @@ export const buildModel = (profile: ICpuProfileRaw): IProfileModel => {
260261

261262
// 2. The profile samples are the 'bottom-most' node, the currently running
262263
// code. Sum of these in the self time.
263-
for (let i = 1; i < profile.timeDeltas.length; i++) {
264-
nodes[profile.samples[i] - 1].selfTime += profile.timeDeltas[i - 1];
264+
for (let i = 1; i < timeDeltas.length; i++) {
265+
nodes[mapId(samples[i])].selfTime += timeDeltas[i - 1];
265266
}
266267

267268
// 3. Add the aggregate times for all node children and locations
@@ -275,8 +276,8 @@ export const buildModel = (profile: ICpuProfileRaw): IProfileModel => {
275276
return {
276277
nodes,
277278
locations,
278-
samples: profile.samples.map(mapId),
279-
timeDeltas: profile.timeDeltas || [],
279+
samples: samples.map(mapId),
280+
timeDeltas,
280281
rootPath: profile.$vscode?.rootPath,
281282
duration: profile.endTime - profile.startTime,
282283
};

packages/vscode-js-profile-table/src/client/time-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const TimeView: FunctionComponent<{
182182
data={rendered}
183183
renderRow={renderRow}
184184
rowHeight={25}
185-
overscanCount={10}
185+
overscanCount={100}
186186
/>
187187
</Fragment>
188188
);

0 commit comments

Comments
 (0)