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

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

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

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

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

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

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

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

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

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

@ -1,3 +1,4 @@
//go:build linux
// +build linux
package cpu
@ -30,7 +31,7 @@ func Times(percpu bool) ([]TimesStat, error) {
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
filename := common.HostProc("stat")
var lines = []string{}
lines := []string{}
if percpu {
statlines, err := common.ReadLines(filename)
if err != nil || len(statlines) < 2 {
@ -338,7 +339,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
}
// physical cores
// 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.
// https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst
// https://github.com/giampaolo/psutil/pull/1727#issuecomment-707624964

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

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

@ -1,3 +1,4 @@
//go:build plan9
// +build plan9
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 {
total := 0.0
for _, y := range x {
@ -47,7 +47,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
user := make(map[float64]float64)
kern := 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$/")
if err != nil {
return nil, fmt.Errorf("cannot execute kstat: %s", err)

@ -15,28 +15,36 @@ func TestParseISAInfo(t *testing.T) {
}{
{
"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",
"tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8",
"tsc", "fpu"},
"tsc", "fpu",
},
},
{
"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",
"tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8",
"tsc", "fpu"},
"tsc", "fpu",
},
},
{
"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",
"tsc", "fpu"},
"tsc", "fpu",
},
},
{
"2cpu_12core_isainfo.txt",
[]string{"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"},
[]string{
"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 {
assert.InEpsilon(t, cpuTotal[0].Idle, perCPUIdleTimeSum, margin)
}
}
func TestCpu_counts(t *testing.T) {
@ -162,7 +161,6 @@ func testCPUPercent(t *testing.T, percpu bool) {
}
func testCPUPercentLastUsed(t *testing.T, percpu bool) {
numcpu := runtime.NumCPU()
testCount := 10
@ -194,7 +192,6 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) {
}
}
}
}
func TestCPUPercent(t *testing.T) {

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

@ -1,3 +1,4 @@
//go:build aix
// +build aix
package disk
@ -13,10 +14,12 @@ import (
var FSType map[int]string
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",
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) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,3 +1,4 @@
//go:build windows
// +build windows
package disk
@ -106,7 +107,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
uintptr(len(lpFileSystemNameBuffer)))
if driveret == 0 {
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
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -98,7 +98,6 @@ var ErrNotImplementedError = errors.New("not implemented yet")
// ReadFile reads contents from a file
func ReadFile(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
@ -312,7 +311,7 @@ func PathExists(filename string) bool {
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 {
value := os.Getenv(key)
if value == "" {

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

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

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

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

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

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

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

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

@ -11,17 +11,17 @@ import (
func TestSleep(test *testing.T) {
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) {
var err = common.Sleep(ctx, dt)
err := common.Sleep(ctx, dt)
if !errors.Is(err, expected) {
test.Errorf("expected %v, got %v", expected, err)
}
})
}
var ctx = context.Background()
var canceled, cancel = context.WithCancel(ctx)
ctx := context.Background()
canceled, cancel := context.WithCancel(ctx)
cancel()
t("background context", ctx, nil)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save