Merge pull request #1083 from elmeyer/fix-processes-smartos
process, v3/process (Linux): fix Processes in SmartOS lx containers
This commit is contained in:
commit
7ea8062810
|
@ -1032,9 +1032,14 @@ func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (ui
|
|||
// There is no such thing as iotime in stat file. As an approximation, we
|
||||
// will use delayacct_blkio_ticks (aggregated block I/O delays, as per Linux
|
||||
// docs). Note: I am assuming at least Linux 2.6.18
|
||||
iotime, err := strconv.ParseFloat(fields[42], 64)
|
||||
if err != nil {
|
||||
iotime = 0 // Ancient linux version, most likely
|
||||
var iotime float64
|
||||
if len(fields) > 42 {
|
||||
iotime, err = strconv.ParseFloat(fields[42], 64)
|
||||
if err != nil {
|
||||
iotime = 0 // Ancient linux version, most likely
|
||||
}
|
||||
} else {
|
||||
iotime = 0 // e.g. SmartOS containers
|
||||
}
|
||||
|
||||
cpuTimes := &cpu.TimesStat{
|
||||
|
|
|
@ -115,3 +115,27 @@ func Test_fillFromStatusWithContext(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_fillFromTIDStatWithContext_lx_brandz(t *testing.T) {
|
||||
pids, err := ioutil.ReadDir("testdata/lx_brandz/")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
f := common.MockEnv("HOST_PROC", "testdata/lx_brandz")
|
||||
defer f()
|
||||
for _, pid := range pids {
|
||||
pid, err := strconv.ParseInt(pid.Name(), 0, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(fmt.Sprintf("testdata/lx_brandz/%d/stat", pid)); err != nil {
|
||||
continue
|
||||
}
|
||||
p, _ := NewProcess(int32(pid))
|
||||
_, _, cpuTimes, _, _, _, _, err := p.fillFromTIDStatWithContext(context.Background(), -1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t, float64(0), cpuTimes.Iowait)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
1 (systemd) S 0 0 0 0 -1 0 0 0 0 0 8 15 48 52 1 0 0 0 25 31883264 1413 18446744073709551615 0 0 140737487261696 0 0 0 0 0 0 18446741901776689794 0 0 17 0
|
|
@ -1027,9 +1027,14 @@ func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (ui
|
|||
// There is no such thing as iotime in stat file. As an approximation, we
|
||||
// will use delayacct_blkio_ticks (aggregated block I/O delays, as per Linux
|
||||
// docs). Note: I am assuming at least Linux 2.6.18
|
||||
iotime, err := strconv.ParseFloat(fields[42], 64)
|
||||
if err != nil {
|
||||
iotime = 0 // Ancient linux version, most likely
|
||||
var iotime float64
|
||||
if len(fields) > 42 {
|
||||
iotime, err = strconv.ParseFloat(fields[42], 64)
|
||||
if err != nil {
|
||||
iotime = 0 // Ancient linux version, most likely
|
||||
}
|
||||
} else {
|
||||
iotime = 0 // e.g. SmartOS containers
|
||||
}
|
||||
|
||||
cpuTimes := &cpu.TimesStat{
|
||||
|
|
|
@ -114,4 +114,28 @@ func Test_fillFromStatusWithContext(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_fillFromTIDStatWithContext_lx_brandz(t *testing.T) {
|
||||
pids, err := ioutil.ReadDir("testdata/lx_brandz/")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
f := common.MockEnv("HOST_PROC", "testdata/lx_brandz")
|
||||
defer f()
|
||||
for _, pid := range pids {
|
||||
pid, err := strconv.ParseInt(pid.Name(), 0, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(fmt.Sprintf("testdata/lx_brandz/%d/stat", pid)); err != nil {
|
||||
continue
|
||||
}
|
||||
p, _ := NewProcess(int32(pid))
|
||||
_, _, cpuTimes, _, _, _, _, err := p.fillFromTIDStatWithContext(context.Background(), -1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t, float64(0), cpuTimes.Iowait)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
1 (systemd) S 0 0 0 0 -1 0 0 0 0 0 8 15 48 52 1 0 0 0 25 31883264 1413 18446744073709551615 0 0 140737487261696 0 0 0 0 0 0 18446741901776689794 0 0 17 0
|
Loading…
Reference in New Issue