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

Function parseCPUInfoMips

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

Source from the content-addressed store, hash-verified

338}
339
340func parseCPUInfoMips(info []byte) ([]CPUInfo, error) {
341 scanner := bufio.NewScanner(bytes.NewReader(info))
342
343 // find the first "processor" line
344 firstLine := firstNonEmptyLine(scanner)
345 if !strings.HasPrefix(firstLine, "system type") || !strings.Contains(firstLine, ":") {
346 return nil, fmt.Errorf("%w: %q", ErrFileParse, firstLine)
347 }
348 field := strings.SplitN(firstLine, ": ", 2)
349 cpuinfo := []CPUInfo{}
350 systemType := field[1]
351
352 i := 0
353
354 for scanner.Scan() {
355 line := scanner.Text()
356 if !strings.Contains(line, ":") {
357 continue
358 }
359 field := strings.SplitN(line, ": ", 2)
360 switch strings.TrimSpace(field[0]) {
361 case "processor":
362 v, err := strconv.ParseUint(field[1], 0, 32)
363 if err != nil {
364 return nil, err
365 }
366 i = int(v)
367 cpuinfo = append(cpuinfo, CPUInfo{}) // start of the next processor
368 cpuinfo[i].Processor = uint(v)
369 cpuinfo[i].VendorID = systemType
370 case "cpu model":
371 cpuinfo[i].ModelName = field[1]
372 case "BogoMIPS":
373 v, err := strconv.ParseFloat(field[1], 64)
374 if err != nil {
375 return nil, err
376 }
377 cpuinfo[i].BogoMips = v
378 }
379 }
380 return cpuinfo, nil
381}
382
383func parseCPUInfoLoong(info []byte) ([]CPUInfo, error) {
384 scanner := bufio.NewScanner(bytes.NewReader(info))

Callers 1

TestCPUInfoParseMipsFunction · 0.85

Calls 1

firstNonEmptyLineFunction · 0.85

Tested by 1

TestCPUInfoParseMipsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…