New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@code-pushup/utils

Package Overview
Dependencies
Maintainers
3
Versions
253
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@code-pushup/utils - npm Package Compare versions

Comparing version
0.109.0
to
0.110.0
+183
src/lib/profiler/trace-file-utils.d.ts
import type { PerformanceEntry, PerformanceMark, PerformanceMeasure } from 'node:perf_hooks';
import type { UserTimingDetail } from '../user-timing-extensibility-api.type.js';
import type { BeginEvent, CompleteEvent, EndEvent, InstantEvent, InstantEventArgs, InstantEventTracingStartedInBrowser, SpanEventArgs, TraceEvent, TraceEventContainer, TraceEventRaw, TraceMetadata, UserTimingTraceEvent } from './trace-file.type.js';
/**
* Generates a unique ID for linking begin and end span events in Chrome traces.
* @returns Object with local ID string for the id2 field
*/
export declare const nextId2: () => {
local: string;
};
/**
* Generates a unique frame tree node ID from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Combined numeric ID
*/
export declare const frameTreeNodeId: (pid: number, tid: number) => number;
/**
* Generates a frame name string from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Formatted frame name
*/
export declare const frameName: (pid: number, tid: number) => string;
/**
* Creates an instant trace event for marking a point in time.
* @param opt - Event configuration options
* @returns InstantEvent object
*/
export declare const getInstantEvent: (opt: {
name: string;
ts?: number;
pid?: number;
tid?: number;
args?: InstantEventArgs;
}) => InstantEvent;
/**
* Creates a start tracing event with frame information.
* This event is needed at the beginning of the traceEvents array to make tell the UI profiling has started, and it should visualize the data.
* @param opt - Tracing configuration options
* @returns StartTracingEvent object
*/
export declare const getInstantEventTracingStartedInBrowser: (opt: {
url: string;
ts?: number;
pid?: number;
tid?: number;
}) => InstantEventTracingStartedInBrowser;
/**
* Creates a complete trace event with duration.
* @param opt - Event configuration with name and duration
* @returns CompleteEvent object
*/
export declare const getCompleteEvent: (opt: {
name: string;
dur: number;
ts?: number;
pid?: number;
tid?: number;
}) => CompleteEvent;
/** Options for creating span events */
type SpanOpt = {
name: string;
id2: {
local: string;
};
ts?: number;
pid?: number;
tid?: number;
args?: SpanEventArgs;
};
/**
* Creates a begin span event.
* @param ph - Phase ('b' for begin)
* @param opt - Span event options
* @returns BeginEvent object
*/
export declare function getSpanEvent(ph: 'b', opt: SpanOpt): BeginEvent;
/**
* Creates an end span event.
* @param ph - Phase ('e' for end)
* @param opt - Span event options
* @returns EndEvent object
*/
export declare function getSpanEvent(ph: 'e', opt: SpanOpt): EndEvent;
/**
* Creates a pair of begin and end span events.
* @param opt - Span configuration with start/end timestamps
* @returns Tuple of BeginEvent and EndEvent
*/
export declare const getSpan: (opt: {
name: string;
tsB: number;
tsE: number;
id2?: {
local: string;
};
pid?: number;
tid?: number;
args?: SpanEventArgs;
tsMarkerPadding?: number;
}) => [BeginEvent, EndEvent];
/**
* Converts a PerformanceMark to an instant trace event.
* @param entry - Performance mark entry
* @param opt - Optional overrides for name, pid, and tid
* @returns InstantEvent object
*/
export declare const markToInstantEvent: (entry: PerformanceMark, opt?: {
name?: string;
pid?: number;
tid?: number;
}) => InstantEvent;
/**
* Converts a PerformanceMeasure to a pair of span events.
* @param entry - Performance measure entry
* @param opt - Optional overrides for name, pid, and tid
* @returns Tuple of BeginEvent and EndEvent
*/
export declare const measureToSpanEvents: (entry: PerformanceMeasure, opt?: {
name?: string;
pid?: number;
tid?: number;
}) => [BeginEvent, EndEvent];
/**
* Converts a PerformanceEntry to an array of UserTimingTraceEvents.
* A mark is converted to an instant event, and a measure is converted to a pair of span events.
* Other entry types are ignored.
* @param entry - Performance entry
* @returns UserTimingTraceEvent[]
*/
export declare function entryToTraceEvents(entry: PerformanceEntry): UserTimingTraceEvent[];
/**
* Creates trace metadata object with standard DevTools fields and custom metadata.
* @param startDate - Optional start date for the trace, defaults to current date
* @param metadata - Optional additional metadata to merge into the trace metadata
* @returns TraceMetadata object with source, startTime, and merged custom metadata
*/
export declare function getTraceMetadata(startDate?: Date, metadata?: Record<string, unknown>): {
source: string;
startTime: string;
hardwareConcurrency: number;
dataOrigin: string;
};
/**
* Creates a complete trace file container with metadata.
* @param opt - Trace file configuration
* @returns TraceEventContainer with events and metadata
*/
export declare const getTraceFile: (opt: {
traceEvents: TraceEvent[];
startTime?: string;
metadata?: Partial<TraceMetadata>;
}) => TraceEventContainer;
/**
* Decodes a JSON string detail property back to its original object form.
* @param target - Object containing a detail property as a JSON string
* @returns UserTimingDetail with the detail property parsed from JSON
*/
export declare function decodeDetail(target: {
detail: string;
}): UserTimingDetail;
/**
* Encodes object detail properties to JSON strings for storage/transmission.
* @param target - UserTimingDetail object with detail property to encode
* @returns UserTimingDetail with object details converted to JSON strings
*/
export declare function encodeDetail(target: UserTimingDetail): UserTimingDetail;
/**
* Decodes a raw trace event with JSON string details back to typed UserTimingTraceEvent.
* Parses detail properties from JSON strings to objects.
* @param event - Raw trace event with string-encoded details
* @returns UserTimingTraceEvent with parsed detail objects
*/
export declare function decodeTraceEvent({ args, ...rest }: TraceEventRaw): UserTimingTraceEvent;
/**
* Encodes a UserTimingTraceEvent to raw format with JSON string details.
* Converts object details to JSON strings for storage/transmission.
* @param event - UserTimingTraceEvent with object details
* @returns TraceEventRaw with string-encoded details
*/
export declare function encodeTraceEvent({ args, ...rest }: UserTimingTraceEvent): TraceEventRaw;
export {};
import { threadId } from 'node:worker_threads';
import { defaultClock } from '../clock-epoch.js';
/** Global counter for generating unique span IDs within a trace */
// eslint-disable-next-line functional/no-let
let id2Count = 0;
/**
* Generates a unique ID for linking begin and end span events in Chrome traces.
* @returns Object with local ID string for the id2 field
*/
export const nextId2 = () => ({ local: `0x${++id2Count}` });
/**
* Provides default values for trace event properties.
* @param opt - Optional overrides for process ID, thread ID, and timestamp
* @param opt.pid - Process ID override, defaults to current process PID
* @param opt.tid - Thread ID override, defaults to current thread ID
* @param opt.ts - Timestamp override in microseconds, defaults to current epoch time
* @returns Object containing pid, tid, and ts with defaults applied
*/
const defaults = (opt) => ({
pid: opt?.pid ?? process.pid,
tid: opt?.tid ?? threadId,
ts: opt?.ts ?? defaultClock.epochNowUs(),
});
/**
* Generates a unique frame tree node ID from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Combined numeric ID
*/
export const frameTreeNodeId = (pid, tid) => Number.parseInt(`${pid}0${tid}`, 10);
/**
* Generates a frame name string from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Formatted frame name
*/
export const frameName = (pid, tid) => `FRAME0P${pid}T${tid}`;
/**
* Creates an instant trace event for marking a point in time.
* @param opt - Event configuration options
* @returns InstantEvent object
*/
export const getInstantEvent = (opt) => ({
cat: 'blink.user_timing',
ph: 'i',
name: opt.name,
...defaults(opt),
args: opt.args ?? {},
});
/**
* Creates a start tracing event with frame information.
* This event is needed at the beginning of the traceEvents array to make tell the UI profiling has started, and it should visualize the data.
* @param opt - Tracing configuration options
* @returns StartTracingEvent object
*/
export const getInstantEventTracingStartedInBrowser = (opt) => {
const { pid, tid, ts } = defaults(opt);
const id = frameTreeNodeId(pid, tid);
return {
cat: 'devtools.timeline',
ph: 'i',
name: 'TracingStartedInBrowser',
pid,
tid,
ts,
args: {
data: {
frameTreeNodeId: id,
frames: [
{
frame: frameName(pid, tid),
isInPrimaryMainFrame: true,
isOutermostMainFrame: true,
name: '',
processId: pid,
url: opt.url,
},
],
persistentIds: true,
},
},
};
};
/**
* Creates a complete trace event with duration.
* @param opt - Event configuration with name and duration
* @returns CompleteEvent object
*/
export const getCompleteEvent = (opt) => ({
cat: 'devtools.timeline',
ph: 'X',
name: opt.name,
dur: opt.dur,
...defaults(opt),
args: {},
});
/**
* Creates a span event (begin or end).
* @param ph - Phase ('b' or 'e')
* @param opt - Span event options
* @returns SpanEvent object
*/
export function getSpanEvent(ph, opt) {
return {
cat: 'blink.user_timing',
ph,
name: opt.name,
id2: opt.id2,
...defaults(opt),
args: opt.args?.data?.detail
? { data: { detail: opt.args.data.detail } }
: {},
};
}
/**
* Creates a pair of begin and end span events.
* @param opt - Span configuration with start/end timestamps
* @returns Tuple of BeginEvent and EndEvent
*/
export const getSpan = (opt) => {
// tsMarkerPadding is here to make the measure slightly smaller so the markers align perfectly.
// Otherwise, the marker is visible at the start of the measure below the frame
// No padding Padding
// spans: ======== |======|
// marks: | |
const pad = opt.tsMarkerPadding ?? 1;
// b|e need to share the same id2
const id2 = opt.id2 ?? nextId2();
return [
getSpanEvent('b', {
...opt,
id2,
ts: opt.tsB + pad,
}),
getSpanEvent('e', {
...opt,
id2,
ts: opt.tsE - pad,
}),
];
};
/**
* Converts a PerformanceMark to an instant trace event.
* @param entry - Performance mark entry
* @param opt - Optional overrides for name, pid, and tid
* @returns InstantEvent object
*/
export const markToInstantEvent = (entry, opt) => getInstantEvent({
...opt,
name: opt?.name ?? entry.name,
ts: defaultClock.fromEntry(entry),
args: entry.detail ? { detail: entry.detail } : undefined,
});
/**
* Converts a PerformanceMeasure to a pair of span events.
* @param entry - Performance measure entry
* @param opt - Optional overrides for name, pid, and tid
* @returns Tuple of BeginEvent and EndEvent
*/
export const measureToSpanEvents = (entry, opt) => getSpan({
...opt,
name: opt?.name ?? entry.name,
tsB: defaultClock.fromEntry(entry),
tsE: defaultClock.fromEntry(entry, true),
args: entry.detail ? { data: { detail: entry.detail } } : undefined,
});
/**
* Converts a PerformanceEntry to an array of UserTimingTraceEvents.
* A mark is converted to an instant event, and a measure is converted to a pair of span events.
* Other entry types are ignored.
* @param entry - Performance entry
* @returns UserTimingTraceEvent[]
*/
export function entryToTraceEvents(entry) {
if (entry.entryType === 'mark') {
return [markToInstantEvent(entry)];
}
if (entry.entryType === 'measure') {
return measureToSpanEvents(entry);
}
return [];
}
/**
* Creates trace metadata object with standard DevTools fields and custom metadata.
* @param startDate - Optional start date for the trace, defaults to current date
* @param metadata - Optional additional metadata to merge into the trace metadata
* @returns TraceMetadata object with source, startTime, and merged custom metadata
*/
export function getTraceMetadata(startDate, metadata) {
return {
source: 'DevTools',
startTime: startDate?.toISOString() ?? new Date().toISOString(),
hardwareConcurrency: 1,
dataOrigin: 'TraceEvents',
...metadata,
};
}
/**
* Creates a complete trace file container with metadata.
* @param opt - Trace file configuration
* @returns TraceEventContainer with events and metadata
*/
export const getTraceFile = (opt) => ({
traceEvents: opt.traceEvents,
displayTimeUnit: 'ms',
metadata: getTraceMetadata(opt.startTime ? new Date(opt.startTime) : new Date(), opt.metadata),
});
/**
* Processes the detail property of an object using a custom processor function.
* @template T - Object type that may contain a detail property
* @param target - Object containing the detail property to process
* @param processor - Function to transform the detail value
* @returns New object with processed detail property, or original object if no detail
*/
function processDetail(target, processor) {
if (target.detail != null &&
(typeof target.detail === 'string' || typeof target.detail === 'object')) {
return { ...target, detail: processor(target.detail) };
}
return target;
}
/**
* Decodes a JSON string detail property back to its original object form.
* @param target - Object containing a detail property as a JSON string
* @returns UserTimingDetail with the detail property parsed from JSON
*/
export function decodeDetail(target) {
return processDetail(target, detail => typeof detail === 'string'
? JSON.parse(detail)
: detail);
}
/**
* Encodes object detail properties to JSON strings for storage/transmission.
* @param target - UserTimingDetail object with detail property to encode
* @returns UserTimingDetail with object details converted to JSON strings
*/
export function encodeDetail(target) {
return processDetail(target, (detail) => typeof detail === 'object'
? JSON.stringify(detail)
: detail);
}
/**
* Decodes a raw trace event with JSON string details back to typed UserTimingTraceEvent.
* Parses detail properties from JSON strings to objects.
* @param event - Raw trace event with string-encoded details
* @returns UserTimingTraceEvent with parsed detail objects
*/
export function decodeTraceEvent({ args, ...rest }) {
if (!args) {
return rest;
}
const processedArgs = decodeDetail(args);
if ('data' in args && args.data && typeof args.data === 'object') {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return {
...rest,
args: {
...processedArgs,
data: decodeDetail(args.data),
},
};
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return { ...rest, args: processedArgs };
}
/**
* Encodes a UserTimingTraceEvent to raw format with JSON string details.
* Converts object details to JSON strings for storage/transmission.
* @param event - UserTimingTraceEvent with object details
* @returns TraceEventRaw with string-encoded details
*/
export function encodeTraceEvent({ args, ...rest }) {
if (!args) {
return rest;
}
const processedArgs = encodeDetail(args);
if ('data' in args && args.data && typeof args.data === 'object') {
const result = {
...rest,
args: {
...processedArgs,
data: encodeDetail(args.data),
},
};
return result;
}
const result = { ...rest, args: processedArgs };
return result;
}
//# sourceMappingURL=trace-file-utils.js.map
{"version":3,"file":"trace-file-utils.js","sourceRoot":"","sources":["../../../../src/lib/profiler/trace-file-utils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAkBjD,mEAAmE;AACnE,6CAA6C;AAC7C,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,QAAQ,GAAG,CAAC,GAAiD,EAAE,EAAE,CAAC,CAAC;IACvE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG;IAC5B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,QAAQ;IACzB,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,YAAY,CAAC,UAAU,EAAE;CACzC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAC1D,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;AAE9E;;;;GAIG;AACH,MAAM,C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.js';
/**
* Arguments for instant trace events.
* @property {UserTimingDetail} [detail] - Optional user timing detail with DevTools payload
*/
export type InstantEventArgs = {
detail?: UserTimingDetail;
} & {
[key: string]: unknown;
};
/**
* Arguments for span trace events (begin/end events).
* @property {object} [data] - Optional data object
* @property {UserTimingDetail} [data.detail] - Optional user timing detail with DevTools payload
*/
export type SpanEventArgs = {
data?: {
detail?: UserTimingDetail;
};
} & {
[key: string]: unknown;
};
/**
* Arguments for complete trace events.
* @property {Record<string, unknown>} [detail] - Optional detail object with arbitrary properties
*/
export type CompleteEventArgs = {
detail?: Record<string, unknown>;
};
/**
* Arguments for start tracing events.
* @property {object} data - Tracing initialization data
* @property {number} data.frameTreeNodeId - Frame tree node identifier
* @property {Array} data.frames - Array of frame information
* @property {boolean} data.persistentIds - Whether IDs are persistent
*/
export type InstantEventTracingStartedInBrowserArgs = {
data: {
frameTreeNodeId: number;
frames: {
frame: string;
isInPrimaryMainFrame: boolean;
isOutermostMainFrame: boolean;
name: string;
processId: number;
url: string;
}[];
persistentIds: boolean;
};
};
/**
* Union type of all possible trace event arguments.
*/
export type TraceArgs = InstantEventArgs | SpanEventArgs | CompleteEventArgs | InstantEventTracingStartedInBrowserArgs;
/**
* Base properties shared by all trace events.
* @property {string} cat - Event category
* @property {string} name - Event name
* @property {number} pid - Process ID
* @property {number} tid - Thread ID
* @property {number} ts - Timestamp in epoch microseconds
* @property {TraceArgs} [args] - Optional event arguments
*/
export type BaseTraceEvent = {
cat: string;
name: string;
pid: number;
tid: number;
ts: number;
args: TraceArgs;
};
/**
* Start tracing event for Chrome DevTools tracing.
*/
export type InstantEventTracingStartedInBrowser = BaseTraceEvent & {
cat: 'devtools.timeline';
ph: 'i';
name: 'TracingStartedInBrowser';
args: InstantEventTracingStartedInBrowserArgs;
};
/**
* Complete trace event with duration.
* Represents a complete operation with start time and duration.
* @property {'X'} ph - Phase indicator for complete events
* @property {number} dur - Duration in microseconds
*/
export type CompleteEvent = BaseTraceEvent & {
ph: 'X';
dur: number;
};
/**
* Instant trace event representing a single point in time.
* Used for user timing marks and other instantaneous events.
* @property {'blink.user_timing'} cat - Fixed category for user timing events
* @property {'i'} ph - Phase indicator for instant events
* @property {never} [dur] - Duration is not applicable for instant events
* @property {InstantEventArgs} [args] - Optional event arguments
*/
export type InstantEvent = Omit<BaseTraceEvent, 'cat' | 'args'> & {
cat: 'blink.user_timing';
ph: 'i';
dur?: never;
args: InstantEventArgs;
};
/**
* Core properties for span trace events (begin/end pairs).
* @property {object} id2 - Span identifier
* @property {string} id2.local - Local span ID (unique to the process, same for b and e events)
* @property {SpanEventArgs} [args] - Optional event arguments
*/
type SpanCore = Omit<BaseTraceEvent, 'args'> & {
id2: {
local: string;
};
args: SpanEventArgs;
};
/**
* Begin event for a span (paired with an end event).
* @property {'b'} ph - Phase indicator for begin events
* @property {never} [dur] - Duration is not applicable for begin events
*/
export type BeginEvent = SpanCore & {
ph: 'b';
dur?: never;
};
/**
* End event for a span (paired with a begin event).
* @property {'e'} ph - Phase indicator for end events
* @property {never} [dur] - Duration is not applicable for end events
*/
export type EndEvent = SpanCore & {
ph: 'e';
dur?: never;
};
/**
* Union type for span events (begin or end).
*/
export type SpanEvent = BeginEvent | EndEvent;
/**
* Union type of all trace event types.
*/
export type UserTimingTraceEvent = InstantEvent | SpanEvent;
/**
* All trace events including system events added during finalization.
*/
export type TraceEvent = UserTimingTraceEvent | CompleteEvent | InstantEventTracingStartedInBrowser;
/**
* Raw arguments format for trace events before processing.
* Either contains a detail string directly or nested in a data object.
*/
type RawArgs = {
detail?: string;
[key: string]: unknown;
} | {
data?: {
detail?: string;
};
[key: string]: unknown;
};
/**
* Raw trace event format before type conversion.
* Similar to TraceEvent but with unprocessed arguments.
*/
export type TraceEventRaw = Omit<TraceEvent, 'args'> & {
args: RawArgs;
};
/**
* Time window bounds (min, max) in trace time units (e.g. microseconds).
* @property {number} min - Minimum timestamp in the window
* @property {number} max - Maximum timestamp in the window
* @property {number} range - Calculated range (max - min)
*/
export type BreadcrumbWindow = {
min: number;
max: number;
range: number;
};
/**
* Custom label for a specific trace entry.
* @property {number | string} entryId - ID or index of the trace entry
* @property {string} label - Label text for the entry
* @property {string} [color] - Optional display color for the label
*/
export type EntryLabel = {
entryId: number | string;
label: string;
color?: string;
};
/**
* Link or relation between two trace entries.
* @property {number | string} fromEntryId - Source entry ID for the link
* @property {number | string} toEntryId - Target entry ID for the link
* @property {string} [linkType] - Optional type or description of the link
*/
export type EntryLink = {
fromEntryId: number | string;
toEntryId: number | string;
linkType?: string;
};
/**
* A time range annotated with a label.
* @property {number} startTime - Start timestamp of the range (microseconds)
* @property {number} endTime - End timestamp of the range (microseconds)
* @property {string} label - Annotation label for the time range
* @property {string} [color] - Optional display color for the range
*/
export type LabelledTimeRange = {
startTime: number;
endTime: number;
label: string;
color?: string;
};
/**
* Hidden or expandable entries information.
* @property {unknown[]} hiddenEntries - IDs or indexes of hidden entries
* @property {unknown[]} expandableEntries - IDs or indexes of expandable entries
*/
export type EntriesModifications = {
hiddenEntries: unknown[];
expandableEntries: unknown[];
};
/**
* Initial breadcrumb information for time ranges and window.
* @property {BreadcrumbWindow} window - Time window bounds
* @property {unknown | null} child - Child breadcrumb or null
*/
export type InitialBreadcrumb = {
window: BreadcrumbWindow;
child: unknown | null;
};
/**
* Annotations such as labels and links between entries.
* @property {EntryLabel[]} entryLabels - Custom labels for entries
* @property {LabelledTimeRange[]} labelledTimeRanges - Time ranges annotated with labels
* @property {EntryLink[]} linksBetweenEntries - Links or relations between entries
*/
export type Annotations = {
entryLabels: EntryLabel[];
labelledTimeRanges: LabelledTimeRange[];
linksBetweenEntries: EntryLink[];
};
/**
* Modifications made to trace data or UI in DevTools export
*/
export type Modifications = {
entriesModifications: EntriesModifications;
initialBreadcrumb: InitialBreadcrumb;
annotations: Annotations;
};
/**
* Top-level metadata for a trace file exported by Chrome DevTools.
* DevTools may add new fields over time.
*/
export type TraceMetadata = {
/** Usually "DevTools" for exports from the Performance panel */
source: string;
/** ISO timestamp when trace was recorded */
startTime: string;
/** May be present when recorded with throttling settings */
hardwareConcurrency?: number;
/** Common fields found in DevTools traces */
cpuThrottling?: number;
networkThrottling?: string;
enhancedTraceVersion?: number;
/** Allow additional custom metadata properties */
[key: string]: unknown;
};
/**
* Structured container for trace events with metadata.
* @property {TraceEvent[]} traceEvents - Array of trace events
* @property {'ms' | 'ns'} [displayTimeUnit] - Time unit for display (milliseconds or nanoseconds)
* @property {TraceMetadata} [metadata] - Optional metadata about the trace
*/
export type TraceEventContainer = {
traceEvents: TraceEvent[];
displayTimeUnit?: 'ms' | 'ns';
metadata?: TraceMetadata;
};
/**
* Trace file format - either an array of events or a structured container.
*/
export type TraceFile = TraceEvent[] | TraceEventContainer;
export {};
export {};
//# sourceMappingURL=trace-file.type.js.map
{"version":3,"file":"trace-file.type.js","sourceRoot":"","sources":["../../../../src/lib/profiler/trace-file.type.ts"],"names":[],"mappings":""}
import type { InvalidEntry } from '../wal.js';
import type { UserTimingTraceEvent } from './trace-file.type.js';
/**
* Generates a complete Chrome DevTools trace file content as JSON string.
* Adds margin events around the trace events and includes metadata.
* @param events - Array of user timing trace events to include
* @param metadata - Optional custom metadata to include in the trace file
* @returns JSON string representation of the complete trace file
*/
export declare function generateTraceContent(events: UserTimingTraceEvent[], metadata?: Record<string, unknown>): string;
/**
* Creates a WAL (Write-Ahead Logging) format configuration for Chrome DevTools trace files.
* Automatically finalizes shards into complete trace files with proper metadata and margin events.
* @returns WalFormat configuration object with baseName, codec, extensions, and finalizer
*/
export declare function traceEventWalFormat(): {
baseName: string;
walExtension: string;
finalExtension: string;
codec: {
encode: (event: UserTimingTraceEvent) => string;
decode: (json: string) => UserTimingTraceEvent;
};
finalizer: (records: (UserTimingTraceEvent | InvalidEntry<string>)[], metadata?: Record<string, unknown>) => string;
};
import { defaultClock } from '../clock-epoch.js';
import { decodeTraceEvent, encodeTraceEvent, getCompleteEvent, getInstantEventTracingStartedInBrowser, getTraceFile, } from './trace-file-utils.js';
/** Name for the trace start margin event */
const TRACE_START_MARGIN_NAME = '[trace padding start]';
/** Name for the trace end margin event */
const TRACE_END_MARGIN_NAME = '[trace padding end]';
/** Microseconds of padding to add before/after trace events (1000ms = 1,000,000μs) */
const TRACE_MARGIN_US = 1_000_000;
/** Duration in microseconds for margin events (20ms = 20,000μs) */
const TRACE_MARGIN_DURATION_US = 20_000;
/**
* Generates a complete Chrome DevTools trace file content as JSON string.
* Adds margin events around the trace events and includes metadata.
* @param events - Array of user timing trace events to include
* @param metadata - Optional custom metadata to include in the trace file
* @returns JSON string representation of the complete trace file
*/
export function generateTraceContent(events, metadata) {
const traceContainer = getTraceFile({
traceEvents: events,
startTime: new Date().toISOString(),
metadata: {
...metadata,
generatedAt: new Date().toISOString(),
},
});
const marginUs = TRACE_MARGIN_US;
const marginDurUs = TRACE_MARGIN_DURATION_US;
const sortedEvents = [...events].sort((a, b) => a.ts - b.ts);
const fallbackTs = defaultClock.epochNowUs();
const firstTs = sortedEvents.at(0)?.ts ?? fallbackTs;
const lastTs = sortedEvents.at(-1)?.ts ?? fallbackTs;
const startTs = firstTs - marginUs;
const endTs = lastTs + marginUs;
const traceEvents = [
getInstantEventTracingStartedInBrowser({
ts: startTs,
url: events.length === 0 ? 'empty-trace' : 'generated-trace',
}),
getCompleteEvent({
name: TRACE_START_MARGIN_NAME,
ts: startTs,
dur: marginDurUs,
}),
...sortedEvents,
getCompleteEvent({
name: TRACE_END_MARGIN_NAME,
ts: endTs,
dur: marginDurUs,
}),
];
return JSON.stringify({ ...traceContainer, traceEvents });
}
/**
* Creates a WAL (Write-Ahead Logging) format configuration for Chrome DevTools trace files.
* Automatically finalizes shards into complete trace files with proper metadata and margin events.
* @returns WalFormat configuration object with baseName, codec, extensions, and finalizer
*/
export function traceEventWalFormat() {
const baseName = 'trace';
const walExtension = '.jsonl';
const finalExtension = '.json';
return {
baseName,
walExtension,
finalExtension,
codec: {
encode: (event) => JSON.stringify(encodeTraceEvent(event)),
decode: (json) => decodeTraceEvent(JSON.parse(json)),
},
finalizer: (records, metadata) => {
const validRecords = records.filter((r) => !(typeof r === 'object' && r != null && '__invalid' in r));
return generateTraceContent(validRecords, metadata);
},
};
}
//# sourceMappingURL=wal-json-trace.js.map
{"version":3,"file":"wal-json-trace.js","sourceRoot":"","sources":["../../../../src/lib/profiler/wal-json-trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,sCAAsC,EACtC,YAAY,GACb,MAAM,uBAAuB,CAAC;AAG/B,4CAA4C;AAC5C,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AACxD,0CAA0C;AAC1C,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AACpD,sFAAsF;AACtF,MAAM,eAAe,GAAG,SAAS,CAAC;AAClC,mEAAmE;AACnE,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAA8B,EAC9B,QAAkC;IAElC,MAAM,cAAc,GAAG,YAAY,CAAC;QAClC,WAAW,EAAE,MAAM;QACnB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,QAAQ,EAAE;YACR,GAAG,QAAQ;YACX,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACtC;KACF,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,eAAe,CAAC;IACjC,MAAM,WAAW,GAAG,wBAAwB,CAAC;IAE7C,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,EAAE,CAAC;IAC7C,MAAM,OAAO,GAAW,YAAY,CAAC,EAAE,CAAC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,EAClC,EAAE;YACF,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CACjC,CAAC,CAAC,EAA6B,EAAE,CAC/B,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,WAAW,IAAI,CAAC,CAAC,CAC5D,CAAC;YACF,OAAO,oBAAoB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC;KACwC,CAAC;AAC9C,CAAC"}
/**
* Codec for encoding/decoding values to/from strings for WAL storage.
* Used to serialize/deserialize records written to and read from WAL files.
*/
export type Codec<I, O = string> = {
/** Encode a value to a string for storage */
encode: (v: I) => O;
/** Decode a string back to the original value type */
decode: (data: O) => I;
};
export type InvalidEntry<O = string> = {
__invalid: true;
raw: O;
};
/**
* Interface for sinks that can append items.
* Allows for different types of appendable storage (WAL, in-memory, etc.)
*/
export type AppendableSink<T> = {
append: (item: T) => void;
};
/**
* Result of recovering records from a WAL file.
* Contains successfully recovered records and any errors encountered during parsing.
*/
export type RecoverResult<T> = {
/** Successfully recovered records */
records: T[];
/** Errors encountered during recovery with line numbers and context */
errors: {
lineNo: number;
line: string;
error: Error;
}[];
/** Last incomplete line if file was truncated (null if clean) */
partialTail: string | null;
};
/**
* Statistics about the WAL file state and last recovery operation.
*/
export type WalStats<T> = {
/** File path for this WAL */
filePath: string;
/** Whether the WAL file is currently closed */
isClosed: boolean;
/** Whether the WAL file exists on disk */
fileExists: boolean;
/** File size in bytes (0 if file doesn't exist) */
fileSize: number;
/** Last recovery state from the most recent {@link recover} or {@link repack} operation */
lastRecovery: RecoverResult<T | InvalidEntry<string>> | null;
};
export declare const createTolerantCodec: <I, O = string>(codec: {
encode: (v: I) => O;
decode: (d: O) => I;
}) => Codec<I | InvalidEntry<O>, O>;
export declare function filterValidRecords<T>(records: (T | InvalidEntry<unknown>)[]): T[];
/**
* Pure helper function to recover records from WAL file content.
* @param content - Raw file content as string
* @param decode - function for decoding records
* @returns Recovery result with records, errors, and partial tail
*/
export declare function recoverFromContent<T>(content: string, decode: Codec<T>['decode']): RecoverResult<T>;
/**
* Write-Ahead Log implementation for crash-safe append-only logging.
* Provides atomic operations for writing, recovering, and repacking log entries.
*/
export declare class WriteAheadLogFile<T> implements AppendableSink<T> {
#private;
/**
* Create a new WAL file instance.
* @param options - Configuration options
*/
constructor(options: {
file: string;
codec: Codec<T>;
});
/** Get the file path for this WAL */
getPath: () => string;
/** Open the WAL file for writing (creates directories if needed) */
open: () => void;
/**
* Append a record to the WAL.
* @param v - Record to append
* @throws Error if WAL cannot be opened
*/
append: (v: T) => void;
/** Close the WAL file */
close: () => void;
isClosed: () => boolean;
/**
* Recover all records from the WAL file.
* Handles partial writes and decode errors gracefully.
* Updates the recovery state (accessible via {@link getStats}).
* @returns Recovery result with records, errors, and partial tail
*/
recover(): RecoverResult<T | InvalidEntry<string>>;
/**
* Repack the WAL by recovering all valid records and rewriting cleanly.
* Removes corrupted entries and ensures clean formatting.
* Updates the recovery state (accessible via {@link getStats}).
* @param out - Output path (defaults to current file)
*/
repack(out?: string): void;
/**
* Get comprehensive statistics about the WAL file state.
* Includes file information, open/close status, and last recovery state.
* @returns Statistics object with file info and last recovery state
*/
getStats(): WalStats<T>;
}
/**
* Format descriptor that binds codec and file extension together.
* Prevents misconfiguration by keeping related concerns in one object.
*/
export type WalFormat<T extends object | string> = {
/** Base name for the WAL (e.g., "trace") */
baseName: string;
/** Shard file extension (e.g., ".jsonl") */
walExtension: string;
/** Final file extension (e.g., ".json", ".trace.json") falls back to walExtension if not provided */
finalExtension: string;
/** Codec for encoding/decoding records */
codec: Codec<T, string>;
/** Finalizer for converting records to a string */
finalizer: (records: (T | InvalidEntry<string>)[], opt?: Record<string, unknown>) => string;
};
export declare const stringCodec: <T extends string | object = string>() => Codec<T>;
/**
* Parses a partial WalFormat configuration and returns a complete WalFormat object.
* All fallback values are targeting string types.
* - baseName defaults to 'wal'
* - walExtension defaults to '.log'
* - finalExtension defaults to '.log'
* - codec defaults to stringCodec<T>()
* - finalizer defaults to encoding each record using codec.encode() and joining with newlines.
* For object types, this properly JSON-stringifies them (not [object Object]).
* InvalidEntry records use their raw string value directly.
* @param format - Partial WalFormat configuration
* @returns Parsed WalFormat with defaults filled in
*/
export declare function parseWalFormat<T extends object | string = object>(format: Partial<WalFormat<T>>): WalFormat<T>;
/**
* Determines if this process is the leader WAL process using the origin PID heuristic.
*
* The leader is the process that first enabled profiling (the one that set CP_PROFILER_ORIGIN_PID).
* All descendant processes inherit the environment but have different PIDs.
*
* @returns true if this is the leader WAL process, false otherwise
*/
export declare function isLeaderWal(envVarName: string, profilerID: string): boolean;
/**
* Initialize the origin PID environment variable if not already set.
* This must be done as early as possible before any user code runs.
* Sets envVarName to the current process ID if not already defined.
*/
export declare function setLeaderWal(envVarName: string, profilerID: string): void;
/**
* Generates a human-readable shard ID.
* This ID is unique per process/thread/shard combination and used in the file name.
* Format: readable-timestamp.pid.threadId.shardCount
* Example: "20240101-120000-000.12345.1.1"
* Becomes file: trace.20240101-120000-000.12345.1.1.log
*/
export declare function getShardId(): string;
/**
* Generates a human-readable sharded group ID.
* This ID is a globally unique, sortable, human-readable date string per run.
* Used directly as the folder name to group shards.
* Format: yyyymmdd-hhmmss-ms
* Example: "20240101-120000-000"
*/
export declare function getShardedGroupId(): string;
/**
* Regex patterns for validating WAL ID formats
*/
export declare const WAL_ID_PATTERNS: {
/** Readable date format: yyyymmdd-hhmmss-ms */
readonly READABLE_DATE: RegExp;
/** Group ID format: yyyymmdd-hhmmss-ms */
readonly GROUP_ID: RegExp;
/** Shard ID format: readable-date.pid.threadId.count */
readonly SHARD_ID: RegExp;
};
export declare function sortableReadableDateString(timestampMs: string): string;
/**
* Generates a path to a shard file using human-readable IDs.
* Both groupId and shardId are already in readable date format.
*
* Example with groupId "20240101-120000-000" and shardId "20240101-120000-000.12345.1.1":
* Full path: /base/20240101-120000-000/trace.20240101-120000-000.12345.1.1.log
*
* @param opt.dir - The directory to store the shard file
* @param opt.format - The WalFormat to use for the shard file
* @param opt.groupId - The human-readable group ID (yyyymmdd-hhmmss-ms format)
* @param opt.shardId - The human-readable shard ID (readable-timestamp.pid.threadId.count format)
* @returns The path to the shard file
*/
export declare function getShardedPath<T extends object | string = object>(opt: {
dir?: string;
format: WalFormat<T>;
groupId: string;
shardId: string;
}): string;
export declare function getShardedFinalPath<T extends object | string = object>(opt: {
dir?: string;
format: WalFormat<T>;
groupId: string;
}): string;
/**
* Sharded Write-Ahead Log manager for coordinating multiple WAL shards.
* Handles distributed logging across multiple processes/files with atomic finalization.
*/
export declare class ShardedWal<T extends object | string = object> {
#private;
readonly groupId: string;
/**
* Create a sharded WAL manager.
*/
constructor(opt: {
dir?: string;
format: Partial<WalFormat<T>>;
groupId?: string;
});
shard(shardId?: string): WriteAheadLogFile<T>;
/** Get all shard file paths matching this WAL's base name */
private shardFiles;
/**
* Finalize all shards by merging them into a single output file.
* Recovers all records from all shards, validates no errors, and writes merged result.
* @throws Error if any shard contains decode errors
*/
finalize(opt?: Record<string, unknown>): void;
cleanup(): void;
}
/* eslint-disable max-lines */
import * as fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { threadId } from 'node:worker_threads';
export const createTolerantCodec = (codec) => {
const { encode, decode } = codec;
return {
encode: v => v && typeof v === 'object' && '__invalid' in v
? v.raw
: encode(v),
decode: d => {
try {
return decode(d);
}
catch {
return { __invalid: true, raw: d };
}
},
};
};
export function filterValidRecords(records) {
return records
.filter((r) => !(typeof r === 'object' && r != null && '__invalid' in r))
.map(r => r);
}
/**
* Pure helper function to recover records from WAL file content.
* @param content - Raw file content as string
* @param decode - function for decoding records
* @returns Recovery result with records, errors, and partial tail
*/
export function recoverFromContent(content, decode) {
const lines = content.split('\n');
const clean = content.endsWith('\n');
const out = lines.slice(0, -1).reduce((a, l, i) => {
if (!l) {
return a;
}
try {
return {
...a,
records: [...a.records, decode(l)],
};
}
catch (error) {
return {
...a,
errors: [
...a.errors,
{ lineNo: i + 1, line: l, error: error },
],
};
}
}, { records: [], errors: [] });
const tail = lines.at(-1);
return {
...out,
partialTail: clean || !tail ? null : tail,
};
}
/**
* Write-Ahead Log implementation for crash-safe append-only logging.
* Provides atomic operations for writing, recovering, and repacking log entries.
*/
export class WriteAheadLogFile {
#fd = null;
#file;
#decode;
#encode;
#lastRecoveryState = null;
/**
* Create a new WAL file instance.
* @param options - Configuration options
*/
constructor(options) {
this.#file = options.file;
const c = createTolerantCodec(options.codec);
this.#decode = c.decode;
this.#encode = c.encode;
}
/** Get the file path for this WAL */
getPath = () => this.#file;
/** Open the WAL file for writing (creates directories if needed) */
open = () => {
if (this.#fd) {
return;
}
ensureDirectoryExistsSync(path.dirname(this.#file));
this.#fd = fs.openSync(this.#file, 'a');
};
/**
* Append a record to the WAL.
* @param v - Record to append
* @throws Error if WAL cannot be opened
*/
append = (v) => {
if (!this.#fd) {
throw new Error('WAL not opened');
}
fs.writeSync(this.#fd, `${this.#encode(v)}\n`);
};
/** Close the WAL file */
close = () => {
if (this.#fd) {
fs.closeSync(this.#fd);
}
this.#fd = null;
};
isClosed = () => this.#fd == null;
/**
* Recover all records from the WAL file.
* Handles partial writes and decode errors gracefully.
* Updates the recovery state (accessible via {@link getStats}).
* @returns Recovery result with records, errors, and partial tail
*/
recover() {
if (!fs.existsSync(this.#file)) {
this.#lastRecoveryState = { records: [], errors: [], partialTail: null };
return this.#lastRecoveryState;
}
const txt = fs.readFileSync(this.#file, 'utf8');
this.#lastRecoveryState = recoverFromContent(txt, this.#decode);
return this.#lastRecoveryState;
}
/**
* Repack the WAL by recovering all valid records and rewriting cleanly.
* Removes corrupted entries and ensures clean formatting.
* Updates the recovery state (accessible via {@link getStats}).
* @param out - Output path (defaults to current file)
*/
repack(out = this.#file) {
this.close();
const r = this.recover();
if (r.errors.length > 0) {
// eslint-disable-next-line no-console
console.log('WAL repack encountered decode errors');
}
// Check if any records are invalid entries (from tolerant codec)
const hasInvalidEntries = r.records.some(rec => typeof rec === 'object' && rec != null && '__invalid' in rec);
if (hasInvalidEntries) {
// eslint-disable-next-line no-console
console.log('Found invalid entries during WAL repack');
}
const recordsToWrite = hasInvalidEntries
? r.records
: filterValidRecords(r.records);
ensureDirectoryExistsSync(path.dirname(out));
fs.writeFileSync(out, `${recordsToWrite.map(this.#encode).join('\n')}\n`);
}
/**
* Get comprehensive statistics about the WAL file state.
* Includes file information, open/close status, and last recovery state.
* @returns Statistics object with file info and last recovery state
*/
getStats() {
const fileExists = fs.existsSync(this.#file);
return {
filePath: this.#file,
isClosed: this.#fd == null,
fileExists,
fileSize: fileExists ? fs.statSync(this.#file).size : 0,
lastRecovery: this.#lastRecoveryState,
};
}
}
export const stringCodec = () => ({
encode: v => (typeof v === 'string' ? v : JSON.stringify(v)),
decode: v => {
try {
return JSON.parse(v);
}
catch {
return v;
}
},
});
/**
* Parses a partial WalFormat configuration and returns a complete WalFormat object.
* All fallback values are targeting string types.
* - baseName defaults to 'wal'
* - walExtension defaults to '.log'
* - finalExtension defaults to '.log'
* - codec defaults to stringCodec<T>()
* - finalizer defaults to encoding each record using codec.encode() and joining with newlines.
* For object types, this properly JSON-stringifies them (not [object Object]).
* InvalidEntry records use their raw string value directly.
* @param format - Partial WalFormat configuration
* @returns Parsed WalFormat with defaults filled in
*/
export function parseWalFormat(format) {
const { baseName = 'wal', walExtension = '.log', finalExtension = walExtension, codec = stringCodec(), } = format;
const finalizer = format.finalizer ??
((records) => {
// Encode each record using the codec before joining.
// For object types, codec.encode() will JSON-stringify them properly.
// InvalidEntry records use their raw string value directly.
const encoded = records.map(record => typeof record === 'object' && record != null && '__invalid' in record
? record.raw
: codec.encode(record));
return `${encoded.join('\n')}\n`;
});
return {
baseName,
walExtension,
finalExtension,
codec,
finalizer,
};
}
/**
* Determines if this process is the leader WAL process using the origin PID heuristic.
*
* The leader is the process that first enabled profiling (the one that set CP_PROFILER_ORIGIN_PID).
* All descendant processes inherit the environment but have different PIDs.
*
* @returns true if this is the leader WAL process, false otherwise
*/
export function isLeaderWal(envVarName, profilerID) {
return process.env[envVarName] === profilerID;
}
/**
* Initialize the origin PID environment variable if not already set.
* This must be done as early as possible before any user code runs.
* Sets envVarName to the current process ID if not already defined.
*/
export function setLeaderWal(envVarName, profilerID) {
if (!process.env[envVarName]) {
// eslint-disable-next-line functional/immutable-data
process.env[envVarName] = profilerID;
}
}
// eslint-disable-next-line functional/no-let
let shardCount = 0;
/**
* Generates a human-readable shard ID.
* This ID is unique per process/thread/shard combination and used in the file name.
* Format: readable-timestamp.pid.threadId.shardCount
* Example: "20240101-120000-000.12345.1.1"
* Becomes file: trace.20240101-120000-000.12345.1.1.log
*/
export function getShardId() {
const timestamp = Math.round(performance.timeOrigin + performance.now());
const readableTimestamp = sortableReadableDateString(`${timestamp}`);
return `${readableTimestamp}.${process.pid}.${threadId}.${++shardCount}`;
}
/**
* Generates a human-readable sharded group ID.
* This ID is a globally unique, sortable, human-readable date string per run.
* Used directly as the folder name to group shards.
* Format: yyyymmdd-hhmmss-ms
* Example: "20240101-120000-000"
*/
export function getShardedGroupId() {
return sortableReadableDateString(`${Math.round(performance.timeOrigin + performance.now())}`);
}
/**
* Regex patterns for validating WAL ID formats
*/
export const WAL_ID_PATTERNS = {
/** Readable date format: yyyymmdd-hhmmss-ms */
READABLE_DATE: /^\d{8}-\d{6}-\d{3}$/,
/** Group ID format: yyyymmdd-hhmmss-ms */
GROUP_ID: /^\d{8}-\d{6}-\d{3}$/,
/** Shard ID format: readable-date.pid.threadId.count */
SHARD_ID: /^\d{8}-\d{6}-\d{3}(?:\.\d+){3}$/,
};
export function sortableReadableDateString(timestampMs) {
const timestamp = Number.parseInt(timestampMs, 10);
const date = new Date(timestamp);
const MILLISECONDS_PER_SECOND = 1000;
const yyyy = date.getFullYear();
const mm = String(date.getMonth() + 1).padStart(2, '0');
const dd = String(date.getDate()).padStart(2, '0');
const hh = String(date.getHours()).padStart(2, '0');
const min = String(date.getMinutes()).padStart(2, '0');
const ss = String(date.getSeconds()).padStart(2, '0');
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const ms = String(timestamp % MILLISECONDS_PER_SECOND).padStart(3, '0');
return `${yyyy}${mm}${dd}-${hh}${min}${ss}-${ms}`;
}
/**
* Ensures a directory exists, creating it recursively if necessary using sync methods.
* @param dirPath - The directory path to ensure exists
*/
function ensureDirectoryExistsSync(dirPath) {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
}
/**
* Generates a path to a shard file using human-readable IDs.
* Both groupId and shardId are already in readable date format.
*
* Example with groupId "20240101-120000-000" and shardId "20240101-120000-000.12345.1.1":
* Full path: /base/20240101-120000-000/trace.20240101-120000-000.12345.1.1.log
*
* @param opt.dir - The directory to store the shard file
* @param opt.format - The WalFormat to use for the shard file
* @param opt.groupId - The human-readable group ID (yyyymmdd-hhmmss-ms format)
* @param opt.shardId - The human-readable shard ID (readable-timestamp.pid.threadId.count format)
* @returns The path to the shard file
*/
export function getShardedPath(opt) {
const { dir = '', format, groupId, shardId } = opt;
const { baseName, walExtension } = format;
return path.join(dir, groupId, `${baseName}.${shardId}${walExtension}`);
}
export function getShardedFinalPath(opt) {
const { dir = '', format, groupId } = opt;
const { baseName, finalExtension } = format;
return path.join(dir, groupId, `${baseName}.${groupId}${finalExtension}`);
}
/**
* Sharded Write-Ahead Log manager for coordinating multiple WAL shards.
* Handles distributed logging across multiple processes/files with atomic finalization.
*/
export class ShardedWal {
groupId = getShardedGroupId();
#format;
#dir = process.cwd();
/**
* Create a sharded WAL manager.
*/
constructor(opt) {
const { dir, format, groupId } = opt;
this.groupId = groupId ?? getShardedGroupId();
if (dir) {
this.#dir = dir;
}
this.#format = parseWalFormat(format);
}
shard(shardId = getShardId()) {
return new WriteAheadLogFile({
file: getShardedPath({
dir: this.#dir,
format: this.#format,
groupId: this.groupId,
shardId,
}),
codec: this.#format.codec,
});
}
/** Get all shard file paths matching this WAL's base name */
shardFiles() {
if (!fs.existsSync(this.#dir)) {
return [];
}
const groupIdDir = path.dirname(getShardedFinalPath({
dir: this.#dir,
format: this.#format,
groupId: this.groupId,
}));
// create dir if not existing
ensureDirectoryExistsSync(groupIdDir);
return fs
.readdirSync(groupIdDir)
.filter(entry => entry.endsWith(this.#format.walExtension))
.filter(entry => entry.startsWith(`${this.#format.baseName}`))
.map(entry => path.join(groupIdDir, entry));
}
/**
* Finalize all shards by merging them into a single output file.
* Recovers all records from all shards, validates no errors, and writes merged result.
* @throws Error if any shard contains decode errors
*/
finalize(opt) {
const fileRecoveries = this.shardFiles().map(f => ({
file: f,
recovery: new WriteAheadLogFile({
file: f,
codec: this.#format.codec,
}).recover(),
}));
const records = fileRecoveries.flatMap(({ recovery }) => recovery.records);
// Check if any records are invalid entries (from tolerant codec)
const hasInvalidEntries = records.some(r => typeof r === 'object' && r != null && '__invalid' in r);
const recordsToFinalize = hasInvalidEntries
? records
: filterValidRecords(records);
const out = getShardedFinalPath({
dir: this.#dir,
format: this.#format,
groupId: this.groupId,
});
ensureDirectoryExistsSync(path.dirname(out));
fs.writeFileSync(out, this.#format.finalizer(recordsToFinalize, opt));
}
cleanup() {
this.shardFiles().forEach(f => {
// Remove the shard file
fs.unlinkSync(f);
// Remove the parent directory (shard group directory)
const shardDir = path.dirname(f);
try {
fs.rmdirSync(shardDir);
}
catch {
// Directory might not be empty or already removed, ignore
}
});
// Also try to remove the root directory if it becomes empty
try {
fs.rmdirSync(this.#dir);
}
catch {
// Directory might not be empty or already removed, ignore
}
}
}
//# sourceMappingURL=wal.js.map
{"version":3,"file":"wal.js","sourceRoot":"","sources":["../../../src/lib/wal.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAoD/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAgB,KAGlD,EAAiC,EAAE;IAClC,MAAM,EA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I,CAAC;gBACH,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACP,0DAA0D;YAC5D,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,4DAA4D;QAC5D,IAAI,CAAC;YACH,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,0DAA0D;QAC5D,CAAC;IACH,CAAC;CACF"}
+2
-2
{
"name": "@code-pushup/utils",
"version": "0.109.0",
"version": "0.110.0",
"description": "Low-level utilities (helper functions, etc.) used by Code PushUp CLI",

@@ -30,3 +30,3 @@ "license": "MIT",

"dependencies": {
"@code-pushup/models": "0.109.0",
"@code-pushup/models": "0.110.0",
"ansis": "^3.3.0",

@@ -33,0 +33,0 @@ "build-md": "^0.4.2",

import { type PerformanceEntry } from 'node:perf_hooks';
import type { Buffered, Encoder, Observer, Sink } from './sink-source.type';
import type { AppendableSink } from './wal.js';
export declare const DEFAULT_FLUSH_THRESHOLD = 20;
export type PerformanceObserverOptions<T> = {
sink: Sink<T, unknown>;
sink: AppendableSink<T>;
encode: (entry: PerformanceEntry) => T[];

@@ -10,3 +10,3 @@ buffered?: boolean;

};
export declare class PerformanceObserverSink<T> implements Observer, Buffered, Encoder<PerformanceEntry, T[]> {
export declare class PerformanceObserverSink<T> {
#private;

@@ -13,0 +13,0 @@ constructor(options: PerformanceObserverOptions<T>);

@@ -51,3 +51,3 @@ import { PerformanceObserver, performance, } from 'node:perf_hooks';

.flatMap(entry => this.encode(entry))
.forEach(item => this.#sink.write(item));
.forEach(item => this.#sink.append(item));
this.#written.set(t, written + fresh.length);

@@ -54,0 +54,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"file":"performance-observer.js","sourceRoot":"","sources":["../../../src/lib/performance-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEnB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAG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O,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CACb,wDAAwD,EACxD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,WAAW;QACT,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC;IACtC,CAAC;CACF"}
export declare const PROFILER_ENABLED_ENV_VAR = "CP_PROFILING";
export declare const PROFILER_COORDINATOR_FLAG_ENV_VAR = "CP_PROFILER_COORDINATOR";
export declare const PROFILER_ORIGIN_PID_ENV_VAR = "CP_PROFILER_ORIGIN_PID";
export declare const PROFILER_DIRECTORY_ENV_VAR = "CP_PROFILER_DIR";
export declare const PROFILER_BASE_NAME = "trace";
export declare const PROFILER_DIRECTORY = "./tmp/profiles";
export const PROFILER_ENABLED_ENV_VAR = 'CP_PROFILING';
export const PROFILER_COORDINATOR_FLAG_ENV_VAR = 'CP_PROFILER_COORDINATOR';
export const PROFILER_ORIGIN_PID_ENV_VAR = 'CP_PROFILER_ORIGIN_PID';
export const PROFILER_DIRECTORY_ENV_VAR = 'CP_PROFILER_DIR';
export const PROFILER_BASE_NAME = 'trace';
export const PROFILER_DIRECTORY = './tmp/profiles';
//# sourceMappingURL=constants.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/lib/profiler/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC"}
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/lib/profiler/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC;AACvD,MAAM,CAAC,MAAM,iCAAiC,GAAG,yBAAyB,CAAC;AAC3E,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAwB,CAAC;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,iBAAiB,CAAC;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC"}
import { type ActionTrackConfigs, type MeasureCtxOptions, type MeasureOptions } from '../user-timing-extensibility-api-utils.js';
import type { ActionTrackEntryPayload, DevToolsColor, EntryMeta } from '../user-timing-extensibility-api.type.js';
/**
* Generates a unique profiler ID based on performance time origin, process ID, thread ID, and instance count.
*/
export declare function getProfilerId(): string;
/**
* Configuration options for creating a Profiler instance.

@@ -44,2 +48,4 @@ *

#private;
static instanceCount: number;
readonly id: string;
readonly tracks: Record<keyof T, ActionTrackEntryPayload> | undefined;

@@ -46,0 +52,0 @@ /**

import process from 'node:process';
import { threadId } from 'node:worker_threads';
import { isEnvVarEnabled } from '../env.js';

@@ -6,2 +7,9 @@ import { asOptions, markerPayload, measureCtx, setupTracks, } from '../user-timing-extensibility-api-utils.js';

/**
* Generates a unique profiler ID based on performance time origin, process ID, thread ID, and instance count.
*/
export function getProfilerId() {
// eslint-disable-next-line functional/immutable-data
return `${Math.round(performance.timeOrigin)}.${process.pid}.${threadId}.${++Profiler.instanceCount}`;
}
/**
* Performance profiler that creates structured timing measurements with Chrome DevTools Extensibility API payloads.

@@ -14,2 +22,4 @@ *

export class Profiler {
static instanceCount = 0;
id = getProfilerId();
#enabled;

@@ -16,0 +26,0 @@ #defaults;

@@ -1,1 +0,1 @@

{"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../../../src/lib/profiler/profiler.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAA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AAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC9D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,CAAC,CAAC,CAAC;YACX,OAAO,CAAC,CAAC;QACX,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,KAAK,CAAC,MAAM,CAAC,CAAC;YACd,MAAM,MAAM,CAAC;QACf,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,YAAY,CAChB,KAAa,EACb,IAAsB,EACtB,OAA2B;QAE3B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,MAAM,IAAI,EAAE,CAAC;QACtB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC9D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,MAAM,IAAI,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC,CAAC,CAAC;YACX,OAAO,CAAC,CAAC;QACX,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,KAAK,CAAC,MAAM,CAAC,CAAC;YACd,MAAM,MAAM,CAAC;QACf,CAAC;IACH,CAAC"}
export type Encoder<I, O> = {
encode: (input: I) => O;
};
export type Decoder<O, I> = {
decode: (output: O) => I;
};
export type Sink<I, O> = {
open: () => void;
write: (input: I) => void;
close: () => void;
isClosed: () => boolean;
} & Encoder<I, O>;
export type Buffered = {
flush: () => void;
};
export type BufferedSink<I, O> = Sink<I, O> & Buffered;
export type Source<I, O = unknown> = {
read?: () => O;
decode?: (input: I) => O;
};
export type Observer = {
subscribe: () => void;
unsubscribe: () => void;
isSubscribed: () => boolean;
};
export type Recoverable = {
recover: () => RecoverResult;
repack: () => void;
finalize: () => void;
};
export type RecoverResult<T = unknown> = {
records: T[];
errors: {
lineNo: number;
line: string;
error: Error;
}[];
partialTail: string | null;
};
export type RecoverOptions = {
keepInvalid?: boolean;
};
export type Output<I, O> = {} & BufferedSink<I, O>;
export {};
//# sourceMappingURL=sink-source.type.js.map
{"version":3,"file":"sink-source.type.js","sourceRoot":"","sources":["../../../src/lib/sink-source.type.ts"],"names":[],"mappings":""}
import type { PerformanceMark, PerformanceMeasure } from 'node:perf_hooks';
import type { BeginEvent, CompleteEvent, EndEvent, InstantEvent, InstantEventArgs, InstantEventTracingStartedInBrowser, SpanEventArgs, TraceEvent, TraceEventContainer } from './trace-file.type.js';
/**
* Generates a unique ID for linking begin and end span events in Chrome traces.
* @returns Object with local ID string for the id2 field
*/
export declare const nextId2: () => {
local: string;
};
/**
* Generates a unique frame tree node ID from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Combined numeric ID
*/
export declare const frameTreeNodeId: (pid: number, tid: number) => number;
/**
* Generates a frame name string from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Formatted frame name
*/
export declare const frameName: (pid: number, tid: number) => string;
/**
* Creates an instant trace event for marking a point in time.
* @param opt - Event configuration options
* @returns InstantEvent object
*/
export declare const getInstantEvent: (opt: {
name: string;
ts?: number;
pid?: number;
tid?: number;
args?: InstantEventArgs;
}) => InstantEvent;
/**
* Creates a start tracing event with frame information.
* This event is needed at the beginning of the traceEvents array to make tell the UI profiling has started, and it should visualize the data.
* @param opt - Tracing configuration options
* @returns StartTracingEvent object
*/
export declare const getInstantEventTracingStartedInBrowser: (opt: {
url: string;
ts?: number;
pid?: number;
tid?: number;
}) => InstantEventTracingStartedInBrowser;
/**
* Creates a complete trace event with duration.
* @param opt - Event configuration with name and duration
* @returns CompleteEvent object
*/
export declare const getCompleteEvent: (opt: {
name: string;
dur: number;
ts?: number;
pid?: number;
tid?: number;
}) => CompleteEvent;
/** Options for creating span events */
type SpanOpt = {
name: string;
id2: {
local: string;
};
ts?: number;
pid?: number;
tid?: number;
args?: SpanEventArgs;
};
/**
* Creates a begin span event.
* @param ph - Phase ('b' for begin)
* @param opt - Span event options
* @returns BeginEvent object
*/
export declare function getSpanEvent(ph: 'b', opt: SpanOpt): BeginEvent;
/**
* Creates an end span event.
* @param ph - Phase ('e' for end)
* @param opt - Span event options
* @returns EndEvent object
*/
export declare function getSpanEvent(ph: 'e', opt: SpanOpt): EndEvent;
/**
* Creates a pair of begin and end span events.
* @param opt - Span configuration with start/end timestamps
* @returns Tuple of BeginEvent and EndEvent
*/
export declare const getSpan: (opt: {
name: string;
tsB: number;
tsE: number;
id2?: {
local: string;
};
pid?: number;
tid?: number;
args?: SpanEventArgs;
tsMarkerPadding?: number;
}) => [BeginEvent, EndEvent];
/**
* Converts a PerformanceMark to an instant trace event.
* @param entry - Performance mark entry
* @param opt - Optional overrides for name, pid, and tid
* @returns InstantEvent object
*/
export declare const markToInstantEvent: (entry: PerformanceMark, opt?: {
name?: string;
pid?: number;
tid?: number;
}) => InstantEvent;
/**
* Converts a PerformanceMeasure to a pair of span events.
* @param entry - Performance measure entry
* @param opt - Optional overrides for name, pid, and tid
* @returns Tuple of BeginEvent and EndEvent
*/
export declare const measureToSpanEvents: (entry: PerformanceMeasure, opt?: {
name?: string;
pid?: number;
tid?: number;
}) => [BeginEvent, EndEvent];
/**
* Creates a complete trace file container with metadata.
* @param opt - Trace file configuration
* @returns TraceEventContainer with events and metadata
*/
export declare const getTraceFile: (opt: {
traceEvents: TraceEvent[];
startTime?: string;
}) => TraceEventContainer;
export {};
import os from 'node:os';
import { threadId } from 'node:worker_threads';
import { defaultClock } from './clock-epoch.js';
/** Global counter for generating unique span IDs within a trace */
// eslint-disable-next-line functional/no-let
let id2Count = 0;
/**
* Generates a unique ID for linking begin and end span events in Chrome traces.
* @returns Object with local ID string for the id2 field
*/
export const nextId2 = () => ({ local: `0x${++id2Count}` });
/**
* Provides default values for trace event properties.
* @param opt - Optional overrides for pid, tid, and timestamp
* @returns Object with pid, tid, and timestamp
*/
const defaults = (opt) => ({
pid: opt?.pid ?? process.pid,
tid: opt?.tid ?? threadId,
ts: opt?.ts ?? defaultClock.epochNowUs(),
});
/**
* Generates a unique frame tree node ID from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Combined numeric ID
*/
export const frameTreeNodeId = (pid, tid) => Number.parseInt(`${pid}0${tid}`, 10);
/**
* Generates a frame name string from process and thread IDs.
* @param pid - Process ID
* @param tid - Thread ID
* @returns Formatted frame name
*/
export const frameName = (pid, tid) => `FRAME0P${pid}T${tid}`;
/**
* Creates an instant trace event for marking a point in time.
* @param opt - Event configuration options
* @returns InstantEvent object
*/
export const getInstantEvent = (opt) => ({
cat: 'blink.user_timing',
ph: 'i',
name: opt.name,
...defaults(opt),
args: opt.args ?? {},
});
/**
* Creates a start tracing event with frame information.
* This event is needed at the beginning of the traceEvents array to make tell the UI profiling has started, and it should visualize the data.
* @param opt - Tracing configuration options
* @returns StartTracingEvent object
*/
export const getInstantEventTracingStartedInBrowser = (opt) => {
const { pid, tid, ts } = defaults(opt);
const id = frameTreeNodeId(pid, tid);
return {
cat: 'devtools.timeline',
ph: 'i',
name: 'TracingStartedInBrowser',
pid,
tid,
ts,
args: {
data: {
frameTreeNodeId: id,
frames: [
{
frame: frameName(pid, tid),
isInPrimaryMainFrame: true,
isOutermostMainFrame: true,
name: '',
processId: pid,
url: opt.url,
},
],
persistentIds: true,
},
},
};
};
/**
* Creates a complete trace event with duration.
* @param opt - Event configuration with name and duration
* @returns CompleteEvent object
*/
export const getCompleteEvent = (opt) => ({
cat: 'devtools.timeline',
ph: 'X',
name: opt.name,
dur: opt.dur,
...defaults(opt),
args: {},
});
/**
* Creates a span event (begin or end).
* @param ph - Phase ('b' or 'e')
* @param opt - Span event options
* @returns SpanEvent object
*/
export function getSpanEvent(ph, opt) {
return {
cat: 'blink.user_timing',
ph,
name: opt.name,
id2: opt.id2,
...defaults(opt),
args: opt.args?.data?.detail
? { data: { detail: opt.args.data.detail } }
: {},
};
}
/**
* Creates a pair of begin and end span events.
* @param opt - Span configuration with start/end timestamps
* @returns Tuple of BeginEvent and EndEvent
*/
export const getSpan = (opt) => {
// tsMarkerPadding is here to make the measure slightly smaller so the markers align perfectly.
// Otherwise, the marker is visible at the start of the measure below the frame
// No padding Padding
// spans: ======== |======|
// marks: | |
const pad = opt.tsMarkerPadding ?? 1;
// b|e need to share the same id2
const id2 = opt.id2 ?? nextId2();
return [
getSpanEvent('b', {
...opt,
id2,
ts: opt.tsB + pad,
}),
getSpanEvent('e', {
...opt,
id2,
ts: opt.tsE - pad,
}),
];
};
/**
* Converts a PerformanceMark to an instant trace event.
* @param entry - Performance mark entry
* @param opt - Optional overrides for name, pid, and tid
* @returns InstantEvent object
*/
export const markToInstantEvent = (entry, opt) => getInstantEvent({
...opt,
name: opt?.name ?? entry.name,
ts: defaultClock.fromEntry(entry),
args: entry.detail ? { detail: entry.detail } : undefined,
});
/**
* Converts a PerformanceMeasure to a pair of span events.
* @param entry - Performance measure entry
* @param opt - Optional overrides for name, pid, and tid
* @returns Tuple of BeginEvent and EndEvent
*/
export const measureToSpanEvents = (entry, opt) => getSpan({
...opt,
name: opt?.name ?? entry.name,
tsB: defaultClock.fromEntry(entry),
tsE: defaultClock.fromEntry(entry, true),
args: entry.detail ? { data: { detail: entry.detail } } : undefined,
});
/**
* Creates a complete trace file container with metadata.
* @param opt - Trace file configuration
* @returns TraceEventContainer with events and metadata
*/
export const getTraceFile = (opt) => ({
traceEvents: opt.traceEvents,
displayTimeUnit: 'ms',
metadata: {
source: 'Node.js UserTiming',
startTime: opt.startTime ?? new Date().toISOString(),
hardwareConcurrency: os.cpus().length,
},
});
//# sourceMappingURL=trace-file-utils.js.map
{"version":3,"file":"trace-file-utils.js","sourceRoot":"","sources":["../../../src/lib/trace-file-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;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AI;IAC7B,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC;IAClC,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC;IACxC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;CACpE,CAAC,CAAC;AAEL;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAG5B,EAAuB,EAAE,CAAC,CAAC;IAC1B,WAAW,EAAE,GAAG,CAAC,WAAW;IAC5B,eAAe,EAAE,IAAI;IACrB,QAAQ,EAAE;QACR,MAAM,EAAE,oBAAoB;QAC5B,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpD,mBAAmB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM;KACtC;CACF,CAAC,CAAC"}
import type { UserTimingDetail } from './user-timing-extensibility-api.type.js';
/**
* Arguments for instant trace events.
* @property {UserTimingDetail} [detail] - Optional user timing detail with DevTools payload
*/
export type InstantEventArgs = {
detail?: UserTimingDetail;
} & {
[key: string]: unknown;
};
/**
* Arguments for span trace events (begin/end events).
* @property {object} [data] - Optional data object
* @property {UserTimingDetail} [data.detail] - Optional user timing detail with DevTools payload
*/
export type SpanEventArgs = {
data?: {
detail?: UserTimingDetail;
};
} & {
[key: string]: unknown;
};
/**
* Arguments for complete trace events.
* @property {Record<string, unknown>} [detail] - Optional detail object with arbitrary properties
*/
export type CompleteEventArgs = {
detail?: Record<string, unknown>;
};
/**
* Arguments for start tracing events.
* @property {object} data - Tracing initialization data
* @property {number} data.frameTreeNodeId - Frame tree node identifier
* @property {Array} data.frames - Array of frame information
* @property {boolean} data.persistentIds - Whether IDs are persistent
*/
export type InstantEventTracingStartedInBrowserArgs = {
data: {
frameTreeNodeId: number;
frames: {
frame: string;
isInPrimaryMainFrame: boolean;
isOutermostMainFrame: boolean;
name: string;
processId: number;
url: string;
}[];
persistentIds: boolean;
};
};
/**
* Union type of all possible trace event arguments.
*/
export type TraceArgs = InstantEventArgs | SpanEventArgs | CompleteEventArgs | InstantEventTracingStartedInBrowserArgs;
/**
* Base properties shared by all trace events.
* @property {string} cat - Event category
* @property {string} name - Event name
* @property {number} pid - Process ID
* @property {number} tid - Thread ID
* @property {number} ts - Timestamp in epoch microseconds
* @property {TraceArgs} [args] - Optional event arguments
*/
export type BaseTraceEvent = {
cat: string;
name: string;
pid: number;
tid: number;
ts: number;
args: TraceArgs;
};
/**
* Start tracing event for Chrome DevTools tracing.
*/
export type InstantEventTracingStartedInBrowser = BaseTraceEvent & {
cat: 'devtools.timeline';
ph: 'i';
name: 'TracingStartedInBrowser';
args: InstantEventTracingStartedInBrowserArgs;
};
/**
* Complete trace event with duration.
* Represents a complete operation with start time and duration.
* @property {'X'} ph - Phase indicator for complete events
* @property {number} dur - Duration in microseconds
*/
export type CompleteEvent = BaseTraceEvent & {
ph: 'X';
dur: number;
};
/**
* Instant trace event representing a single point in time.
* Used for user timing marks and other instantaneous events.
* @property {'blink.user_timing'} cat - Fixed category for user timing events
* @property {'i'} ph - Phase indicator for instant events
* @property {never} [dur] - Duration is not applicable for instant events
* @property {InstantEventArgs} [args] - Optional event arguments
*/
export type InstantEvent = Omit<BaseTraceEvent, 'cat' | 'args'> & {
cat: 'blink.user_timing';
ph: 'i';
dur?: never;
args: InstantEventArgs;
};
/**
* Core properties for span trace events (begin/end pairs).
* @property {object} id2 - Span identifier
* @property {string} id2.local - Local span ID (unique to the process, same for b and e events)
* @property {SpanEventArgs} [args] - Optional event arguments
*/
type SpanCore = Omit<BaseTraceEvent, 'args'> & {
id2: {
local: string;
};
args: SpanEventArgs;
};
/**
* Begin event for a span (paired with an end event).
* @property {'b'} ph - Phase indicator for begin events
* @property {never} [dur] - Duration is not applicable for begin events
*/
export type BeginEvent = SpanCore & {
ph: 'b';
dur?: never;
};
/**
* End event for a span (paired with a begin event).
* @property {'e'} ph - Phase indicator for end events
* @property {never} [dur] - Duration is not applicable for end events
*/
export type EndEvent = SpanCore & {
ph: 'e';
dur?: never;
};
/**
* Union type for span events (begin or end).
*/
export type SpanEvent = BeginEvent | EndEvent;
/**
* Union type of all trace event types.
*/
export type TraceEvent = InstantEvent | CompleteEvent | SpanEvent | InstantEventTracingStartedInBrowser;
/**
* Raw arguments format for trace events before processing.
* Either contains a detail string directly or nested in a data object.
*/
type RawArgs = {
detail?: string;
[key: string]: unknown;
} | {
data?: {
detail?: string;
};
[key: string]: unknown;
};
/**
* Raw trace event format before type conversion.
* Similar to TraceEvent but with unprocessed arguments.
*/
export type TraceEventRaw = Omit<TraceEvent, 'args'> & {
args: RawArgs;
};
/**
* Time window bounds (min, max) in trace time units (e.g. microseconds).
* @property {number} min - Minimum timestamp in the window
* @property {number} max - Maximum timestamp in the window
* @property {number} range - Calculated range (max - min)
*/
export type BreadcrumbWindow = {
min: number;
max: number;
range: number;
};
/**
* Custom label for a specific trace entry.
* @property {number | string} entryId - ID or index of the trace entry
* @property {string} label - Label text for the entry
* @property {string} [color] - Optional display color for the label
*/
export type EntryLabel = {
entryId: number | string;
label: string;
color?: string;
};
/**
* Link or relation between two trace entries.
* @property {number | string} fromEntryId - Source entry ID for the link
* @property {number | string} toEntryId - Target entry ID for the link
* @property {string} [linkType] - Optional type or description of the link
*/
export type EntryLink = {
fromEntryId: number | string;
toEntryId: number | string;
linkType?: string;
};
/**
* A time range annotated with a label.
* @property {number} startTime - Start timestamp of the range (microseconds)
* @property {number} endTime - End timestamp of the range (microseconds)
* @property {string} label - Annotation label for the time range
* @property {string} [color] - Optional display color for the range
*/
export type LabelledTimeRange = {
startTime: number;
endTime: number;
label: string;
color?: string;
};
/**
* Hidden or expandable entries information.
* @property {unknown[]} hiddenEntries - IDs or indexes of hidden entries
* @property {unknown[]} expandableEntries - IDs or indexes of expandable entries
*/
export type EntriesModifications = {
hiddenEntries: unknown[];
expandableEntries: unknown[];
};
/**
* Initial breadcrumb information for time ranges and window.
* @property {BreadcrumbWindow} window - Time window bounds
* @property {unknown | null} child - Child breadcrumb or null
*/
export type InitialBreadcrumb = {
window: BreadcrumbWindow;
child: unknown | null;
};
/**
* Annotations such as labels and links between entries.
* @property {EntryLabel[]} entryLabels - Custom labels for entries
* @property {LabelledTimeRange[]} labelledTimeRanges - Time ranges annotated with labels
* @property {EntryLink[]} linksBetweenEntries - Links or relations between entries
*/
export type Annotations = {
entryLabels: EntryLabel[];
labelledTimeRanges: LabelledTimeRange[];
linksBetweenEntries: EntryLink[];
};
/**
* Modifications made to trace data or UI in DevTools export
*/
export type Modifications = {
entriesModifications: EntriesModifications;
initialBreadcrumb: InitialBreadcrumb;
annotations: Annotations;
};
/**
* Top-level metadata for a trace file exported by Chrome DevTools.
* DevTools may add new fields over time.
*/
export type TraceMetadata = {
/** Usually "DevTools" for exports from the Performance panel */
source: string;
/** ISO timestamp when trace was recorded */
startTime: string;
/** May be present when recorded with throttling settings */
hardwareConcurrency?: number;
/** Common fields found in DevTools traces */
cpuThrottling?: number;
networkThrottling?: string;
enhancedTraceVersion?: number;
/** Allow additional custom metadata properties */
[key: string]: unknown;
};
/**
* Structured container for trace events with metadata.
* @property {TraceEvent[]} traceEvents - Array of trace events
* @property {'ms' | 'ns'} [displayTimeUnit] - Time unit for display (milliseconds or nanoseconds)
* @property {TraceMetadata} [metadata] - Optional metadata about the trace
*/
export type TraceEventContainer = {
traceEvents: TraceEvent[];
displayTimeUnit?: 'ms' | 'ns';
metadata?: TraceMetadata;
};
/**
* Trace file format - either an array of events or a structured container.
*/
export type TraceFile = TraceEvent[] | TraceEventContainer;
export {};
export {};
//# sourceMappingURL=trace-file.type.js.map
{"version":3,"file":"trace-file.type.js","sourceRoot":"","sources":["../../../src/lib/trace-file.type.ts"],"names":[],"mappings":""}