From f61fab3201017231ae99482a475cb844b034819a Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 28 May 2024 08:23:34 +0200 Subject: [PATCH] use monotonic clock for update checks (#81) --- metrics.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/metrics.nim b/metrics.nim index 86f60d7..a7ff985 100644 --- a/metrics.nim +++ b/metrics.nim @@ -17,7 +17,7 @@ when defined(metricsTest): else: {.pragma: testOnly, deprecated: "slow helpers used for tests only".} -import std/[locks, os, sets, tables, times] +import std/[locks, monotimes, os, sets, tables, times] when defined(metrics): import std/[algorithm, hashes, strutils, sequtils], stew/ptrops, metrics/common @@ -1116,7 +1116,7 @@ when defined(metrics): threadMetricsUpdateProcs: array[metrics_max_hooks, ThreadMetricsUpdateProc] threadMetricsUpdateProcsIndex = 0 systemMetricsUpdateInterval = initDuration(seconds = 10) - systemMetricsLastUpdated = now() + systemMetricsLastUpdated = getMonoTime() proc getSystemMetricsUpdateInterval*(): Duration = return systemMetricsUpdateInterval @@ -1135,7 +1135,7 @@ when defined(metrics): # Update system metrics if at least systemMetricsUpdateInterval seconds # have passed and if we are being called from the main thread. if getThreadId() == mainThreadID: - let currTime = now() + let currTime = getMonoTime() if currTime >= (systemMetricsLastUpdated + systemMetricsUpdateInterval): systemMetricsLastUpdated = currTime # Update thread metrics, only when automation is on and we're in the