github
DocsBlog
fontcolor_theme
package

API @deepkit/stopwatch

npm install @deepkit/stopwatch

Classes

StopwatchStore [source]
export abstract class StopwatchStore {
    frameQueue: (FrameStart | FrameEnd)[];
    dataQueue: FrameData[];
    analytics: AnalyticData[];
    async close();
    abstract run<T>(data: {
        [name: string]: any;
    }, cb: () => Promise<T>): Promise<T>;
    abstract getZone(): {
        [name: string]: any;
    } | undefined;
    data(data: FrameData);
    collectAnalytics();
    add(frame: FrameStart | FrameEnd): void;
}
StopwatchFrame [source]
export class StopwatchFrame<C extends FrameCategory> implements StopwatchFrameInterface<C> {
    constructor(protected store: StopwatchStore, public context: number, public category: number, public cid: number);
    data(data: Partial<TypeOfCategory<C>>);
    end();
    run<T>(cb: () => Promise<T>, data: {
        [name: string]: any;
    } = {}): Promise<T>;
}
NoopStopwatchFrame [source]
export class NoopStopwatchFrame<C extends FrameCategory> implements StopwatchFrameInterface<C> {
    data(data: any);
    end();
    run<T>(cb: () => Promise<T>, data: {
        [p: string]: any;
    } = {}): Promise<T>;
}
Stopwatch [source]
export class Stopwatch {
    /**
     * It's active when there is a StopwatchStore attached.
     * Per default its inactive.
     */
    active: boolean;
    constructor(protected store?: StopwatchStore);
    enable();
    disable();
    /**
     * Please check Stopwatch.active before using this method.
     *
     * When a new context is created, it's important to use StopwatchFrame.run() so that all
     * sub frames are correctly assigned to the new context.
     */
    start<C extends FrameCategory>(label: string, category: C = FrameCategory.none as C, newContext: boolean = false): StopwatchFrameInterface<C>;
}
Frame [source]
export class Frame {
    end?: number;
    data?: any;
    constructor(public cid: number, public start: number, public context: number, public label: string, public category: FrameCategory);
}

Functions

getTypeOfCategory [source]
(category: FrameCategory): Type | undefined
encodeCompoundKey [source]
(id: number, worker: number): number
incrementCompoundKey [source]
(cid: number, id: number): number
decodeCompoundKey [source]
(cid: number): [id: number, worker: number]

Types

StopwatchFrameInterface [source]
interface StopwatchFrameInterface<C extends FrameCategory> {
    data(data: TypeOfCategory<C>): void;

    end(): void;

    run<T>(cb: () => Promise<T> | T, data?: { [name: string]: any }): Promise<T>;
}
AnalyticData [source]
type AnalyticData = {
    timestamp: number;
    cpu: number;
    memory: number;
    loopBlocked: number;
}
FrameCategoryData [source]
interface FrameCategoryData {
    [FrameCategory.http]: {
        url?: string;
        method?: string;
        clientIp?: string;
        responseStatus?: number;
    };
    [FrameCategory.rpc]: {
        method: string;
        controller: string;
        arguments: any[];
    };
    [FrameCategory.database]: {
        collection?: string;
        className?: string;
    };
    [FrameCategory.databaseQuery]: {
        sql: string;
        sqlParams?: any[];
    };
}
TypeOfCategory [source]
type TypeOfCategory<C extends FrameCategory> = C extends keyof FrameCategoryData ? Partial<FrameCategoryData[C]> : undefined;
FrameStart [source]
interface FrameStart {
    cid: number;
    type: FrameType.start;
    timestamp: number;
    context: number;
    label: string;
    category: FrameCategory;
}
FrameEnd [source]
interface FrameEnd {
    cid: number;
    type: FrameType.end;
    timestamp: number;
}
FrameData [source]
interface FrameData {
    cid: number;
    category: FrameCategory;
    data: any;
}