[common] Add support for determining current nanoseconds runtime.

This commit is contained in:
Ciprian Dorin Craciun 2021-12-18 17:31:14 +02:00
parent dbaa404abf
commit b448af248e

View file

@ -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
}