This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+109
View File
@@ -0,0 +1,109 @@
declare module '@ioc:Adonis/Core/Profiler' {
/**
* Shape of data packet for a single action
*/
export type ProfilerAction = {
type: 'action';
label: string;
timestamp: number;
duration: [number, number];
data: any;
parent_id?: string;
};
/**
* Shape of data packet for a single row
*/
export type ProfilerRow = {
id: string;
type: 'row';
label: string;
timestamp: number;
duration: [number, number];
data: any;
parent_id?: string;
};
/**
* The processor action or worker node that listens for the logs
*/
export type ProfilerProcessor = string | ((log: ProfilerAction | ProfilerRow) => void | Promise<void>);
/**
* Profiler action just has one method to mark
* the action as `done`.
*/
export interface ProfilerActionContract {
/**
* End profiling an action
*/
end(data?: any): void;
}
/**
* Exposes the API to time functions
*/
export interface AbstractProfilerContract {
/**
* Time a function by wrapping it inside the callback
*/
profile<T extends any>(action: string, data: any, cb: () => T): T;
/**
* Create a profiler action to time a block of code. Make sure to
* call `end` on the output of this function
*/
profile(action: string, data?: any): ProfilerActionContract;
profile<T extends any>(action: string, data?: any, cb?: () => T): ProfilerActionContract | T;
/**
* Time an async function by wrapping it inside the callback
*/
profileAsync<T extends any>(action: string, data: any, cb: () => Promise<T>): Promise<T>;
/**
* Create a profiler action to time a block of code. Make sure to
* call `end` on the output of this function
*/
profileAsync(action: string, data?: any): Promise<ProfilerActionContract>;
profileAsync<T extends any>(action: string, data?: any, cb?: () => Promise<T>): Promise<ProfilerActionContract | T>;
}
/**
* Profiler row can spawn new actions or new rows
*/
export interface ProfilerRowContract extends AbstractProfilerContract {
hasParent: boolean;
/**
* Create a children row
*/
create(label: string, data?: any): ProfilerRowContract;
/**
* End profiling a row
*/
end(data?: any): void;
}
/**
* Main profiler
*/
export interface ProfilerContract extends AbstractProfilerContract {
processor?: Exclude<ProfilerProcessor, string>;
isEnabled(labelOrAction: string): boolean;
/**
* Create a new profiler row
*/
create(label: string, data?: any): ProfilerRowContract;
/**
* Define a custom processor function or path to
* the processor function module.
*/
process(fn: ProfilerProcessor): void;
/**
* Flush final bits (if any) and close the worker
* process
*/
cleanup(): void;
}
/**
* Profiler config
*/
export type ProfilerConfig = {
enabled: boolean;
whitelist: string[];
blacklist: string[];
};
const Profiler: ProfilerContract;
export default Profiler;
}
+8
View File
@@ -0,0 +1,8 @@
/*
* @adonisjs/profiler
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/