MCPcopy Create free account
hub / github.com/prometheus/procfs / parseInterrupts

Function parseInterrupts

proc_interrupts.go:52–98  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

50}
51
52func parseInterrupts(r io.Reader) (Interrupts, error) {
53 var (
54 interrupts = Interrupts{}
55 scanner = bufio.NewScanner(r)
56 )
57
58 if !scanner.Scan() {
59 return nil, errors.New("interrupts empty")
60 }
61 cpuNum := len(strings.Fields(scanner.Text())) // one header per cpu
62
63 for scanner.Scan() {
64 parts := strings.Fields(scanner.Text())
65 if len(parts) == 0 { // skip empty lines
66 continue
67 }
68 if len(parts) < 2 {
69 return nil, fmt.Errorf("%w: Not enough fields in interrupts (expected 2+ fields but got %d): %s", ErrFileParse, len(parts), parts)
70 }
71 intName := parts[0][:len(parts[0])-1] // remove trailing :
72
73 if len(parts) == 2 {
74 interrupts[intName] = Interrupt{
75 Info: "",
76 Devices: "",
77 Values: []string{
78 parts[1],
79 },
80 }
81 continue
82 }
83
84 intr := Interrupt{
85 Values: parts[1 : cpuNum+1],
86 }
87
88 if _, err := strconv.Atoi(intName); err == nil { // numeral interrupt
89 intr.Info = parts[cpuNum+1]
90 intr.Devices = strings.Join(parts[cpuNum+2:], " ")
91 } else {
92 intr.Info = strings.Join(parts[cpuNum+1:], " ")
93 }
94 interrupts[intName] = intr
95 }
96
97 return interrupts, scanner.Err()
98}

Callers 1

InterruptsMethod · 0.85

Calls 1

ErrMethod · 0.80

Tested by

no test coverage detected