Skip to content

Commit

Permalink
metrics: fix the panic for reading empty cpu stats (ethereum#21864)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 authored and enriquefynn committed Feb 15, 2021
1 parent a3c9929 commit 1364186
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metrics/cpu_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func ReadCPUStats(stats *CPUStats) {
log.Error("Could not read cpu stats", "err", err)
return
}
if len(timeStats) == 0 {
log.Error("Empty cpu stats")
return
}
// requesting all cpu times will always return an array with only one time stats entry
timeStat := timeStats[0]
stats.GlobalTime = int64((timeStat.User + timeStat.Nice + timeStat.System) * cpu.ClocksPerSec)
Expand Down

0 comments on commit 1364186

Please sign in to comment.