From 008512c74c553d4400f3fabb46053e5e8a4a0cd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 19 Jul 2023 12:05:41 +0200 Subject: [PATCH] refactor: cleanup measurement statistics computation code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 12 ++++++------ src/utils.ts | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 6467f4eb..5481099f 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -36,6 +36,7 @@ import type { WorkerUsage } from './worker' import { + type MeasurementStatisticsRequirements, Measurements, WorkerChoiceStrategies, type WorkerChoiceStrategy, @@ -774,22 +775,21 @@ export abstract class AbstractPool< workerUsage: WorkerUsage, message: MessageValue ): void { + const eluTaskStatisticsRequirements: MeasurementStatisticsRequirements = + this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu updateMeasurementStatistics( workerUsage.elu.active, - this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu, + eluTaskStatisticsRequirements, message.taskPerformance?.elu?.active ?? 0, workerUsage.tasks.executed ) updateMeasurementStatistics( workerUsage.elu.idle, - this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu, + eluTaskStatisticsRequirements, message.taskPerformance?.elu?.idle ?? 0, workerUsage.tasks.executed ) - if ( - this.workerChoiceStrategyContext.getTaskStatisticsRequirements().elu - .aggregate - ) { + if (eluTaskStatisticsRequirements.aggregate) { if (message.taskPerformance?.elu != null) { if (workerUsage.elu.utilization != null) { workerUsage.elu.utilization = diff --git a/src/utils.ts b/src/utils.ts index cc71491a..45e4fd23 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -136,13 +136,13 @@ export const isAsyncFunction = ( * @param measurementStatistics - The measurement statistics to update. * @param measurementRequirements - The measurement statistics requirements. * @param measurementValue - The measurement value. - * @param tasksExecuted - The number of tasks executed. + * @param numberOfMeasurements - The number of measurements. */ export const updateMeasurementStatistics = ( measurementStatistics: MeasurementStatistics, measurementRequirements: MeasurementStatisticsRequirements, measurementValue: number, - tasksExecuted: number + numberOfMeasurements: number ): void => { if (measurementRequirements.aggregate) { measurementStatistics.aggregate = @@ -155,9 +155,9 @@ export const updateMeasurementStatistics = ( measurementValue, measurementStatistics.maximum ?? -Infinity ) - if (measurementRequirements.average && tasksExecuted !== 0) { + if (measurementRequirements.average && numberOfMeasurements !== 0) { measurementStatistics.average = - measurementStatistics.aggregate / tasksExecuted + measurementStatistics.aggregate / numberOfMeasurements } if (measurementRequirements.median && measurementValue != null) { measurementStatistics.history.push(measurementValue) -- 2.34.1