Files
orca/src/preload/renderer-heap-statistics-reader.ts
T
OrcaWinandOrcaWin 0efc842028 [comment audit] Shorten preload comments (#32257)
* chore: audit preload root comments and track repository coverage

* docs: track repository comment audit coverage

* chore: keep comment audit tracker local

* chore: shorten preload API contract comments

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 02:16:59 -07:00

33 lines
963 B
TypeScript

import type { RendererHeapStatistics } from '../shared/renderer-heap-statistics'
type HeapStatisticsSource = Pick<NodeJS.Process, 'getHeapStatistics' | 'getBlinkMemoryInfo'>
// performance.memory quantizes and caches values, hiding heap growth.
export function readRendererHeapStatistics(
source: HeapStatisticsSource = process
): RendererHeapStatistics | null {
let heap: Electron.HeapStatistics
try {
heap = source.getHeapStatistics()
} catch {
// Diagnostics must tolerate missing Electron APIs.
return null
}
let blinkAllocatedKB: number | undefined
try {
// A failed supplementary Blink read must not discard the V8 measurements.
blinkAllocatedKB = source.getBlinkMemoryInfo().allocated
} catch {
blinkAllocatedKB = undefined
}
return {
usedHeapKB: heap.usedHeapSize,
totalHeapKB: heap.totalHeapSize,
heapLimitKB: heap.heapSizeLimit,
mallocedKB: heap.mallocedMemory,
blinkAllocatedKB
}
}