enable unparam linter

pull/1208/head
Matthieu MOREL 3 years ago committed by GitHub
parent b1186a68ed
commit c8fd8c7b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,9 +1,12 @@
issues:
max-same-issues: 0
linters: linters:
enable: enable:
- errorlint - errorlint
- gci - gci
- gosimple - gosimple
- typecheck - typecheck
- unparam
disable: disable:
- deadcode - deadcode
- errcheck - errcheck

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

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

@ -35,7 +35,7 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
} }
func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
vm, _, err := fillFromMeminfoWithContext(ctx) vm, _, err := fillFromMeminfoWithContext()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -47,14 +47,14 @@ func VirtualMemoryEx() (*VirtualMemoryExStat, error) {
} }
func VirtualMemoryExWithContext(ctx context.Context) (*VirtualMemoryExStat, error) { func VirtualMemoryExWithContext(ctx context.Context) (*VirtualMemoryExStat, error) {
_, vmEx, err := fillFromMeminfoWithContext(ctx) _, vmEx, err := fillFromMeminfoWithContext()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return vmEx, nil return vmEx, nil
} }
func fillFromMeminfoWithContext(ctx context.Context) (*VirtualMemoryStat, *VirtualMemoryExStat, error) { func fillFromMeminfoWithContext() (*VirtualMemoryStat, *VirtualMemoryExStat, error) {
filename := common.HostProc("meminfo") filename := common.HostProc("meminfo")
lines, _ := common.ReadLines(filename) lines, _ := common.ReadLines(filename)

@ -82,7 +82,7 @@ func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
func (p *Process) NameWithContext(ctx context.Context) (string, error) { func (p *Process) NameWithContext(ctx context.Context) (string, error) {
if p.name == "" { if p.name == "" {
if err := p.fillNameWithContext(ctx); err != nil { if err := p.fillNameWithContext(); err != nil {
return "", err return "", err
} }
} }
@ -91,7 +91,7 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) {
func (p *Process) TgidWithContext(ctx context.Context) (int32, error) { func (p *Process) TgidWithContext(ctx context.Context) (int32, error) {
if p.tgid == 0 { if p.tgid == 0 {
if err := p.fillFromStatusWithContext(ctx); err != nil { if err := p.fillFromStatusWithContext(); err != nil {
return 0, err return 0, err
} }
} }
@ -99,7 +99,7 @@ func (p *Process) TgidWithContext(ctx context.Context) (int32, error) {
} }
func (p *Process) ExeWithContext(ctx context.Context) (string, error) { func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
return p.fillFromExeWithContext(ctx) return p.fillFromExeWithContext()
} }
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) { func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
@ -119,11 +119,11 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
} }
func (p *Process) CwdWithContext(ctx context.Context) (string, error) { func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
return p.fillFromCwdWithContext(ctx) return p.fillFromCwdWithContext()
} }
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) { func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -134,7 +134,7 @@ func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
} }
func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) { func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext()
if err != nil { if err != nil {
return []string{""}, err return []string{""}, err
} }
@ -159,7 +159,7 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
} }
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext()
if err != nil { if err != nil {
return []int32{}, err return []int32{}, err
} }
@ -167,7 +167,7 @@ func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
} }
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext()
if err != nil { if err != nil {
return []int32{}, err return []int32{}, err
} }
@ -175,7 +175,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
} }
func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) { func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext()
if err != nil { if err != nil {
return []int32{}, err return []int32{}, err
} }
@ -212,7 +212,7 @@ func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
} }
func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) ([]RlimitStat, error) { func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) ([]RlimitStat, error) {
rlimits, err := p.fillFromLimitsWithContext(ctx) rlimits, err := p.fillFromLimitsWithContext()
if !gatherUsed || err != nil { if !gatherUsed || err != nil {
return rlimits, err return rlimits, err
} }
@ -221,7 +221,7 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) (
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := p.fillFromStatusWithContext(ctx); err != nil { if err := p.fillFromStatusWithContext(); err != nil {
return nil, err return nil, err
} }
@ -267,11 +267,11 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) (
} }
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) { func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
return p.fillFromIOWithContext(ctx) return p.fillFromIOWithContext()
} }
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) { func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -284,7 +284,7 @@ func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
} }
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) { func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
err := p.fillFromStatusWithContext(ctx) err := p.fillFromStatusWithContext()
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -324,7 +324,7 @@ func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
} }
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) { func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
meminfo, _, err := p.fillFromStatmWithContext(ctx) meminfo, _, err := p.fillFromStatmWithContext()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -332,7 +332,7 @@ func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, e
} }
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) { func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
_, memInfoEx, err := p.fillFromStatmWithContext(ctx) _, memInfoEx, err := p.fillFromStatmWithContext()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -513,7 +513,7 @@ func limitToUint(val string) (uint64, error) {
} }
// Get num_fds from /proc/(pid)/limits // Get num_fds from /proc/(pid)/limits
func (p *Process) fillFromLimitsWithContext(ctx context.Context) ([]RlimitStat, error) { func (p *Process) fillFromLimitsWithContext() ([]RlimitStat, error) {
pid := p.Pid pid := p.Pid
limitsFile := common.HostProc(strconv.Itoa(int(pid)), "limits") limitsFile := common.HostProc(strconv.Itoa(int(pid)), "limits")
d, err := os.Open(limitsFile) d, err := os.Open(limitsFile)
@ -648,7 +648,7 @@ func (p *Process) fillFromfdWithContext(ctx context.Context) (int32, []*OpenFile
} }
// Get cwd from /proc/(pid)/cwd // Get cwd from /proc/(pid)/cwd
func (p *Process) fillFromCwdWithContext(ctx context.Context) (string, error) { func (p *Process) fillFromCwdWithContext() (string, error) {
pid := p.Pid pid := p.Pid
cwdPath := common.HostProc(strconv.Itoa(int(pid)), "cwd") cwdPath := common.HostProc(strconv.Itoa(int(pid)), "cwd")
cwd, err := os.Readlink(cwdPath) cwd, err := os.Readlink(cwdPath)
@ -659,7 +659,7 @@ func (p *Process) fillFromCwdWithContext(ctx context.Context) (string, error) {
} }
// Get exe from /proc/(pid)/exe // Get exe from /proc/(pid)/exe
func (p *Process) fillFromExeWithContext(ctx context.Context) (string, error) { func (p *Process) fillFromExeWithContext() (string, error) {
pid := p.Pid pid := p.Pid
exePath := common.HostProc(strconv.Itoa(int(pid)), "exe") exePath := common.HostProc(strconv.Itoa(int(pid)), "exe")
exe, err := os.Readlink(exePath) exe, err := os.Readlink(exePath)
@ -707,7 +707,7 @@ func (p *Process) fillSliceFromCmdlineWithContext(ctx context.Context) ([]string
} }
// Get IO status from /proc/(pid)/io // Get IO status from /proc/(pid)/io
func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, error) { func (p *Process) fillFromIOWithContext() (*IOCountersStat, error) {
pid := p.Pid pid := p.Pid
ioPath := common.HostProc(strconv.Itoa(int(pid)), "io") ioPath := common.HostProc(strconv.Itoa(int(pid)), "io")
ioline, err := ioutil.ReadFile(ioPath) ioline, err := ioutil.ReadFile(ioPath)
@ -743,7 +743,7 @@ func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, e
} }
// Get memory info from /proc/(pid)/statm // Get memory info from /proc/(pid)/statm
func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoStat, *MemoryInfoExStat, error) { func (p *Process) fillFromStatmWithContext() (*MemoryInfoStat, *MemoryInfoExStat, error) {
pid := p.Pid pid := p.Pid
memPath := common.HostProc(strconv.Itoa(int(pid)), "statm") memPath := common.HostProc(strconv.Itoa(int(pid)), "statm")
contents, err := ioutil.ReadFile(memPath) contents, err := ioutil.ReadFile(memPath)
@ -795,16 +795,16 @@ func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoStat
} }
// Get name from /proc/(pid)/comm or /proc/(pid)/status // Get name from /proc/(pid)/comm or /proc/(pid)/status
func (p *Process) fillNameWithContext(ctx context.Context) error { func (p *Process) fillNameWithContext() error {
err := p.fillFromCommWithContext(ctx) err := p.fillFromCommWithContext()
if err == nil && p.name != "" && len(p.name) < 15 { if err == nil && p.name != "" && len(p.name) < 15 {
return nil return nil
} }
return p.fillFromStatusWithContext(ctx) return p.fillFromStatusWithContext()
} }
// Get name from /proc/(pid)/comm // Get name from /proc/(pid)/comm
func (p *Process) fillFromCommWithContext(ctx context.Context) error { func (p *Process) fillFromCommWithContext() error {
pid := p.Pid pid := p.Pid
statPath := common.HostProc(strconv.Itoa(int(pid)), "comm") statPath := common.HostProc(strconv.Itoa(int(pid)), "comm")
contents, err := ioutil.ReadFile(statPath) contents, err := ioutil.ReadFile(statPath)
@ -817,7 +817,7 @@ func (p *Process) fillFromCommWithContext(ctx context.Context) error {
} }
// Get various status from /proc/(pid)/status // Get various status from /proc/(pid)/status
func (p *Process) fillFromStatusWithContext(ctx context.Context) error { func (p *Process) fillFromStatusWithContext() error {
pid := p.Pid pid := p.Pid
statPath := common.HostProc(strconv.Itoa(int(pid)), "status") statPath := common.HostProc(strconv.Itoa(int(pid)), "status")
contents, err := ioutil.ReadFile(statPath) contents, err := ioutil.ReadFile(statPath)

@ -110,7 +110,7 @@ func Test_fillFromCommWithContext(t *testing.T) {
continue continue
} }
p, _ := NewProcess(int32(pid)) p, _ := NewProcess(int32(pid))
if err := p.fillFromCommWithContext(context.Background()); err != nil { if err := p.fillFromCommWithContext(); err != nil {
t.Error(err) t.Error(err)
} }
} }
@ -132,7 +132,7 @@ func Test_fillFromStatusWithContext(t *testing.T) {
continue continue
} }
p, _ := NewProcess(int32(pid)) p, _ := NewProcess(int32(pid))
if err := p.fillFromStatusWithContext(context.Background()); err != nil { if err := p.fillFromStatusWithContext(); err != nil {
t.Error(err) t.Error(err)
} }
} }
@ -144,7 +144,7 @@ func Benchmark_fillFromCommWithContext(b *testing.B) {
pid := 1060 pid := 1060
p, _ := NewProcess(int32(pid)) p, _ := NewProcess(int32(pid))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
p.fillFromCommWithContext(context.Background()) p.fillFromCommWithContext()
} }
} }
@ -154,7 +154,7 @@ func Benchmark_fillFromStatusWithContext(b *testing.B) {
pid := 1060 pid := 1060
p, _ := NewProcess(int32(pid)) p, _ := NewProcess(int32(pid))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
p.fillFromStatusWithContext(context.Background()) p.fillFromStatusWithContext()
} }
} }

Loading…
Cancel
Save