|
|
|
@ -14,6 +14,7 @@ import (
|
|
|
|
|
"runtime"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync/atomic"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/shirou/gopsutil/internal/common"
|
|
|
|
@ -85,10 +86,14 @@ func Info() (*InfoStat, error) {
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cachedBootTime must be accessed via atomic.Load/StoreUint64
|
|
|
|
|
var cachedBootTime uint64
|
|
|
|
|
|
|
|
|
|
// BootTime returns the system boot time expressed in seconds since the epoch.
|
|
|
|
|
func BootTime() (uint64, error) {
|
|
|
|
|
if cachedBootTime != 0 {
|
|
|
|
|
return cachedBootTime, nil
|
|
|
|
|
t := atomic.LoadUint64(&cachedBootTime)
|
|
|
|
|
if t != 0 {
|
|
|
|
|
return t, nil
|
|
|
|
|
}
|
|
|
|
|
filename := common.HostProc("stat")
|
|
|
|
|
lines, err := common.ReadLines(filename)
|
|
|
|
@ -105,8 +110,9 @@ func BootTime() (uint64, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
cachedBootTime = uint64(b)
|
|
|
|
|
return cachedBootTime, nil
|
|
|
|
|
t = uint64(b)
|
|
|
|
|
atomic.StoreUint64(&cachedBootTime, t)
|
|
|
|
|
return t, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|