Skip to content

Commit 460f590

Browse files
authored
Merge pull request #180 from microsoft/connor4312/cpuprofile-sorting
fix: inflated inline metrics for profiles, stall opening cpu profile
2 parents bcbbb7c + 2582f39 commit 460f590

File tree

9 files changed

+36
-28
lines changed

9 files changed

+36
-28
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/vscode-js-profile-core/src/profileAnnotations.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ export abstract class ProfileAnnotations<TNode extends INode> {
2020

2121
public add(rootPath: string | undefined, node: TNode) {
2222
const expand = once(() => {
23-
this.set(
24-
node.callFrame.url,
25-
new Position(
26-
Math.max(0, node.callFrame.lineNumber),
27-
Math.max(0, node.callFrame.columnNumber),
28-
),
29-
node,
23+
const seen = new Set<string>();
24+
const basePosition = new Position(
25+
Math.max(0, node.callFrame.lineNumber),
26+
Math.max(0, node.callFrame.columnNumber),
3027
);
28+
seen.add(`${node.callFrame.url}/${basePosition.line}`);
29+
this.set(node.callFrame.url, basePosition, node);
3130

3231
const src = node.src;
3332
if (
@@ -40,11 +39,16 @@ export abstract class ProfileAnnotations<TNode extends INode> {
4039
}
4140

4241
for (const path of getCandidateDiskPaths(rootPath, src.source)) {
43-
this.set(
44-
path,
45-
new Position(Math.max(0, src.lineNumber - 1), Math.max(0, src.columnNumber - 1)),
46-
node,
42+
const position = new Position(
43+
Math.max(0, src.lineNumber - 1),
44+
Math.max(0, src.columnNumber - 1),
4745
);
46+
47+
const key = `${path}/${position.line}`;
48+
if (!seen.has(key)) {
49+
seen.add(key);
50+
this.set(path, position, node);
51+
}
4852
}
4953
});
5054

packages/vscode-js-profile-core/src/ql/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ export class DataProvider<T> {
6262
}
6363
}
6464

65-
/** Recursively updates the sorting used for data in the provider. */
65+
/** Updates the sorting used for data in the provider. */
6666
public setSort(sort?: (a: T, b: T) => number) {
67+
if (sort === this.sortFn) {
68+
return;
69+
}
70+
6771
this.sortFn = sort;
6872
if (!this.eof) {
6973
// if we didn't read all the data from the provider, we need to throw away
@@ -73,10 +77,6 @@ export class DataProvider<T> {
7377
} else if (this.data) {
7478
this.data.sort(sort);
7579
}
76-
77-
for (const child of this.children.values()) {
78-
child.setSort(sort);
79-
}
8080
}
8181

8282
/** Gets a data provider for the children of the item. */
@@ -87,6 +87,8 @@ export class DataProvider<T> {
8787
this.children.set(item, children);
8888
}
8989

90+
children.setSort(this.sortFn); // sort lazily
91+
9092
return children;
9193
}
9294

packages/vscode-js-profile-flame/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/vscode-js-profile-flame/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-js-profile-flame",
33
"displayName": "Flame Chart Visualizer for JavaScript Profiles",
4-
"version": "1.0.8",
4+
"version": "1.0.9",
55
"description": "Flame graph visualizer for Heap and CPU profiles taken from the JavaScript debugger",
66
"author": "Connor Peet <[email protected]>",
77
"homepage": "https://github.com/microsoft/vscode-js-profile-visualizer#readme",

packages/vscode-js-profile-table/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/vscode-js-profile-table/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vscode-js-profile-table",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"displayName": "Table Visualizer for JavaScript Profiles",
55
"description": "Text visualizer for profiles taken from the JavaScript debugger",
66
"author": "Connor Peet <[email protected]>",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import ImpactBar from '../common/impact-bar';
1919
import styles from '../common/time-view.css';
2020
import { SortFn } from '../common/types';
2121

22-
const selfTime: SortFn<IGraphNode> = n => n.selfTime;
23-
const aggTime: SortFn<IGraphNode> = n => n.aggregateTime;
22+
const selfTime: SortFn<IGraphNode> = (a, b) => b.selfTime - a.selfTime;
23+
const aggTime: SortFn<IGraphNode> = (a, b) => b.aggregateTime - a.aggregateTime;
2424

2525
const BaseTimeView = makeBaseTimeView<IGraphNode>();
2626

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import ImpactBar from '../common/impact-bar';
1919
import styles from '../common/time-view.css';
2020
import { SortFn } from '../common/types';
2121

22-
const selfSize: SortFn<ITreeNode> = n => (n as IHeapProfileNode).selfSize;
23-
const totalSize: SortFn<ITreeNode> = n => (n as IHeapProfileNode).totalSize;
22+
const selfSize: SortFn<ITreeNode> = (a, b) =>
23+
(b as IHeapProfileNode).selfSize - (a as IHeapProfileNode).selfSize;
24+
const totalSize: SortFn<ITreeNode> = (a, b) =>
25+
(b as IHeapProfileNode).totalSize - (a as IHeapProfileNode).totalSize;
2426

2527
const BaseTimeView = makeBaseTimeView<ITreeNode>();
2628

0 commit comments

Comments
 (0)