Skip to content

Commit 204e831

Browse files
sethbrenithDevtools-frontend LUCI CQ
authored andcommitted
Fix heap snapshot comparisons when an entire category is removed
I recently introduced a bug in heap snapshot comparisons where if all instances of a class are removed, the class name shows up as blank in the comparison view. This change fixes the bug by using the class name from the "before" state when there is no "after" state. Bug: 377200307 Change-Id: Ia1c42ea25f90fde0f6a92766f52cb6e66c9ec119 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5992931 Reviewed-by: Simon Zünd <[email protected]> Commit-Queue: Seth Brenith <[email protected]>
1 parent 2de6ccf commit 204e831

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ export abstract class HeapSnapshot {
13331333
selfSizes[i] = node.selfSize();
13341334
}
13351335

1336-
result[classKey] = {indexes, ids, selfSizes};
1336+
result[classKey] = {name: node.className(), indexes, ids, selfSizes};
13371337
}
13381338

13391339
this.#aggregatesForDiffInternal = {interfaceDefinitions, aggregates: result};
@@ -2480,7 +2480,7 @@ export abstract class HeapSnapshot {
24802480
let j = 0;
24812481
const l = baseIds.length;
24822482
const m = indexes.length;
2483-
const diff = new HeapSnapshotModel.HeapSnapshotModel.Diff(aggregate ? aggregate.name : '');
2483+
const diff = new HeapSnapshotModel.HeapSnapshotModel.Diff(aggregate ? aggregate.name : baseAggregate.name);
24842484

24852485
const nodeB = this.createNode(indexes[j]);
24862486
while (i < l && j < m) {

front_end/models/heap_snapshot_model/HeapSnapshotModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ export class Aggregate {
146146
}
147147

148148
export class AggregateForDiff {
149+
name: string;
149150
indexes: number[];
150151
ids: number[];
151152
selfSizes: number[];
152153
constructor() {
154+
this.name = '';
153155
this.indexes = [];
154156
this.ids = [];
155157
this.selfSizes = [];

test/e2e/memory/memory_test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,10 @@ describe('The Memory Panel', function() {
580580
await takeHeapSnapshot();
581581
await waitForNonEmptyHeapSnapshotData();
582582
await setClassFilter('DuplicatedClassName');
583-
let rows = await waitForMany('tr.data-grid-data-grid-node', 2);
583+
let rows = await waitForMany('tr.data-grid-data-grid-node', 3);
584584
assert.strictEqual(30, await getCountFromCategoryRow(rows[0]));
585585
assert.strictEqual(3, await getCountFromCategoryRow(rows[1]));
586+
assert.strictEqual(2, await getCountFromCategoryRow(rows[2]));
586587
await focusTableRow(rows[0]);
587588
await expandFocusedRow();
588589
const {frontend, target} = await getBrowserAndPages();
@@ -598,10 +599,12 @@ describe('The Memory Panel', function() {
598599
await waitForNonEmptyHeapSnapshotData();
599600
await changeViewViaDropdown('Comparison');
600601
await setClassFilter('DuplicatedClassName');
601-
rows = await waitForMany('tr.data-grid-data-grid-node', 2);
602+
rows = await waitForMany('tr.data-grid-data-grid-node', 3);
602603
assert.strictEqual(5, await getAddedCountFromComparisonRow(rows[0]));
603604
assert.strictEqual(1, await getRemovedCountFromComparisonRow(rows[0]));
604605
assert.strictEqual(1, await getAddedCountFromComparisonRow(rows[1]));
605606
assert.strictEqual(10, await getRemovedCountFromComparisonRow(rows[1]));
607+
assert.strictEqual(0, await getAddedCountFromComparisonRow(rows[2]));
608+
assert.strictEqual(2, await getRemovedCountFromComparisonRow(rows[2]));
606609
});
607610
});

test/e2e/resources/memory/duplicated-names.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ <h1>Memory Panel (Heap profiler) Test</h1>
2121
}
2222
holder.a.x = holder.d[0];
2323
holder.d[0].x = [1, 2, 3];
24+
(function () {
25+
class DuplicatedClassName {}
26+
holder.e = new DuplicatedClassName();
27+
holder.f = new DuplicatedClassName();
28+
})();
2429
document.getElementById('update').addEventListener('click', function () {
2530
holder.b = new DuplicatedClassName();
2631
holder.e = new DuplicatedClassName();

0 commit comments

Comments
 (0)