Merge pull request #857 from Gui13/fix_837

Do not cache boot time for linux. Fix #837
pull/878/head
Lomanic 5 years ago committed by GitHub
commit c89193f22d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,6 @@ import (
"path/filepath"
"strconv"
"strings"
"sync/atomic"
"time"
)
@ -54,14 +53,7 @@ func NumProcs() (uint64, error) {
return cnt, nil
}
// cachedBootTime must be accessed via atomic.Load/StoreUint64
var cachedBootTime uint64
func BootTimeWithContext(ctx context.Context) (uint64, error) {
t := atomic.LoadUint64(&cachedBootTime)
if t != 0 {
return t, nil
}
system, role, err := Virtualization()
if err != nil {
@ -94,8 +86,7 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
if err != nil {
return 0, err
}
t = uint64(b)
atomic.StoreUint64(&cachedBootTime, t)
t := uint64(b)
return t, nil
}
}
@ -108,8 +99,7 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
if err != nil {
return 0, err
}
t = uint64(time.Now().Unix()) - uint64(b)
atomic.StoreUint64(&cachedBootTime, t)
t := uint64(time.Now().Unix()) - uint64(b)
return t, nil
}

Loading…
Cancel
Save