Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

963 B
Raw Blame
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
  }
}