(r io.Reader)
| 74 | } |
| 75 | |
| 76 | func parseInterrupts(r io.Reader) (map[string]interrupt, error) { |
| 77 | var ( |
| 78 | interrupts = map[string]interrupt{} |
| 79 | scanner = bufio.NewScanner(r) |
| 80 | ) |
| 81 | |
| 82 | if !scanner.Scan() { |
| 83 | return nil, errors.New("interrupts empty") |
| 84 | } |
| 85 | cpuNum := len(strings.Fields(scanner.Text())) // one header per cpu |
| 86 | |
| 87 | for scanner.Scan() { |
| 88 | // On aarch64 there can be zero space between the name/label |
| 89 | // and the values, so we need to split on `:` before using |
| 90 | // strings.Fields() to split on fields. |
| 91 | group := strings.SplitN(scanner.Text(), ":", 2) |
| 92 | if len(group) > 1 { |
| 93 | parts := strings.Fields(group[1]) |
| 94 | |
| 95 | if len(parts) < cpuNum+1 { // irq + one column per cpu + details, |
| 96 | continue // we ignore ERR and MIS for now |
| 97 | } |
| 98 | intName := strings.TrimLeft(group[0], " ") |
| 99 | intr := interrupt{ |
| 100 | values: parts[0:cpuNum], |
| 101 | } |
| 102 | |
| 103 | if _, err := strconv.Atoi(intName); err == nil { // numeral interrupt |
| 104 | intr.info = parts[cpuNum] |
| 105 | intr.devices = strings.Join(parts[cpuNum+1:], " ") |
| 106 | } else { |
| 107 | intr.info = strings.Join(parts[cpuNum:], " ") |
| 108 | } |
| 109 | interrupts[intName] = intr |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return interrupts, scanner.Err() |
| 114 | } |
no outgoing calls