Skip to content

Commit

Permalink
use monotonic clock for update checks (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck authored May 28, 2024
1 parent 0e768ca commit f61fab3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions metrics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f61fab3

Please sign in to comment.