UNPKG

@hirosystems/api-toolkit

Version:
30 lines (29 loc) 1.53 kB
import * as inspector from 'inspector'; import * as stream from 'stream'; import { Stopwatch } from '../helpers'; export type CpuProfileResult = inspector.Profiler.Profile; export interface ProfilerInstance<TStopResult = void> { start: () => Promise<void>; stop: () => Promise<TStopResult>; dispose: () => Promise<void>; session: inspector.Session; sessionType: 'cpu' | 'memory'; stopwatch: Stopwatch; } /** * Connects and enables a new `inspector` session, then starts an internal v8 CPU profiling process. * @returns A function to stop the profiling, and return the CPU profile result object. * The result object can be used to create a `.cpuprofile` file using JSON.stringify. * Use VSCode or Chrome's 'DevTools for Node' (under chrome://inspect) to visualize the `.cpuprofile` file. * @param samplingInterval - Optionally set sampling interval in microseconds, default is 1000 microseconds. */ export declare function initCpuProfiling(samplingInterval?: number): ProfilerInstance<CpuProfileResult>; /** * Connects and enables a new `inspector` session, then creates an internal v8 Heap profiler snapshot. * @param outputStream - An output stream that heap snapshot chunks are written to. * The result stream can be used to create a `.heapsnapshot` file. * Use Chrome's 'DevTools for Node' (under chrome://inspect) to visualize the `.heapsnapshot` file. */ export declare function initHeapSnapshot(outputStream: stream.Writable): ProfilerInstance<{ totalSnapshotByteSize: number; }>;