github.com/scaleft/monotime@v0.0.0-20180209174256-2da272f3dad0/clock_clock_gettime.go (about)

     1  // +build netbsd freebsd solaris
     2  // +build !go1.9
     3  
     4  package monotime
     5  
     6  import (
     7  	"syscall"
     8  	"time"
     9  	"unsafe"
    10  )
    11  
    12  func monotime() Monotime {
    13  	var ts syscall.Timespec
    14  
    15  	syscall.Syscall(syscall.SYS_CLOCK_GETTIME, clock_monotonic, uintptr(unsafe.Pointer(&ts)), 0)
    16  
    17  	return uint64(ts.Nano())
    18  }
    19  
    20  func duration(start Monotime, end Monotime) time.Duration {
    21  	return time.Duration(end - start)
    22  }