Skip to content

Commit

Permalink
parse cpu with ID in /proc/stat
Browse files Browse the repository at this point in the history
Signed-off-by: Jia Xin <alexjx@gmail.com>
  • Loading branch information
alexjx authored and discordianfish committed Sep 29, 2022
1 parent f5d82fa commit 800411b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions stat.go
Expand Up @@ -62,7 +62,7 @@ type Stat struct {
// Summed up cpu statistics.
CPUTotal CPUStat
// Per-CPU statistics.
CPU []CPUStat
CPU map[int64]CPUStat
// Number of times interrupts were handled, which contains numbered and unnumbered IRQs.
IRQTotal uint64
// Number of times a numbered IRQ was triggered.
Expand Down Expand Up @@ -171,7 +171,9 @@ func (fs FS) Stat() (Stat, error) {
return Stat{}, err
}

stat := Stat{}
stat := Stat{
CPU: make(map[int64]CPUStat),
}

scanner := bufio.NewScanner(bytes.NewReader(data))
for scanner.Scan() {
Expand Down Expand Up @@ -228,9 +230,6 @@ func (fs FS) Stat() (Stat, error) {
if cpuID == -1 {
stat.CPUTotal = cpuStat
} else {
for int64(len(stat.CPU)) <= cpuID {
stat.CPU = append(stat.CPU, CPUStat{})
}
stat.CPU[cpuID] = cpuStat
}
}
Expand Down

0 comments on commit 800411b

Please sign in to comment.