Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/profile-logic/gecko-profile-versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,13 @@ const _upgraders: {
// upgraded counters; ignore them.
continue;
}
counter.samples = counter.sample_groups[0].samples;
// A counter that collected no data has an empty sample_groups array
// (see the version 18 upgrader), so fall back to an empty samples
// table when there is no group to unwrap.
counter.samples =
counter.sample_groups.length > 0
? counter.sample_groups[0].samples
: { schema: { time: 0, count: 1, number: 2 }, data: [] };
delete counter.sample_groups;
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/unit/profile-upgrading.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ describe('upgrading gecko profiles', function () {
// - upgrading tracing markers without interval information
testProfileUpgrading(require('../fixtures/upgrades/gecko-2.json'));
});

it('handles a counter with no collected data', function () {
// The version 18 upgrader turns a counter whose sample_groups object has no
// samples into one with an empty sample_groups array. The version 29
// upgrader must not crash when unwrapping that empty array.
const profile: any = {
meta: { version: 17 },
processes: [],
threads: [],
counters: [
{
name: 'power',
category: 'power',
description: 'Power counter',
sample_groups: { id: 0 },
},
],
};
upgradeGeckoProfileToCurrentVersion(profile);
expect(profile.meta.version).toEqual(GECKO_PROFILE_VERSION);
const [counter] = profile.counters;
expect(counter.sample_groups).toBe(undefined);
expect(counter.samples.data).toEqual([]);
});
});

describe('upgrading processed profiles', function () {
Expand Down
Loading