mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-10 14:56:31 +00:00
16c85db43c
* chore: update submodules * fix: libp2p now provides callback to update peer addrs * fix: breaking change in EthereumNode constructor * fix: contentType type has changed (again) * fix: explicit future type * fix: nim 1.6.6 error handling requirements * fix: missed a spot - peer info addrs in sim2 * fix: help compiler a bit here
39 lines
996 B
Nim
39 lines
996 B
Nim
## Contains types and utilities for timestamps.
|
|
{.push raises: [Defect].}
|
|
|
|
import
|
|
std/times,
|
|
metrics
|
|
|
|
type Timestamp* = int64
|
|
|
|
proc getNanosecondTime*[T](timeInSeconds: T): Timestamp =
|
|
var ns = Timestamp(timeInSeconds.int64 * 1000_000_000.int64)
|
|
return ns
|
|
|
|
proc getMicrosecondTime*[T](timeInSeconds: T): Timestamp =
|
|
var us = Timestamp(timeInSeconds.int64 * 1000_000.int64)
|
|
return us
|
|
|
|
proc getMillisecondTime*[T](timeInSeconds: T): Timestamp =
|
|
var ms = Timestamp(timeInSeconds.int64 * 1000.int64)
|
|
return ms
|
|
|
|
proc nowInUnixFloat(): float =
|
|
return getTime().toUnixFloat()
|
|
|
|
template nanosecondTime*(collector: Summary | Histogram, body: untyped) =
|
|
when defined(metrics):
|
|
let start = nowInUnixFloat()
|
|
body
|
|
collector.observe(nowInUnixFloat() - start)
|
|
else:
|
|
body
|
|
|
|
template nanosecondTime*(collector: Gauge, body: untyped) =
|
|
when defined(metrics):
|
|
let start = nowInUnixFloat()
|
|
body
|
|
metrics.set(collector, nowInUnixFloat() - start)
|
|
else:
|
|
body |