Skip to content

Commit

Permalink
updated TestProcIOStats test
Browse files Browse the repository at this point in the history
On this test we assumed that there would always be reading stats for our
own process /proc/self, but on restricted environments that might not
alwys be the case. Anyway, a value of 0 is not an error in itself.

Closes #1075
  • Loading branch information
gustavo-iniguez-goya committed Jan 5, 2024
1 parent 1518cb3 commit b2bd56d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
18 changes: 10 additions & 8 deletions daemon/procmon/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ func (p *Process) readDescriptors() {
}
}

func (p *Process) readIOStats() {
func (p *Process) readIOStats() (err error) {
f, err := os.Open(p.pathIO)
if err != nil {
return
return err
}
defer f.Close()

Expand All @@ -318,19 +318,21 @@ func (p *Process) readIOStats() {
s := strings.Split(scanner.Text(), " ")
switch s[0] {
case "rchar:":
p.IOStats.RChar, _ = strconv.ParseInt(s[1], 10, 64)
p.IOStats.RChar, err = strconv.ParseInt(s[1], 10, 64)
case "wchar:":
p.IOStats.WChar, _ = strconv.ParseInt(s[1], 10, 64)
p.IOStats.WChar, err = strconv.ParseInt(s[1], 10, 64)
case "syscr:":
p.IOStats.SyscallRead, _ = strconv.ParseInt(s[1], 10, 64)
p.IOStats.SyscallRead, err = strconv.ParseInt(s[1], 10, 64)
case "syscw:":
p.IOStats.SyscallWrite, _ = strconv.ParseInt(s[1], 10, 64)
p.IOStats.SyscallWrite, err = strconv.ParseInt(s[1], 10, 64)
case "read_bytes:":
p.IOStats.ReadBytes, _ = strconv.ParseInt(s[1], 10, 64)
p.IOStats.ReadBytes, err = strconv.ParseInt(s[1], 10, 64)
case "write_bytes:":
p.IOStats.WriteBytes, _ = strconv.ParseInt(s[1], 10, 64)
p.IOStats.WriteBytes, err = strconv.ParseInt(s[1], 10, 64)
}
}

return err
}

func (p *Process) readStatus() {
Expand Down
21 changes: 3 additions & 18 deletions daemon/procmon/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,11 @@ func TestProcEnv(t *testing.T) {
}

func TestProcIOStats(t *testing.T) {
proc.readIOStats()
err := proc.readIOStats()

if proc.IOStats.RChar == 0 {
t.Error("Proc.IOStats.RChar should not be 0:", proc.IOStats)
if err != nil {
t.Error("error reading proc IOStats:", err)
}
if proc.IOStats.WChar == 0 {
t.Error("Proc.IOStats.WChar should not be 0:", proc.IOStats)
}
if proc.IOStats.SyscallRead == 0 {
t.Error("Proc.IOStats.SyscallRead should not be 0:", proc.IOStats)
}
if proc.IOStats.SyscallWrite == 0 {
t.Error("Proc.IOStats.SyscallWrite should not be 0:", proc.IOStats)
}
/*if proc.IOStats.ReadBytes == 0 {
t.Error("Proc.IOStats.ReadBytes should not be 0:", proc.IOStats)
}
if proc.IOStats.WriteBytes == 0 {
t.Error("Proc.IOStats.WriteBytes should not be 0:", proc.IOStats)
}*/
}

func TestProcStatus(t *testing.T) {
Expand Down

0 comments on commit b2bd56d

Please sign in to comment.