@webda/profiler
Version:
Webda Basic Profiler
82 lines (81 loc) • 2.14 kB
TypeScript
import { Service, ServiceParameters, WebContext } from "@webda/core";
/**
* Profiler Parameters
*/
export declare class ProfilerParameters extends ServiceParameters {
/**
* Disable the service
*/
disabled?: boolean;
/**
* @inheritdoc
*/
constructor(params: any);
}
/**
* Profiling service
*
* Mesure timing of each method and display them in TRACE
*
* @WebdaModda
*/
export default class Profiler<T extends ProfilerParameters = ProfilerParameters> extends Service<T> {
/**
* @inheritdoc
*/
loadParameters(params: any): ProfilerParameters;
/**
* Return all methods from an object
*
* @param obj to return methods from
*/
getMethods(obj: any): unknown[];
/**
* Method to call before original function
* @param {Service} service being patched
* @param method method being patch
*/
preprocessor(_service: Service, _method: string): {
start: number;
};
/**
* Method to call after original function
* @param service being patched
* @param method method being patch
* @param data return by the preprocessor
* @param err error thrown by the method if any
*/
postprocessor(service: Service, method: string, data?: any, err?: any): void;
/**
* Log the performance
* @param args
*/
logMetrics(...args: any[]): void;
/**
* Return true if the service should not be instrumentalized
* Logger service are excluded
*
* @param service to check
*/
excludeService(service: Service): boolean;
/**
* Patch all services method: interlacing our pre/post processor
*/
patchServices(services: any): void;
/**
* Return if Profiler is enable
*/
isEnabled(): boolean;
/**
* Instrument Request to display request duration in ms
*
* @param {Context} request to instrument
* @param {any[]}
*/
instrumentRequest(ctx: WebContext, ..._args: any[]): void;
/**
* Add listeners on `Webda.Init.Services` and `Webda.Request`
*/
resolve(): this;
}
export { Profiler };