pull/1208/head
mmorel-35 3 years ago
parent 5eac39f418
commit 1e6b445a8a

@ -103,5 +103,4 @@ func main() {
issueRemoveUnusedValue() issueRemoveUnusedValue()
} }
} }
} }

@ -51,8 +51,10 @@ type lastPercent struct {
lastPerCPUTimes []TimesStat lastPerCPUTimes []TimesStat
} }
var lastCPUPercent lastPercent var (
var invoke common.Invoker = common.Invoke{} lastCPUPercent lastPercent
invoke common.Invoker = common.Invoke{}
)
func init() { func init() {
lastCPUPercent.Lock() lastCPUPercent.Lock()

@ -1,3 +1,4 @@
//go:build aix
// +build aix // +build aix
package cpu package cpu

@ -1,3 +1,4 @@
//go:build darwin
// +build darwin // +build darwin
package cpu package cpu

@ -1,5 +1,5 @@
// +build darwin //go:build darwin && cgo
// +build cgo // +build darwin,cgo
package cpu package cpu
@ -108,5 +108,4 @@ func allCPUTimes() ([]TimesStat, error) {
} }
return []TimesStat{c}, nil return []TimesStat{c}, nil
} }

@ -1,5 +1,5 @@
// +build darwin //go:build darwin && !cgo
// +build !cgo // +build darwin,!cgo
package cpu package cpu

@ -15,14 +15,16 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
var ClocksPerSec = float64(128) var (
var cpuMatch = regexp.MustCompile(`^CPU:`) ClocksPerSec = float64(128)
var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`) cpuMatch = regexp.MustCompile(`^CPU:`)
var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`) originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`) featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
var cpuEnd = regexp.MustCompile(`^Trying to mount root`) featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
var cpuTimesSize int cpuEnd = regexp.MustCompile(`^Trying to mount root`)
var emptyTimes cpuTimes cpuTimesSize int
emptyTimes cpuTimes
)
func init() { func init() {
clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK)

@ -1,3 +1,4 @@
//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !dragonfly && !plan9 && !aix
// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly,!plan9,!aix // +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly,!plan9,!aix
package cpu package cpu

@ -15,15 +15,17 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
var ClocksPerSec = float64(128) var (
var cpuMatch = regexp.MustCompile(`^CPU:`) ClocksPerSec = float64(128)
var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`) cpuMatch = regexp.MustCompile(`^CPU:`)
var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`) originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`) featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
var cpuEnd = regexp.MustCompile(`^Trying to mount root`) featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
var cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`) cpuEnd = regexp.MustCompile(`^Trying to mount root`)
var cpuTimesSize int cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`)
var emptyTimes cpuTimes cpuTimesSize int
emptyTimes cpuTimes
)
func init() { func init() {
clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK)

@ -13,7 +13,7 @@ func TestParseDmesgBoot(t *testing.T) {
t.SkipNow() t.SkipNow()
} }
var cpuTests = []struct { cpuTests := []struct {
file string file string
cpuNum int cpuNum int
cores int32 cores int32

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package cpu package cpu
@ -30,7 +31,7 @@ func Times(percpu bool) ([]TimesStat, error) {
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
filename := common.HostProc("stat") filename := common.HostProc("stat")
var lines = []string{} lines := []string{}
if percpu { if percpu {
statlines, err := common.ReadLines(filename) statlines, err := common.ReadLines(filename)
if err != nil || len(statlines) < 2 { if err != nil || len(statlines) < 2 {
@ -338,7 +339,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
} }
// physical cores // physical cores
// https://github.com/giampaolo/psutil/blob/8415355c8badc9c94418b19bdf26e622f06f0cce/psutil/_pslinux.py#L615-L628 // https://github.com/giampaolo/psutil/blob/8415355c8badc9c94418b19bdf26e622f06f0cce/psutil/_pslinux.py#L615-L628
var threadSiblingsLists = make(map[string]bool) threadSiblingsLists := make(map[string]bool)
// These 2 files are the same but */core_cpus_list is newer while */thread_siblings_list is deprecated and may disappear in the future. // These 2 files are the same but */core_cpus_list is newer while */thread_siblings_list is deprecated and may disappear in the future.
// https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst // https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst
// https://github.com/giampaolo/psutil/pull/1727#issuecomment-707624964 // https://github.com/giampaolo/psutil/pull/1727#issuecomment-707624964

@ -1,3 +1,4 @@
//go:build openbsd
// +build openbsd // +build openbsd
package cpu package cpu
@ -108,7 +109,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
j *= 2 j *= 2
} }
var cpuTimes = make([]int32, cpUStates) cpuTimes := make([]int32, cpUStates)
var mib []int32 var mib []int32
if percpu { if percpu {
mib = []int32{ctlKern, kernCptime2, int32(j)} mib = []int32{ctlKern, kernCptime2, int32(j)}

@ -1,3 +1,4 @@
//go:build plan9
// +build plan9 // +build plan9
package cpu package cpu

@ -1,3 +1,4 @@
//go:build plan9
// +build plan9 // +build plan9
package cpu package cpu

@ -24,7 +24,7 @@ func init() {
} }
} }
//sum all values in a float64 map with float64 keys // sum all values in a float64 map with float64 keys
func msum(x map[float64]float64) float64 { func msum(x map[float64]float64) float64 {
total := 0.0 total := 0.0
for _, y := range x { for _, y := range x {
@ -47,7 +47,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
user := make(map[float64]float64) user := make(map[float64]float64)
kern := make(map[float64]float64) kern := make(map[float64]float64)
iowt := make(map[float64]float64) iowt := make(map[float64]float64)
//swap := make(map[float64]float64) // swap := make(map[float64]float64)
kstatSysOut, err := invoke.CommandWithContext(ctx, kstatSys, "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/") kstatSysOut, err := invoke.CommandWithContext(ctx, kstatSys, "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/")
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot execute kstat: %s", err) return nil, fmt.Errorf("cannot execute kstat: %s", err)

@ -15,28 +15,36 @@ func TestParseISAInfo(t *testing.T) {
}{ }{
{ {
"1cpu_1core_isainfo.txt", "1cpu_1core_isainfo.txt",
[]string{"rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx", []string{
"rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx",
"avx", "xsave", "pclmulqdq", "aes", "movbe", "sse4.2", "sse4.1", "ssse3", "popcnt", "avx", "xsave", "pclmulqdq", "aes", "movbe", "sse4.2", "sse4.1", "ssse3", "popcnt",
"tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8", "tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8",
"tsc", "fpu"}, "tsc", "fpu",
},
}, },
{ {
"2cpu_1core_isainfo.txt", "2cpu_1core_isainfo.txt",
[]string{"rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx", []string{
"rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx",
"avx", "xsave", "pclmulqdq", "aes", "movbe", "sse4.2", "sse4.1", "ssse3", "popcnt", "avx", "xsave", "pclmulqdq", "aes", "movbe", "sse4.2", "sse4.1", "ssse3", "popcnt",
"tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8", "tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8",
"tsc", "fpu"}, "tsc", "fpu",
},
}, },
{ {
"2cpu_8core_isainfo.txt", "2cpu_8core_isainfo.txt",
[]string{"vmx", "avx", "xsave", "pclmulqdq", "aes", "sse4.2", "sse4.1", "ssse3", "popcnt", []string{
"vmx", "avx", "xsave", "pclmulqdq", "aes", "sse4.2", "sse4.1", "ssse3", "popcnt",
"tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8", "tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8",
"tsc", "fpu"}, "tsc", "fpu",
},
}, },
{ {
"2cpu_12core_isainfo.txt", "2cpu_12core_isainfo.txt",
[]string{"amd_svm", "amd_lzcnt", "popcnt", "amd_sse4a", "tscp", "ahf", "cx16", "sse3", "sse2", []string{
"sse", "fxsr", "amd_3dnowx", "amd_3dnow", "amd_mmx", "mmx", "cmov", "amd_sysc", "cx8", "tsc", "fpu"}, "amd_svm", "amd_lzcnt", "popcnt", "amd_sse4a", "tscp", "ahf", "cx16", "sse3", "sse2",
"sse", "fxsr", "amd_3dnowx", "amd_3dnow", "amd_mmx", "mmx", "cmov", "amd_sysc", "cx8", "tsc", "fpu",
},
}, },
} }

@ -74,7 +74,6 @@ func TestCpu_times(t *testing.T) {
if cpuTotal[0].Idle != 0 { if cpuTotal[0].Idle != 0 {
assert.InEpsilon(t, cpuTotal[0].Idle, perCPUIdleTimeSum, margin) assert.InEpsilon(t, cpuTotal[0].Idle, perCPUIdleTimeSum, margin)
} }
} }
func TestCpu_counts(t *testing.T) { func TestCpu_counts(t *testing.T) {
@ -162,7 +161,6 @@ func testCPUPercent(t *testing.T, percpu bool) {
} }
func testCPUPercentLastUsed(t *testing.T, percpu bool) { func testCPUPercentLastUsed(t *testing.T, percpu bool) {
numcpu := runtime.NumCPU() numcpu := runtime.NumCPU()
testCount := 10 testCount := 10
@ -194,7 +192,6 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) {
} }
} }
} }
} }
func TestCPUPercent(t *testing.T) { func TestCPUPercent(t *testing.T) {

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package cpu package cpu

@ -1,3 +1,4 @@
//go:build aix
// +build aix // +build aix
package disk package disk
@ -13,10 +14,12 @@ import (
var FSType map[int]string var FSType map[int]string
func init() { func init() {
FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc", FSType = map[int]string{
0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc",
16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs", 16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs",
33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs", 33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
39: "ahafs", 40: "sterm-nfs", 41: "asmfs"} 39: "ahafs", 40: "sterm-nfs", 41: "asmfs",
}
} }
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {

@ -1,3 +1,4 @@
//go:build darwin
// +build darwin // +build darwin
package disk package disk

@ -1,5 +1,5 @@
// +build darwin //go:build darwin && cgo
// +build cgo // +build darwin,cgo
package disk package disk

@ -1,5 +1,5 @@
// +build darwin //go:build darwin && !cgo
// +build !cgo // +build darwin,!cgo
package disk package disk

@ -1,3 +1,4 @@
//go:build !darwin && !linux && !freebsd && !openbsd && !windows && !solaris && !aix
// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix // +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix
package disk package disk

@ -1,3 +1,4 @@
//go:build freebsd
// +build freebsd // +build freebsd
package disk package disk

@ -52,6 +52,7 @@ type devstat struct {
Id *byte Id *byte
Sequence1 uint32 Sequence1 uint32
} }
type bintime struct { type bintime struct {
Sec int32 Sec int32
Frac uint64 Frac uint64

@ -55,6 +55,7 @@ type devstat struct {
Sequence1 uint32 Sequence1 uint32
Pad_cgo_2 [4]byte Pad_cgo_2 [4]byte
} }
type bintime struct { type bintime struct {
Sec int64 Sec int64
Frac uint64 Frac uint64

@ -52,6 +52,7 @@ type devstat struct {
Id *byte Id *byte
Sequence1 uint32 Sequence1 uint32
} }
type bintime struct { type bintime struct {
Sec int32 Sec int32
Frac uint64 Frac uint64

@ -1,5 +1,6 @@
// +build freebsd //go:build freebsd && arm64
// +build arm64 // +build freebsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT. // Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_freebsd.go // cgo -godefs disk/types_freebsd.go

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package disk package disk
@ -21,6 +22,7 @@ import (
const ( const (
sectorSize = 512 sectorSize = 512
) )
const ( const (
// man statfs // man statfs
ADFS_SUPER_MAGIC = 0xadf5 ADFS_SUPER_MAGIC = 0xadf5

@ -1,3 +1,4 @@
//go:build openbsd
// +build openbsd // +build openbsd
package disk package disk

@ -1,5 +1,6 @@
// +build openbsd //go:build openbsd && 386
// +build 386 // +build openbsd,386
// Code generated by cmd/cgo -godefs; DO NOT EDIT. // Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_openbsd.go // cgo -godefs disk/types_openbsd.go

@ -1,5 +1,6 @@
// +build openbsd //go:build openbsd && arm64
// +build arm64 // +build openbsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT. // Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs disk/types_openbsd.go // cgo -godefs disk/types_openbsd.go

@ -1,3 +1,4 @@
//go:build solaris
// +build solaris // +build solaris
package disk package disk
@ -23,20 +24,18 @@ const (
_MNTTAB = "/etc/mnttab" _MNTTAB = "/etc/mnttab"
) )
var ( // A blacklist of read-only virtual filesystems. Writable filesystems are of
// A blacklist of read-only virtual filesystems. Writable filesystems are of // operational concern and must not be included in this list.
// operational concern and must not be included in this list. var fsTypeBlacklist = map[string]struct{}{
fsTypeBlacklist = map[string]struct{}{ "ctfs": {},
"ctfs": {}, "dev": {},
"dev": {}, "fd": {},
"fd": {}, "lofs": {},
"lofs": {}, "lxproc": {},
"lxproc": {}, "mntfs": {},
"mntfs": {}, "objfs": {},
"objfs": {}, "proc": {},
"proc": {}, }
}
)
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
ret := make([]PartitionStat, 0, _DEFAULT_NUM_MOUNTS) ret := make([]PartitionStat, 0, _DEFAULT_NUM_MOUNTS)
@ -113,6 +112,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
return usageStat, nil return usageStat, nil
} }
func SerialNumberWithContext(ctx context.Context, name string) (string, error) { func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
return "", common.ErrNotImplementedError return "", common.ErrNotImplementedError
} }

@ -1,3 +1,4 @@
//go:build freebsd || linux || darwin
// +build freebsd linux darwin // +build freebsd linux darwin
package disk package disk

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package disk package disk
@ -106,7 +107,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
uintptr(len(lpFileSystemNameBuffer))) uintptr(len(lpFileSystemNameBuffer)))
if driveret == 0 { if driveret == 0 {
if typeret == 5 || typeret == 2 { if typeret == 5 || typeret == 2 {
continue //device is not ready will happen if there is no disk in the drive continue // device is not ready will happen if there is no disk in the drive
} }
return ret, err return ret, err
} }

@ -1,4 +1,6 @@
//go:build ignore
// +build ignore // +build ignore
// Hand writing: _Ctype_struct___0 // Hand writing: _Ctype_struct___0
/* /*
@ -58,5 +60,7 @@ type (
_C_long_double C.longlong _C_long_double C.longlong
) )
type devstat C.struct_devstat type (
type bintime C.struct_bintime devstat C.struct_devstat
bintime C.struct_bintime
)

@ -1,4 +1,6 @@
//go:build ignore
// +build ignore // +build ignore
// Hand writing: _Ctype_struct___0 // Hand writing: _Ctype_struct___0
/* /*
@ -25,8 +27,12 @@ const (
sizeOfDiskstats = C.sizeof_struct_diskstats sizeOfDiskstats = C.sizeof_struct_diskstats
) )
type Diskstats C.struct_diskstats type (
type Timeval C.struct_timeval Diskstats C.struct_diskstats
Timeval C.struct_timeval
)
type Diskstat C.struct_diskstat type (
type bintime C.struct_bintime Diskstat C.struct_diskstat
bintime C.struct_bintime
)

@ -8,8 +8,10 @@ import (
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
) )
var ErrDockerNotAvailable = errors.New("docker not available") var (
var ErrCgroupNotAvailable = errors.New("cgroup not available") ErrDockerNotAvailable = errors.New("docker not available")
ErrCgroupNotAvailable = errors.New("cgroup not available")
)
var invoke common.Invoker = common.Invoke{} var invoke common.Invoker = common.Invoke{}

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package docker package docker

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package docker package docker

@ -1,3 +1,4 @@
//go:build !linux
// +build !linux // +build !linux
package docker package docker

@ -1,3 +1,4 @@
//go:build darwin || freebsd || openbsd
// +build darwin freebsd openbsd // +build darwin freebsd openbsd
package host package host

@ -1,3 +1,4 @@
//go:build darwin
// +build darwin // +build darwin
package host package host
@ -94,7 +95,6 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
} }
return ret, nil return ret, nil
} }
func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) {

@ -14,6 +14,7 @@ type Utmpx struct {
Host [256]int8 Host [256]int8
Pad [16]uint32 Pad [16]uint32
} }
type Timeval struct { type Timeval struct {
Sec int32 Sec int32
} }

@ -14,6 +14,7 @@ type Utmpx struct {
Host [256]int8 Host [256]int8
Pad [16]uint32 Pad [16]uint32
} }
type Timeval struct { type Timeval struct {
Sec int32 Sec int32
} }

@ -1,5 +1,6 @@
// +build darwin //go:build darwin && arm64
// +build arm64 // +build darwin,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT. // Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs host/types_darwin.go // cgo -godefs host/types_darwin.go

@ -1,5 +1,5 @@
// +build darwin //go:build darwin && cgo
// +build cgo // +build darwin,cgo
package host package host

@ -1,5 +1,5 @@
// +build darwin //go:build darwin && !cgo
// +build !cgo // +build darwin,!cgo
package host package host

@ -1,3 +1,4 @@
//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows
// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows // +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows
package host package host

@ -1,3 +1,4 @@
//go:build freebsd
// +build freebsd // +build freebsd
package host package host
@ -81,7 +82,6 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
} }
return ret, nil return ret, nil
} }
func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) {

@ -1,5 +1,6 @@
// +build freebsd //go:build freebsd && arm64
// +build arm64 // +build freebsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT. // Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs host/types_freebsd.go // cgo -godefs host/types_freebsd.go

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package host package host
@ -121,7 +122,6 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
} }
return ret, nil return ret, nil
} }
func getlsbStruct() (*lsbStruct, error) { func getlsbStruct() (*lsbStruct, error) {
@ -304,7 +304,6 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil
} }
return platform, family, version, nil return platform, family, version, nil
} }
func KernelVersionWithContext(ctx context.Context) (version string, err error) { func KernelVersionWithContext(ctx context.Context) (version string, err error) {

@ -35,10 +35,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__unused [20]int8 X__unused [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type UtTv struct { type UtTv struct {
Sec int32 Sec int32
Usec int32 Usec int32

@ -33,10 +33,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__glibc_reserved [20]int8 X__glibc_reserved [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64

@ -33,10 +33,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__glibc_reserved [20]int8 X__glibc_reserved [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int32 Sec int32
Usec int32 Usec int32

@ -33,10 +33,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__glibc_reserved [20]int8 X__glibc_reserved [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64

@ -33,10 +33,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__unused [20]int8 X__unused [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int32 Sec int32
Usec int32 Usec int32

@ -33,10 +33,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__unused [20]int8 X__unused [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int32 Sec int32
Usec int32 Usec int32

@ -33,10 +33,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__unused [20]int8 X__unused [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int32 Sec int32
Usec int32 Usec int32

@ -33,10 +33,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__unused [20]int8 X__unused [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int32 Sec int32
Usec int32 Usec int32

@ -1,5 +1,6 @@
// +build linux //go:build linux && ppc64le
// +build ppc64le // +build linux,ppc64le
// Created by cgo -godefs - DO NOT EDIT // Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_linux.go // cgo -godefs types_linux.go
@ -35,10 +36,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__glibc_reserved [20]int8 X__glibc_reserved [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64

@ -32,10 +32,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__glibc_reserved [20]uint8 X__glibc_reserved [20]uint8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64

@ -1,5 +1,6 @@
// +build linux //go:build linux && s390x
// +build s390x // +build linux,s390x
// Created by cgo -godefs - DO NOT EDIT // Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_linux.go // cgo -godefs types_linux.go
@ -35,10 +36,12 @@ type utmp struct {
Addr_v6 [4]int32 Addr_v6 [4]int32
X__glibc_reserved [20]int8 X__glibc_reserved [20]int8
} }
type exit_status struct { type exit_status struct {
Termination int16 Termination int16
Exit int16 Exit int16
} }
type timeval struct { type timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package host package host

@ -1,3 +1,4 @@
//go:build openbsd
// +build openbsd // +build openbsd
package host package host

@ -1,5 +1,6 @@
// +build openbsd //go:build openbsd && 386
// +build 386 // +build openbsd,386
// Code generated by cmd/cgo -godefs; DO NOT EDIT. // Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs host/types_openbsd.go // cgo -godefs host/types_openbsd.go

@ -25,6 +25,7 @@ type Utmp struct {
Host [256]int8 Host [256]int8
Time int64 Time int64
} }
type Timeval struct { type Timeval struct {
Sec int64 Sec int64
Usec int64 Usec int64

@ -1,5 +1,6 @@
// +build openbsd //go:build openbsd && arm64
// +build arm64 // +build openbsd,arm64
// Code generated by cmd/cgo -godefs; DO NOT EDIT. // Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs host/types_openbsd.go // cgo -godefs host/types_openbsd.go

@ -1,3 +1,4 @@
//go:build linux || freebsd || openbsd || darwin || solaris
// +build linux freebsd openbsd darwin solaris // +build linux freebsd openbsd darwin solaris
package host package host

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package host package host

@ -1,4 +1,6 @@
//go:build ignore
// +build ignore // +build ignore
// plus hand editing about timeval // plus hand editing about timeval
/* /*
@ -13,5 +15,7 @@ package host
*/ */
import "C" import "C"
type Utmpx C.struct_utmpx type (
type Timeval C.struct_timeval Utmpx C.struct_utmpx
Timeval C.struct_timeval
)

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore // +build ignore
/* /*
@ -40,5 +41,7 @@ type (
_C_long_long C.longlong _C_long_long C.longlong
) )
type Utmp C.struct_utmp // for FreeBSD 9.0 compatibility type (
type Utmpx C.struct_futx Utmp C.struct_utmp // for FreeBSD 9.0 compatibility
Utmpx C.struct_futx
)

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore // +build ignore
/* /*
@ -37,6 +38,8 @@ type (
_C_long_long C.longlong _C_long_long C.longlong
) )
type utmp C.struct_utmp type (
type exit_status C.struct_exit_status utmp C.struct_utmp
type timeval C.struct_timeval exit_status C.struct_exit_status
timeval C.struct_timeval
)

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore // +build ignore
/* /*
@ -39,5 +40,7 @@ type (
_C_long_long C.longlong _C_long_long C.longlong
) )
type Utmp C.struct_utmp type (
type Timeval C.struct_timeval Utmp C.struct_utmp
Timeval C.struct_timeval
)

@ -388,8 +388,10 @@ type coder struct {
buf []byte buf []byte
} }
type decoder coder type (
type encoder coder decoder coder
encoder coder
)
func (d *decoder) uint8() uint8 { func (d *decoder) uint8() uint8 {
x := d.buf[0] x := d.buf[0]

@ -98,7 +98,6 @@ var ErrNotImplementedError = errors.New("not implemented yet")
// ReadFile reads contents from a file // ReadFile reads contents from a file
func ReadFile(filename string) (string, error) { func ReadFile(filename string) (string, error) {
content, err := ioutil.ReadFile(filename) content, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -312,7 +311,7 @@ func PathExists(filename string) bool {
return false return false
} }
//GetEnv retrieves the environment variable key. If it does not exist it returns the default. // GetEnv retrieves the environment variable key. If it does not exist it returns the default.
func GetEnv(key string, dfault string, combineWith ...string) string { func GetEnv(key string, dfault string, combineWith ...string) string {
value := os.Getenv(key) value := os.Getenv(key)
if value == "" { if value == "" {

@ -1,3 +1,4 @@
//go:build darwin
// +build darwin // +build darwin
package common package common

@ -1,3 +1,4 @@
//go:build freebsd || openbsd
// +build freebsd openbsd // +build freebsd openbsd
package common package common

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package common package common
@ -55,7 +56,6 @@ func NumProcs() (uint64, error) {
} }
func BootTimeWithContext(ctx context.Context) (uint64, error) { func BootTimeWithContext(ctx context.Context) (uint64, error) {
system, role, err := Virtualization() system, role, err := Virtualization()
if err != nil { if err != nil {
return 0, err return 0, err
@ -201,7 +201,6 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
if PathExists(filepath.Join(filename, "self", "status")) { if PathExists(filepath.Join(filename, "self", "status")) {
contents, err := ReadLines(filepath.Join(filename, "self", "status")) contents, err := ReadLines(filepath.Join(filename, "self", "status"))
if err == nil { if err == nil {
if StringsContains(contents, "s_context:") || if StringsContains(contents, "s_context:") ||
StringsContains(contents, "VxID:") { StringsContains(contents, "VxID:") {
system = "linux-vserver" system = "linux-vserver"

@ -1,3 +1,4 @@
//go:build openbsd
// +build openbsd // +build openbsd
package common package common

@ -37,6 +37,7 @@ func TestIntToString(t *testing.T) {
t.Error("could not convert") t.Error("could not convert")
} }
} }
func TestByteToString(t *testing.T) { func TestByteToString(t *testing.T) {
src := []byte{65, 66, 67} src := []byte{65, 66, 67}
dst := ByteToString(src) dst := ByteToString(src)
@ -63,12 +64,14 @@ func TestMustParseInt32(t *testing.T) {
t.Error("could not parse") t.Error("could not parse")
} }
} }
func TestMustParseUint64(t *testing.T) { func TestMustParseUint64(t *testing.T) {
ret := mustParseUint64("11111") ret := mustParseUint64("11111")
if ret != uint64(11111) { if ret != uint64(11111) {
t.Error("could not parse") t.Error("could not parse")
} }
} }
func TestMustParseFloat64(t *testing.T) { func TestMustParseFloat64(t *testing.T) {
ret := mustParseFloat64("11111.11") ret := mustParseFloat64("11111.11")
if ret != float64(11111.11) { if ret != float64(11111.11) {
@ -79,6 +82,7 @@ func TestMustParseFloat64(t *testing.T) {
t.Error("could not parse") t.Error("could not parse")
} }
} }
func TestStringsContains(t *testing.T) { func TestStringsContains(t *testing.T) {
target, err := ReadLines("common_test.go") target, err := ReadLines("common_test.go")
if err != nil { if err != nil {

@ -1,3 +1,4 @@
//go:build linux || freebsd || darwin || openbsd
// +build linux freebsd darwin openbsd // +build linux freebsd darwin openbsd
package common package common

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package common package common
@ -162,7 +163,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance
if err != nil { if err != nil {
return nil, err return nil, err
} }
var counter = Win32PerformanceCounter{ counter := Win32PerformanceCounter{
Query: query, Query: query,
PostName: postName, PostName: postName,
CounterName: counterName, CounterName: counterName,

@ -8,7 +8,7 @@ import (
// Sleep awaits for provided interval. // Sleep awaits for provided interval.
// Can be interrupted by context cancelation. // Can be interrupted by context cancelation.
func Sleep(ctx context.Context, interval time.Duration) error { func Sleep(ctx context.Context, interval time.Duration) error {
var timer = time.NewTimer(interval) timer := time.NewTimer(interval)
select { select {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return ctx.Err()

@ -11,17 +11,17 @@ import (
func TestSleep(test *testing.T) { func TestSleep(test *testing.T) {
const dt = 50 * time.Millisecond const dt = 50 * time.Millisecond
var t = func(name string, ctx context.Context, expected error) { t := func(name string, ctx context.Context, expected error) {
test.Run(name, func(test *testing.T) { test.Run(name, func(test *testing.T) {
var err = common.Sleep(ctx, dt) err := common.Sleep(ctx, dt)
if !errors.Is(err, expected) { if !errors.Is(err, expected) {
test.Errorf("expected %v, got %v", expected, err) test.Errorf("expected %v, got %v", expected, err)
} }
}) })
} }
var ctx = context.Background() ctx := context.Background()
var canceled, cancel = context.WithCancel(ctx) canceled, cancel := context.WithCancel(ctx)
cancel() cancel()
t("background context", ctx, nil) t("background context", ctx, nil)

@ -1,3 +1,4 @@
//go:build aix
// +build aix // +build aix
package load package load

@ -1,3 +1,4 @@
//go:build darwin
// +build darwin // +build darwin
package load package load

@ -1,3 +1,4 @@
//go:build !darwin && !linux && !freebsd && !openbsd && !windows && !solaris && !aix
// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix // +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix
package load package load

@ -1,3 +1,4 @@
//go:build freebsd
// +build freebsd // +build freebsd
package load package load

@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package load package load

@ -1,3 +1,4 @@
//go:build openbsd
// +build openbsd // +build openbsd
package load package load

@ -1,3 +1,4 @@
//go:build solaris
// +build solaris // +build solaris
package load package load

@ -71,7 +71,6 @@ func TestMiscStatString(t *testing.T) {
} }
func BenchmarkLoad(b *testing.B) { func BenchmarkLoad(b *testing.B) {
loadAvg := func(t testing.TB) { loadAvg := func(t testing.TB) {
v, err := Avg() v, err := Avg()
skipIfNotImplementedErr(t, err) skipIfNotImplementedErr(t, err)

@ -1,3 +1,4 @@
//go:build windows
// +build windows // +build windows
package load package load

@ -1,3 +1,4 @@
//go:build aix
// +build aix // +build aix
package mem package mem

@ -1,3 +1,4 @@
//go:build freebsd || openbsd
// +build freebsd openbsd // +build freebsd openbsd
package mem package mem

@ -1,3 +1,4 @@
//go:build freebsd || openbsd
// +build freebsd openbsd // +build freebsd openbsd
package mem package mem

@ -1,3 +1,4 @@
//go:build darwin
// +build darwin // +build darwin
package mem package mem

@ -1,3 +1,4 @@
//go:build darwin && cgo
// +build darwin,cgo // +build darwin,cgo
package mem package mem

@ -1,3 +1,4 @@
//go:build darwin && !cgo
// +build darwin,!cgo // +build darwin,!cgo
package mem package mem

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save