import { type PerformanceObserverOptions } from '../performance-observer.js'; import type { ActionTrackEntryPayload } from '../user-timing-extensibility-api.type.js'; import { type WalRecord } from '../wal.js'; import { Profiler, type ProfilerOptions } from './profiler.js'; /** * Options for configuring a NodejsProfiler instance. * * Extends ProfilerOptions with a required sink parameter. * * @template Tracks - Record type defining available track names and their configurations */ export type NodejsProfilerOptions> = ProfilerOptions & Omit, 'sink'> & { /** * File path for the WriteAheadLogFile sink. * If not provided, defaults to `trace.json` in the current working directory. * * @default path.join(process.cwd(), 'trace.json') */ filename?: string; /** * Name of the environment variable to check for debug mode. * When the env var is set to 'true', profiler state transitions create performance marks for debugging. * * @default 'CP_PROFILER_DEBUG' */ debugEnvVar?: string; }; /** * Performance profiler with automatic process exit handling for buffered performance data. * * This class extends the base {@link Profiler} with automatic flushing of performance data * when the process exits. It automatically creates a {@link WriteAheadLogFile} sink that buffers * performance entries and ensures they are written out during process termination, even for unexpected exits. * * The sink uses a default codec for serializing performance data to JSON format, * enabling compatibility with Chrome DevTools trace file format. * * The profiler automatically subscribes to the performance observer when enabled and installs * exit handlers that flush buffered data on process termination (signals, fatal errors, or normal exit). * * @template DomainEvents - The type of domain-specific events encoded by the performance observer sink * @template Tracks - Record type defining available track names and their configurations */ export declare class NodejsProfiler = Record> extends Profiler { #private; /** * Creates a NodejsProfiler instance. * A WriteAheadLogFile sink is automatically created for buffering performance data. * @param options - Configuration options */ constructor(options: NodejsProfilerOptions); /** * Returns whether debug mode is enabled for profiler state transitions. * * Debug mode is initially determined by the environment variable specified by `debugEnvVar` * (defaults to 'CP_PROFILER_DEBUG') during construction, but can be changed at runtime * using {@link setDebugMode}. When enabled, profiler state transitions create * performance marks for debugging. * * @returns true if debug mode is enabled, false otherwise */ get debug(): boolean; /** * Sets debug mode for profiler state transitions. * * When debug mode is enabled, profiler state transitions create performance marks * for debugging. This allows runtime control of debug mode without needing to * restart the application or change environment variables. * * @param enabled - Whether to enable debug mode */ setDebugMode(enabled: boolean): void; /** * Closes profiler and releases resources. Idempotent, safe for exit handlers. * **Exit Handler Usage**: Call only this method from process exit handlers. */ close(): void; /** @returns Current profiler state */ get state(): 'idle' | 'running' | 'closed'; /** @returns Whether profiler is in 'running' state */ isEnabled(): boolean; /** Enables profiling (start/stop) */ setEnabled(enabled: boolean): void; /** @returns Queue statistics and profiling state for monitoring */ get stats(): { debug: boolean; state: "idle" | "running" | "closed"; walOpen: boolean; isSubscribed: boolean; queued: number; dropped: number; written: number; maxQueueSize: number; flushThreshold: number; addedSinceLastFlush: number; buffered: boolean; }; /** Flushes buffered performance data to sink. */ flush(): void; /** @returns The file path of the WriteAheadLogFile sink */ get filePath(): string; }