MCPcopy Create free account
hub / github.com/subquery/subql / profiler

Function profiler

packages/node-core/src/profiler.ts:25–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25export function profiler(): MethodDecorator {
26 return (target, name: string | symbol, descriptor: PropertyDescriptor): void => {
27 if (enableProfiler && !!descriptor && typeof descriptor.value === 'function') {
28 const orig = descriptor.value;
29 // tslint:disable no-function-expression no-invalid-this
30 descriptor.value = function (...args: any[]): any {
31 const start = performance.now();
32 const res = orig.bind(this)(...args);
33 if (isPromise(res)) {
34 res.then(
35 (_: any) => {
36 printCost(start, performance.now(), target.constructor.name, name);
37 return _;
38 },
39 (err: any) => {
40 printCost(start, performance.now(), target.constructor.name, name);
41 throw err;
42 }
43 );
44 } else {
45 printCost(start, performance.now(), target.constructor.name, name);
46 }
47 return res;
48 };
49 }
50 };
51}
52
53type AnyFn = (...args: any[]) => any;
54

Callers 6

StoreCacheServiceClass · 0.90
dictionaryV1.tsFile · 0.90
IndexerManagerClass · 0.90
RuntimeServiceClass · 0.90

Calls 2

isPromiseFunction · 0.85
printCostFunction · 0.85

Tested by

no test coverage detected