Skip to content

Commit

Permalink
fix: out of bounds histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Jan 28, 2024
1 parent cc1d31b commit 9688c3d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ function createHistogramSummary (histogram: Histogram): HistogramSummary {
};
}

function toIntegerNano (milliseconds: number): number {
return Math.trunc(milliseconds * 1000);
function toHistogramIntegerNano (milliseconds: number): number {
return Math.max(1, Math.trunc(milliseconds * 1000));
}

interface AbortSignalEventTargetAddOptions {
Expand Down Expand Up @@ -805,7 +805,7 @@ class ThreadPool {
break;
}
const now = performance.now();
this.waitTime.record(toIntegerNano(now - taskInfo.created));
this.waitTime.record(toHistogramIntegerNano(now - taskInfo.created));
taskInfo.started = now;
workerInfo.postTask(taskInfo);
this._maybeDrain();
Expand Down Expand Up @@ -866,7 +866,7 @@ class ThreadPool {
(err : Error | null, result : any) => {
this.completed++;
if (taskInfo.started) {
this.runTime.record(toIntegerNano(performance.now() - taskInfo.started));
this.runTime.record(toHistogramIntegerNano(performance.now() - taskInfo.started));
}
if (err !== null) {
reject(err);
Expand Down Expand Up @@ -956,7 +956,7 @@ class ThreadPool {

// TODO(addaleax): Clean up the waitTime/runTime recording.
const now = performance.now();
this.waitTime.record(toIntegerNano(now - taskInfo.created));
this.waitTime.record(toHistogramIntegerNano(now - taskInfo.created));
taskInfo.started = now;
workerInfo.postTask(taskInfo);
this._maybeDrain();
Expand Down

0 comments on commit 9688c3d

Please sign in to comment.