You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by wu...@apache.org on 2022/12/02 06:11:35 UTC

[skywalking-rover] branch main updated: Enhance the boottime for getting the nanosecond (#63)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git


The following commit(s) were added to refs/heads/main by this push:
     new b083cf6  Enhance the boottime for getting the nanosecond (#63)
b083cf6 is described below

commit b083cf6cf5810ee1a6cd0bd7169abbb03ec0769f
Author: mrproliu <74...@qq.com>
AuthorDate: Fri Dec 2 14:11:30 2022 +0800

    Enhance the boottime for getting the nanosecond (#63)
---
 pkg/tools/host/time.go | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/pkg/tools/host/time.go b/pkg/tools/host/time.go
index b1ef253..7cc8a78 100644
--- a/pkg/tools/host/time.go
+++ b/pkg/tools/host/time.go
@@ -21,20 +21,23 @@ import (
 	"fmt"
 	"time"
 
-	v3 "skywalking.apache.org/repo/goapi/collect/common/v3"
+	"golang.org/x/sys/unix"
 
-	"github.com/shirou/gopsutil/host"
+	v3 "skywalking.apache.org/repo/goapi/collect/common/v3"
 )
 
 // BootTime the System boot time
 var BootTime time.Time
 
 func init() {
-	boot, err := host.BootTime()
+	var ts unix.Timespec
+	err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts)
+	now := time.Now()
 	if err != nil {
 		panic(fmt.Errorf("init boot time error: %v", err))
 	}
-	BootTime = time.Unix(int64(boot), 0)
+	bootTimeNano := now.UnixNano() - ts.Nano()
+	BootTime = time.Unix(bootTimeNano/1e9, bootTimeNano%1e9)
 }
 
 func TimeToInstant(bpfTime uint64) *v3.Instant {