From b448af248ed887511e87645edb114910715b3b4b Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Sat, 18 Dec 2021 17:31:14 +0200 Subject: [PATCH] [common] Add support for determining current nanoseconds runtime. --- sources/lib/common/runtime.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sources/lib/common/runtime.go b/sources/lib/common/runtime.go index 276fe7f..c3564db 100644 --- a/sources/lib/common/runtime.go +++ b/sources/lib/common/runtime.go @@ -1,6 +1,8 @@ + package common + import "reflect" import "unsafe" @@ -61,3 +63,36 @@ func StringToBytes (_input string) ([]byte) { return _output } + + + +// NOTE: https://github.com/aristanetworks/goarista/blob/master/monotime/nanotime.go + +//go:noescape +//go:linkname runtime_nanotime runtime.nanotime +func runtime_nanotime () (int64) + +func RuntimeNanoseconds () (uint64) { + return uint64 (runtime_nanotime ()) +} + +func RuntimeMicroseconds () (uint64) { + return uint64 (runtime_nanotime ()) / 1000 +} + +func RuntimeMilliseconds () (uint64) { + return uint64 (runtime_nanotime ()) / 1000 / 1000 +} + +func RuntimeSeconds () (uint64) { + return uint64 (runtime_nanotime ()) / 1000 / 1000 / 1000 +} + +func RuntimeSecondsFloat () (float64) { + return float64 (runtime_nanotime ()) / 1000 / 1000 / 1000 +} + +func RuntimeHoursFloat () (float64) { + return float64 (RuntimeSeconds ()) / 3600 +} +