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

Function parseCPUInfoARM

cpuinfo.go:190–254  ·  view source on GitHub ↗
(info []byte)

Source from the content-addressed store, hash-verified

188}
189
190func parseCPUInfoARM(info []byte) ([]CPUInfo, error) {
191 scanner := bufio.NewScanner(bytes.NewReader(info))
192
193 firstLine := firstNonEmptyLine(scanner)
194 match, err := regexp.MatchString("^[Pp]rocessor", firstLine)
195 if !match || !strings.Contains(firstLine, ":") {
196 return nil, fmt.Errorf("%w: Cannot parse line: %q: %w", ErrFileParse, firstLine, err)
197
198 }
199 field := strings.SplitN(firstLine, ": ", 2)
200 cpuinfo := []CPUInfo{}
201 featuresLine := ""
202 commonCPUInfo := CPUInfo{}
203 i := 0
204 if strings.TrimSpace(field[0]) == "Processor" {
205 commonCPUInfo = CPUInfo{ModelName: field[1]}
206 i = -1
207 } else {
208 v, err := strconv.ParseUint(field[1], 0, 32)
209 if err != nil {
210 return nil, err
211 }
212 firstcpu := CPUInfo{Processor: uint(v)}
213 cpuinfo = []CPUInfo{firstcpu}
214 }
215
216 for scanner.Scan() {
217 line := scanner.Text()
218 if !strings.Contains(line, ":") {
219 continue
220 }
221 field := strings.SplitN(line, ": ", 2)
222 switch strings.TrimSpace(field[0]) {
223 case "processor":
224 cpuinfo = append(cpuinfo, commonCPUInfo) // start of the next processor
225 i++
226 v, err := strconv.ParseUint(field[1], 0, 32)
227 if err != nil {
228 return nil, err
229 }
230 cpuinfo[i].Processor = uint(v)
231 case "BogoMIPS":
232 if i == -1 {
233 cpuinfo = append(cpuinfo, commonCPUInfo) // There is only one processor
234 i++
235 cpuinfo[i].Processor = 0
236 }
237 v, err := strconv.ParseFloat(field[1], 64)
238 if err != nil {
239 return nil, err
240 }
241 cpuinfo[i].BogoMips = v
242 case "Features":
243 featuresLine = line
244 case "model name":
245 cpuinfo[i].ModelName = field[1]
246 }
247 }

Callers 3

TestCPUInfoParseARMFunction · 0.85

Calls 1

firstNonEmptyLineFunction · 0.85

Tested by 3

TestCPUInfoParseARMFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…