mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-29 13:49:21 +08:00
Minor cleanups motivated by staticcheck warnings.
This commit is contained in:
parent
5ce887df8f
commit
bc4661937d
@ -351,7 +351,7 @@ func (p *Process) PageFaultsWithContext(ctx context.Context) (*PageFaultsStat, e
|
|||||||
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
pids, err := common.CallPgrepWithContext(ctx, invoke, p.Pid)
|
pids, err := common.CallPgrepWithContext(ctx, invoke, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pids == nil || len(pids) == 0 {
|
if len(pids) == 0 {
|
||||||
return nil, ErrorNoChildren
|
return nil, ErrorNoChildren
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -705,10 +705,7 @@ func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
ret := strings.FieldsFunc(string(cmdline), func(r rune) bool {
|
ret := strings.FieldsFunc(string(cmdline), func(r rune) bool {
|
||||||
if r == '\u0000' {
|
return r == '\u0000'
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return strings.Join(ret, " "), nil
|
return strings.Join(ret, " "), nil
|
||||||
|
@ -418,14 +418,14 @@ func Test_Process_Exe(t *testing.T) {
|
|||||||
|
|
||||||
func Test_Process_CpuPercent(t *testing.T) {
|
func Test_Process_CpuPercent(t *testing.T) {
|
||||||
p := testGetProcess()
|
p := testGetProcess()
|
||||||
percent, err := p.Percent(0)
|
_, err := p.Percent(0)
|
||||||
skipIfNotImplementedErr(t, err)
|
skipIfNotImplementedErr(t, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error %v", err)
|
t.Errorf("error %v", err)
|
||||||
}
|
}
|
||||||
duration := time.Duration(1000) * time.Microsecond
|
duration := time.Duration(1000) * time.Microsecond
|
||||||
time.Sleep(duration)
|
time.Sleep(duration)
|
||||||
percent, err = p.Percent(0)
|
percent, err := p.Percent(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error %v", err)
|
t.Errorf("error %v", err)
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ func (p *Process) PageFaultsWithContext(ctx context.Context) (*PageFaultsStat, e
|
|||||||
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
pids, err := common.CallPgrepWithContext(ctx, invoke, p.Pid)
|
pids, err := common.CallPgrepWithContext(ctx, invoke, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pids == nil || len(pids) == 0 {
|
if len(pids) == 0 {
|
||||||
return nil, ErrorNoChildren
|
return nil, ErrorNoChildren
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -678,10 +678,7 @@ func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
ret := strings.FieldsFunc(string(cmdline), func(r rune) bool {
|
ret := strings.FieldsFunc(string(cmdline), func(r rune) bool {
|
||||||
if r == '\u0000' {
|
return r == '\u0000'
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return strings.Join(ret, " "), nil
|
return strings.Join(ret, " "), nil
|
||||||
|
@ -420,14 +420,14 @@ func Test_Process_Exe(t *testing.T) {
|
|||||||
|
|
||||||
func Test_Process_CpuPercent(t *testing.T) {
|
func Test_Process_CpuPercent(t *testing.T) {
|
||||||
p := testGetProcess()
|
p := testGetProcess()
|
||||||
percent, err := p.Percent(0)
|
_, err := p.Percent(0)
|
||||||
skipIfNotImplementedErr(t, err)
|
skipIfNotImplementedErr(t, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error %v", err)
|
t.Errorf("error %v", err)
|
||||||
}
|
}
|
||||||
duration := time.Duration(1000) * time.Microsecond
|
duration := time.Duration(1000) * time.Microsecond
|
||||||
time.Sleep(duration)
|
time.Sleep(duration)
|
||||||
percent, err = p.Percent(0)
|
percent, err := p.Percent(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error %v", err)
|
t.Errorf("error %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user