QVAC Logo

profiler

Singleton object that collects and exports profiling data for SDK operations.

const profiler: {
  enable(options?: ProfilerRuntimeOptions): void;
  disable(): void;
  isEnabled(): boolean;
  exportJSON(options?: { includeRecentEvents?: boolean }): ProfilerExport;
  exportTable(): string;
  exportSummary(): string;
  onRecord(callback: (event: ProfilingEvent) => void): () => void;
  getConfig(): ResolvedProfilerConfig;
  getAggregates(): Record<string, AggregatedStats>;
  clear(): void;
};

Methods

MethodDescription
enable()Enables profiling and resets aggregated data
disable()Disables profiling
isEnabled()Returns whether profiling is currently enabled
exportJSON()Exports profiling data as a structured JSON object
exportTable()Exports aggregated stats as a formatted ASCII table
exportSummary()Exports a human-readable summary string
onRecord()Registers a listener for profiling events; returns an unsubscribe function
getConfig()Returns the current effective profiler configuration
getAggregates()Returns all aggregated stats keyed by operation name
clear()Clears all aggregated data and recent events

enable()

function enable(options?: ProfilerRuntimeOptions): void

Enables profiling and resets all previously aggregated data.

Parameters

NameTypeRequired?Description
optionsProfilerRuntimeOptionsRuntime profiler options

ProfilerRuntimeOptions

FieldTypeRequired?DefaultDescription
mode"summary" | "verbose""summary"Profiling detail level — "verbose" retains recent events
includeServerBreakdownbooleanfalseInclude server-side timing breakdown in profiling data
operationFiltersstring[][]Only profile operations whose names match these filters (empty = all)

Returns

void

disable()

function disable(): void

Disables profiling. New SDK operations will no longer be recorded.

Parameters

No parameters.

Returns

void

isEnabled()

function isEnabled(): boolean

Returns whether profiling is currently enabled.

Parameters

No parameters.

Returns

booleantrue if profiling is enabled, false otherwise.

exportJSON()

function exportJSON(options?: { includeRecentEvents?: boolean }): ProfilerExport

Exports profiling data as a structured JSON object.

Parameters

NameTypeRequired?Description
optionsobjectExport options
options.includeRecentEventsbooleanInclude recent events in the export (only available in "verbose" mode)

Returns

ProfilerExport — structured JSON object containing configuration snapshot, aggregated statistics, and optionally recent events.

ProfilerExport

FieldTypeDescription
configobjectSnapshot of the profiler configuration at export time
config.enabledbooleanWhether profiling was enabled
config.mode"summary" | "verbose"Profiling mode
config.includeServerBreakdownbooleanWhether server breakdown was enabled
config.operationFiltersstring[]Active operation filters
config.maxRecentEventsnumberMax recent events setting
aggregatesRecord<string, AggregatedStats>Aggregated statistics keyed by operation name
recentEventsProfilingEvent[]Recent profiling events (only when includeRecentEvents: true)
exportedAtnumberMonotonic timestamp of the export

AggregatedStats

Per-operation aggregated statistics:

FieldTypeDescription
countnumberNumber of recorded events
minnumberMinimum duration in milliseconds
maxnumberMaximum duration in milliseconds
avgnumberAverage duration in milliseconds
sumnumberTotal accumulated duration in milliseconds
lastnumberMost recent duration in milliseconds

ProfilingEvent

Individual profiling event recorded during an SDK operation:

FieldTypeRequired?Description
tsnumberMonotonic timestamp in milliseconds
opstringOperation name (e.g., "completion", "loadModel")
kindProfilingEventKindEvent category
profileIdstringUnique identifier for the profiling session
phasestringSub-phase within the operation (e.g., "rpc.send", "handler.run")
msnumberDuration in milliseconds
countnumberCount metric (e.g., tokens, chunks)
bytesnumberByte count metric
gaugesRecord<string, number>Numeric gauges (e.g., throughput, token counters)
tagsRecord<string, string>String tags (e.g., handlerType, sourceType, modelId)

ProfilingEventKind

"rpc" | "handler" | "download" | "load" | "delegation"

exportTable()

function exportTable(): string

Exports aggregated stats as a formatted ASCII table suitable for console output.

Parameters

No parameters.

Returns

string — formatted ASCII table of all aggregated profiling data.

exportSummary()

function exportSummary(): string

Exports a human-readable summary of all aggregated profiling data.

Parameters

No parameters.

Returns

string — human-readable summary string.

onRecord()

function onRecord(callback: (event: ProfilingEvent) => void): () => void

Registers a listener that is called for every profiling event.

Parameters

NameTypeRequired?Description
callback(event: ProfilingEvent) => voidFunction called with each profiling event

Returns

() => void — an unsubscribe function. Call it to stop receiving events.

getConfig()

function getConfig(): ResolvedProfilerConfig

Returns the current effective profiler configuration.

Parameters

No parameters.

Returns

ResolvedProfilerConfig:

ResolvedProfilerConfig

FieldTypeDescription
enabledbooleanWhether profiling is currently enabled
mode"summary" | "verbose"Active profiling mode
includeServerBreakdownbooleanWhether server breakdown is included
operationFiltersstring[]Active operation filters
maxRecentEventsnumberMaximum number of recent events retained (default 1000)

getAggregates()

function getAggregates(): Record<string, AggregatedStats>

Returns all aggregated stats keyed by operation name.

Parameters

No parameters.

Returns

Record<string, AggregatedStats> — all aggregated stats keyed by operation name.

clear()

function clear(): void

Clears all aggregated data and recent events. Does not disable profiling.

Parameters

No parameters.

Returns

void

Example

import { profiler, completion, loadModel } from "@qvac/sdk";

profiler.enable({ mode: "verbose", includeServerBreakdown: true });

const modelId = await loadModel({
  modelSrc: "/path/to/model.gguf",
  modelType: "llm",
});

const result = completion({
  modelId,
  history: [{ role: "user", content: "Hello!" }],
});

await result.text;

console.log(profiler.exportTable());

const json = profiler.exportJSON({ includeRecentEvents: true });
console.log("Aggregates:", json.aggregates);

profiler.clear();
profiler.disable();

On this page