Skip to content

Commit 6c83a31

Browse files
committed
fix: don't error out on empty profile
Fixes microsoft/vscode#153752
1 parent 654b8a7 commit 6c83a31

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module.exports = {
1616
rules: {
1717
'@typescript-eslint/no-use-before-define': 'off',
1818
'@typescript-eslint/explicit-function-return-type': 'off',
19-
'@typescript-eslint/interface-name-prefix': ['error', { prefixWithI: 'always' }],
2019
'react/display-name': 'off',
2120
'react/prop-types': 'off',
2221
'header/header': [

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

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ describe('model', () => {
1111
expect(buildModel(profiles[i])).toMatchSnapshot();
1212
});
1313
}
14+
15+
it('does not error on empty, profile', () => {
16+
buildModel({
17+
nodes: [],
18+
samples: [],
19+
timeDeltas: [],
20+
startTime: 1654100488066000,
21+
endTime: 1654100490779000,
22+
$vscode: { rootPath: '.', locations: [] },
23+
});
24+
});
1425
});
1526

1627
const profiles = [

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ export const buildModel = (profile: ICpuProfileRaw): IProfileModel => {
229229
// time before the first sample, and the time of the last sample is only
230230
// derived (approximately) by the missing time in the sum of deltas. Save
231231
// some work by calculating it here.
232-
nodes[mapId(samples[timeDeltas.length - 1])].selfTime += lastNodeTime;
233-
timeDeltas.push(lastNodeTime);
232+
if (nodes.length) {
233+
nodes[mapId(samples[timeDeltas.length - 1])].selfTime += lastNodeTime;
234+
timeDeltas.push(lastNodeTime);
235+
}
234236

235237
// 3. Add the aggregate times for all node children and locations
236238
for (let i = 0; i < nodes.length; i++) {

0 commit comments

Comments
 (0)