mirror of
https://github.com/hengyoush/kyanos.git
synced 2025-12-20 01:03:46 +08:00
24 lines
724 B
Go
24 lines
724 B
Go
package agent
|
|
|
|
/*
|
|
#cgo LDFLAGS: -lrt
|
|
#include <time.h>
|
|
*/
|
|
import "C"
|
|
|
|
func GetMachineStartTimeNano() uint64 {
|
|
var timestamp C.struct_timespec
|
|
|
|
C.clock_gettime(C.CLOCK_REALTIME, ×tamp)
|
|
nowEpochTime := uint64(timestamp.tv_sec)*1000000000 + uint64(timestamp.tv_nsec)
|
|
// fmt.Printf("real time: %d, seconds: %d, nano: %d\n", nowEpochTime, timestamp.tv_sec, timestamp.tv_nsec)
|
|
|
|
C.clock_gettime(C.CLOCK_MONOTONIC, ×tamp)
|
|
machineRunningDuration := uint64(timestamp.tv_sec)*1000000000 + uint64(timestamp.tv_nsec)
|
|
// fmt.Printf("mono time: %d\n", machineRunningDuration)
|
|
|
|
launchEpochTime := nowEpochTime - machineRunningDuration
|
|
// fmt.Printf("machine start time: %d\n", launchEpochTime)
|
|
return launchEpochTime
|
|
}
|