clock_with_raw.go 308 B

12345678910111213141516171819
  1. //go:build linux || darwin
  2. package utils
  3. import (
  4. "time"
  5. "golang.org/x/sys/unix"
  6. )
  7. func MonotonicRaw() (time.Time, error) {
  8. ts := unix.Timespec{}
  9. if err := unix.ClockGettime(unix.CLOCK_MONOTONIC_RAW, &ts); err != nil {
  10. return time.Time{}, err
  11. }
  12. s, ns := ts.Unix()
  13. return time.Unix(s, ns), nil
  14. }