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 committed Mar 24, 2022
1 parent 5f46783 commit 754b774
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions stat.go
Original file line number Diff line number Diff line change
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,10 +230,7 @@ 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
stat.CPU[cpuID] = &cpuStat
}
}
}
Expand Down

0 comments on commit 754b774

Please sign in to comment.