From 1b5757b7d1c6be6459523db0f63344f4c9690b6b Mon Sep 17 00:00:00 2001 From: YangKeao Date: Tue, 21 Dec 2021 16:14:07 +0800 Subject: [PATCH] fix unstable boot time because of float conversion Signed-off-by: YangKeao --- internal/common/common_linux.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 7349989..d2d3d64 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package common @@ -100,8 +101,9 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { if err != nil { return 0, err } - t := uint64(time.Now().Unix()) - uint64(b) - return t, nil + currentTime := float64(time.Now().UnixNano()) / float64(time.Second) + t := currentTime - b + return uint64(t), nil } return 0, fmt.Errorf("could not find btime")