Skip to content

Commit 7710a43

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
Use i18n.ByteUtilities.bytesToString in heap profiler
This replaces displaying bytes as big numbers of bytes, to dynamically adjusting the unit. Bug: 388589515 Change-Id: I6d13841c1b5b13df424f00e2ea4c7c740ed7857e Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6159568 Commit-Queue: Connor Clark <cjamcl@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Auto-Submit: Connor Clark <cjamcl@chromium.org>
1 parent 7cb1b26 commit 7710a43

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

front_end/panels/profiler/HeapProfileView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ const UIStrings = {
2828
/**
2929
*@description Name of column header that reports the size (in terms of bytes) used for a particular part of the heap, excluding the size of the children nodes of this part of the heap
3030
*/
31-
selfSizeBytes: 'Self size (bytes)',
31+
selfSizeBytes: 'Self size',
3232
/**
3333
*@description Name of column header that reports the total size (in terms of bytes) used for a particular part of the heap
3434
*/
35-
totalSizeBytes: 'Total size (bytes)',
35+
totalSizeBytes: 'Total size',
3636
/**
3737
*@description Button text to stop profiling the heap
3838
*/
@@ -588,7 +588,7 @@ export class NodeFormatter implements Formatter {
588588
}
589589

590590
formatValue(value: number): string {
591-
return Platform.NumberUtilities.withThousandsSeparator(value);
591+
return i18n.ByteUtilities.bytesToString(value);
592592
}
593593

594594
formatValueAccessibleText(value: number): string {

front_end/panels/profiler/HeapSnapshotGridNodes.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,11 @@ export abstract class HeapSnapshotGenericObjectNode extends HeapSnapshotGridNode
582582
const snapshot = (dataGrid.snapshot as HeapSnapshotProxy);
583583
const shallowSizePercent = this.shallowSize / snapshot.totalSize * 100.0;
584584
const retainedSizePercent = this.retainedSize / snapshot.totalSize * 100.0;
585+
585586
this.data = {
586587
distance: this.toUIDistance(this.distance),
587-
shallowSize: Platform.NumberUtilities.withThousandsSeparator(this.shallowSize),
588-
retainedSize: Platform.NumberUtilities.withThousandsSeparator(this.retainedSize),
588+
shallowSize: i18n.ByteUtilities.bytesToString(this.shallowSize),
589+
retainedSize: i18n.ByteUtilities.bytesToString(this.retainedSize),
589590
'shallowSize-percent': this.toPercentString(shallowSizePercent),
590591
'retainedSize-percent': this.toPercentString(retainedSizePercent),
591592
};
@@ -1035,10 +1036,10 @@ export class HeapSnapshotInstanceNode extends HeapSnapshotGenericObjectNode {
10351036
data['addedCount'] = '';
10361037
data['addedSize'] = '';
10371038
data['removedCount'] = '\u2022';
1038-
data['removedSize'] = Platform.NumberUtilities.withThousandsSeparator(this.shallowSize || 0);
1039+
data['removedSize'] = i18n.ByteUtilities.bytesToString(this.shallowSize || 0);
10391040
} else {
10401041
data['addedCount'] = '\u2022';
1041-
data['addedSize'] = Platform.NumberUtilities.withThousandsSeparator(this.shallowSize || 0);
1042+
data['addedSize'] = i18n.ByteUtilities.bytesToString(this.shallowSize || 0);
10421043
data['removedCount'] = '';
10431044
data['removedSize'] = '';
10441045
}
@@ -1132,8 +1133,8 @@ export class HeapSnapshotConstructorNode extends HeapSnapshotGridNode {
11321133
object: this.nameInternal,
11331134
count: Platform.NumberUtilities.withThousandsSeparator(this.count),
11341135
distance: this.toUIDistance(this.distance),
1135-
shallowSize: Platform.NumberUtilities.withThousandsSeparator(this.shallowSize),
1136-
retainedSize: Platform.NumberUtilities.withThousandsSeparator(this.retainedSize),
1136+
shallowSize: i18n.ByteUtilities.bytesToString(this.shallowSize),
1137+
retainedSize: i18n.ByteUtilities.bytesToString(this.retainedSize),
11371138
'shallowSize-percent': this.toPercentString(shallowSizePercent),
11381139
'retainedSize-percent': this.toPercentString(retainedSizePercent),
11391140
};
@@ -1301,10 +1302,9 @@ export class HeapSnapshotDiffNode extends HeapSnapshotGridNode {
13011302
removedCount: Platform.NumberUtilities.withThousandsSeparator(this.removedCount),
13021303
countDelta: this.signForDelta(this.countDelta) +
13031304
Platform.NumberUtilities.withThousandsSeparator(Math.abs(this.countDelta)),
1304-
addedSize: Platform.NumberUtilities.withThousandsSeparator(this.addedSize),
1305-
removedSize: Platform.NumberUtilities.withThousandsSeparator(this.removedSize),
1306-
sizeDelta:
1307-
this.signForDelta(this.sizeDelta) + Platform.NumberUtilities.withThousandsSeparator(Math.abs(this.sizeDelta)),
1305+
addedSize: i18n.ByteUtilities.bytesToString(this.addedSize),
1306+
removedSize: i18n.ByteUtilities.bytesToString(this.removedSize),
1307+
sizeDelta: this.signForDelta(this.sizeDelta) + i18n.ByteUtilities.bytesToString(Math.abs(this.sizeDelta)),
13081308
};
13091309
}
13101310

@@ -1400,8 +1400,8 @@ export class AllocationGridNode extends HeapSnapshotGridNode {
14001400
this.data = {
14011401
liveCount: Platform.NumberUtilities.withThousandsSeparator(data.liveCount),
14021402
count: Platform.NumberUtilities.withThousandsSeparator(data.count),
1403-
liveSize: Platform.NumberUtilities.withThousandsSeparator(data.liveSize),
1404-
size: Platform.NumberUtilities.withThousandsSeparator(data.size),
1403+
liveSize: i18n.ByteUtilities.bytesToString(data.liveSize),
1404+
size: i18n.ByteUtilities.bytesToString(data.size),
14051405
name: data.name,
14061406
};
14071407
}

test/e2e/helpers/memory-helpers.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,18 @@ export async function expandFocusedRow() {
313313
await waitFor('.selected.data-grid-data-grid-node.expanded');
314314
}
315315

316-
function parseNumberWithSpaces(number: string): number {
317-
return parseInt(number.replaceAll('\xa0', ''), 10);
316+
function parseByteString(str: string): number {
317+
const number = parseFloat(str);
318+
if (str.endsWith('kB')) {
319+
return number * 1000;
320+
}
321+
if (str.endsWith('MB')) {
322+
return number * 1000 * 1000;
323+
}
324+
if (str.endsWith('GB')) {
325+
return number * 1000 * 1000 * 1000;
326+
}
327+
return number;
318328
}
319329

320330
async function getSizesFromRow(row: puppeteer.ElementHandle<Element>) {
@@ -323,8 +333,8 @@ async function getSizesFromRow(row: puppeteer.ElementHandle<Element>) {
323333
function readNumber(e: Element): string {
324334
return e.textContent as string;
325335
}
326-
const shallowSize = parseNumberWithSpaces(await numericData[0].evaluate(readNumber));
327-
const retainedSize = parseNumberWithSpaces(await numericData[2].evaluate(readNumber));
336+
const shallowSize = parseByteString(await numericData[0].evaluate(readNumber));
337+
const retainedSize = parseByteString(await numericData[2].evaluate(readNumber));
328338
assert.isTrue(retainedSize >= shallowSize);
329339
return {shallowSize, retainedSize};
330340
}
@@ -368,13 +378,13 @@ export async function getAddedCountFromComparisonRowWithName(text: string) {
368378
export async function getAddedCountFromComparisonRow(row: puppeteer.ElementHandle<Element>) {
369379
const addedCountCell = await waitFor('.addedCount-column', row);
370380
const countText = await addedCountCell.evaluate(e => e.textContent ?? '');
371-
return parseNumberWithSpaces(countText);
381+
return parseByteString(countText);
372382
}
373383

374384
export async function getRemovedCountFromComparisonRow(row: puppeteer.ElementHandle<Element>) {
375385
const addedCountCell = await waitFor('.removedCount-column', row);
376386
const countText = await addedCountCell.evaluate(e => e.textContent ?? '');
377-
return parseNumberWithSpaces(countText);
387+
return parseByteString(countText);
378388
}
379389

380390
export async function clickOnContextMenuForRetainer(retainerName: string, menuItem: string) {

test/e2e/memory/memory_test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,10 @@ describe('The Memory Panel', function() {
454454
// The Set object is small, regardless of the contained content.
455455
assert.isTrue(sizes.sizesForSet.shallowSize <= 100);
456456
// The Set retains its backing storage.
457+
// Note: 16 bytes is added to retainedSize to account for rounding present in the UI layer.
457458
assert.isTrue(
458-
sizes.sizesForSet.retainedSize >= sizes.sizesForSet.shallowSize + sizes.sizesForBackingStorage.retainedSize);
459+
sizes.sizesForSet.retainedSize + 16 >=
460+
sizes.sizesForSet.shallowSize + sizes.sizesForBackingStorage.retainedSize);
459461
// The backing storage contains 100 items, which occupy at least one pointer per item.
460462
assert.isTrue(sizes.sizesForBackingStorage.shallowSize >= 400);
461463
// The backing storage retains 100 strings, which occupy at least 16 bytes each.

0 commit comments

Comments
 (0)