refactor: add task function name to task performance
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 9 Jul 2023 12:33:24 +0000 (14:33 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 9 Jul 2023 12:33:24 +0000 (14:33 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utility-types.ts
src/worker/abstract-worker.ts

index a8da491e16fe62143d1d716672c4b4db44aa8e9f..d74773190f4c1e477e86d4a4f4c984d7d61d9f40 100644 (file)
@@ -24,6 +24,10 @@ export interface TaskError<Data = unknown> {
  * @internal
  */
 export interface TaskPerformance {
+  /**
+   * Task name.
+   */
+  readonly name: string
   /**
    * Task performance timestamp.
    */
index 138719a14f024657558ad81fafb6c4e2bc438ed4..a01541156b2041d28faa135dcef7694b496962c0 100644 (file)
@@ -251,7 +251,7 @@ export abstract class AbstractWorker<
     message: MessageValue<Data>
   ): 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() })
     }