From 197b4aa5aa76186bbe6f9274d455f4bdb8baa637 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 9 Jul 2023 14:33:24 +0200 Subject: [PATCH] refactor: add task function name to task performance MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utility-types.ts | 4 ++++ src/worker/abstract-worker.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utility-types.ts b/src/utility-types.ts index a8da491e..d7477319 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -24,6 +24,10 @@ export interface TaskError { * @internal */ export interface TaskPerformance { + /** + * Task name. + */ + readonly name: string /** * Task performance timestamp. */ diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 138719a1..a0154115 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -251,7 +251,7 @@ export abstract class AbstractWorker< message: MessageValue ): void { try { - let taskPerformance = this.beginTaskPerformance() + let taskPerformance = this.beginTaskPerformance(message.name) const res = fn(message.data) taskPerformance = this.endTaskPerformance(taskPerformance) this.sendToMainWorker({ @@ -332,9 +332,10 @@ export abstract class AbstractWorker< return fn } - private beginTaskPerformance (): TaskPerformance { + private beginTaskPerformance (name?: string): TaskPerformance { this.checkStatistics() return { + name: name ?? DEFAULT_FUNCTION_NAME, timestamp: performance.now(), ...(this.statistics.elu && { elu: performance.eventLoopUtilization() }) } -- 2.34.1