Merge pull request #1205 from mmorel-35/master

enable more linters, report coverage and cache mods
tags/v3.21.12 v3.21.12
shirou 3 years ago committed by GitHub
commit 2f8da0a394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,6 +13,18 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- id: cache-paths
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
- name: Cache go modules
uses: actions/cache@v2
with:
path: |
${{ steps.cache-paths.outputs.cache }}
${{ steps.cache-paths.outputs.mod-cache }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- name: Build Test v3
run: |
make build_test

@ -14,6 +14,25 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- id: go-env
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
- name: Cache go modules
uses: actions/cache@v2
with:
path: |
${{ steps.go-env.outputs.cache }}
${{ steps.go-env.outputs.mod-cache }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- name: Test
run: |
go test ./...
go test -coverprofile='coverage.out' -covermode=atomic ./...
- name: Upload Code Coverage
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
files: coverage.out
flags: ${{ runner.os }},go-${{ matrix.go-version }}
token: ${{ secrets.CODECOV_TOKEN }}

@ -1,9 +1,35 @@
issues:
max-same-issues: 0
exclude-rules:
- linters:
- gosec
text: "G204"
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "exported"
linters:
enable:
- asciicheck
- durationcheck
- errorlint
- gci
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
- importas
- megacheck
- misspell
- nakedret
- nolintlint
- predeclared
- revive
- typecheck
- unparam
disable:
- deadcode
- errcheck

@ -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
@ -60,7 +61,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
Mhz: float64(c.ProcessorHz / 1000000),
Cores: int32(c.NCpusCfg),
}
result := []InfoStat{info};
result := []InfoStat{info}
return result, nil
}
@ -71,4 +72,3 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
}
return c.NCpusCfg, nil
}

@ -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 {
@ -63,7 +64,7 @@ func sysCPUPath(cpu int32, relPath string) string {
return common.HostSys(fmt.Sprintf("devices/system/cpu/cpu%d", cpu), relPath)
}
func finishCPUInfo(c *InfoStat) error {
func finishCPUInfo(c *InfoStat) {
var lines []string
var err error
var value float64
@ -82,17 +83,16 @@ func finishCPUInfo(c *InfoStat) error {
// if we encounter errors below such as there are no cpuinfo_max_freq file,
// we just ignore. so let Mhz is 0.
if err != nil || len(lines) == 0 {
return nil
return
}
value, err = strconv.ParseFloat(lines[0], 64)
if err != nil {
return nil
return
}
c.Mhz = value / 1000.0 // value is in kHz
if c.Mhz > 9999 {
c.Mhz = c.Mhz / 1000.0 // value in Hz
}
return nil
}
// CPUInfo on linux will return 1 item per physical thread.
@ -127,10 +127,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
processorName = value
case "processor":
if c.CPU >= 0 {
err := finishCPUInfo(&c)
if err != nil {
return ret, err
}
finishCPUInfo(&c)
ret = append(ret, c)
}
c = InfoStat{Cores: 1, ModelName: processorName}
@ -224,10 +221,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
}
}
if c.CPU >= 0 {
err := finishCPUInfo(&c)
if err != nil {
return ret, err
}
finishCPUInfo(&c)
ret = append(ret, c)
}
return ret, nil
@ -345,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

@ -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
@ -7,8 +8,8 @@ import (
"fmt"
"unsafe"
"github.com/yusufpapurcu/wmi"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)

@ -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
@ -484,9 +486,8 @@ func LabelWithContext(ctx context.Context, name string) (string, error) {
dmname, err := ioutil.ReadFile(dmname_filename)
if err != nil {
return "", err
} else {
return strings.TrimSpace(string(dmname)), nil
}
return strings.TrimSpace(string(dmname)), nil
}
func getFsType(stat unix.Statfs_t) string {

@ -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": struct{}{},
"dev": struct{}{},
"fd": struct{}{},
"lofs": struct{}{},
"lxproc": struct{}{},
"mntfs": struct{}{},
"objfs": struct{}{},
"proc": struct{}{},
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

@ -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
@ -13,9 +14,9 @@ import (
"time"
"unsafe"
"github.com/yusufpapurcu/wmi"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v3/process"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)

@ -15,9 +15,8 @@ func (w *Warnings) Add(err error) {
func (w *Warnings) Reference() error {
if len(w.List) > 0 {
return w
} else {
return nil
}
return nil
}
func (w *Warnings) Error() string {

@ -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
}

@ -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
@ -56,7 +57,7 @@ func CallPgrepWithContext(ctx context.Context, invoke Invoker, pid int32) ([]int
if len(l) == 0 {
continue
}
i, err := strconv.Atoi(l)
i, err := strconv.ParseInt(l, 10, 32)
if err != nil {
continue
}

@ -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
@ -68,4 +69,3 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
}
return &ret, nil
}

@ -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
@ -17,14 +18,14 @@ func Avg() (*AvgStat, error) {
}
func AvgWithContext(ctx context.Context) (*AvgStat, error) {
stat, err := fileAvgWithContext(ctx)
stat, err := fileAvgWithContext()
if err != nil {
stat, err = sysinfoAvgWithContext(ctx)
stat, err = sysinfoAvgWithContext()
}
return stat, err
}
func sysinfoAvgWithContext(ctx context.Context) (*AvgStat, error) {
func sysinfoAvgWithContext() (*AvgStat, error) {
var info syscall.Sysinfo_t
err := syscall.Sysinfo(&info)
if err != nil {
@ -39,7 +40,7 @@ func sysinfoAvgWithContext(ctx context.Context) (*AvgStat, error) {
}, nil
}
func fileAvgWithContext(ctx context.Context) (*AvgStat, error) {
func fileAvgWithContext() (*AvgStat, error) {
values, err := readLoadAvgFromFile()
if err != nil {
return nil, err

@ -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

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

Loading…
Cancel
Save