Skip to content

Commit

Permalink
Do not cache boot time for linux. Fix #837
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Bienkowski committed Apr 15, 2020
1 parent 53cec6b commit aeb3b6b
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions internal/common/common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path/filepath"
"strconv"
"strings"
"sync/atomic"
"time"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}

Expand Down

0 comments on commit aeb3b6b

Please sign in to comment.