Skip to content

Commit d6427f4

Browse files
committed
Make sure walking up process hierarchy happens before resource usage aggregation
1 parent d35d87c commit d6427f4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

utils/hwstats/cpu.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,14 @@ func (c *CPUStats) monitorProcesses() {
205205
}
206206

207207
for pid, stat := range procStats {
208+
pidForGroup := pid
209+
for ppids[pidForGroup] != self.PID && ppids[pidForGroup] != 0 {
210+
// bundle usage up to first child of main go process
211+
pidForGroup = ppids[pidForGroup]
212+
}
213+
208214
memory := stat.RSS * pageSize
209-
stats.Memory[pid] += memory
215+
stats.Memory[pidForGroup] += memory
210216
stats.MemoryTotal += memory
211217

212218
// process usage as percent of total host cpu
@@ -215,13 +221,8 @@ func (c *CPUStats) monitorProcesses() {
215221
continue
216222
}
217223

218-
for ppids[pid] != self.PID && ppids[pid] != 0 {
219-
// bundle usage up to first child of main go process
220-
pid = ppids[pid]
221-
}
222-
223224
cpu := hostCPU * procPercentUsage / 100 / (totalHostTime - prevTotalTime)
224-
stats.Cpu[pid] += cpu
225+
stats.Cpu[pidForGroup] += cpu
225226
stats.CpuIdle -= cpu
226227
}
227228

0 commit comments

Comments
 (0)