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

Function parseCPUInfoPPC

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

Source from the content-addressed store, hash-verified

417}
418
419func parseCPUInfoPPC(info []byte) ([]CPUInfo, error) {
420 scanner := bufio.NewScanner(bytes.NewReader(info))
421
422 firstLine := firstNonEmptyLine(scanner)
423 if !strings.HasPrefix(firstLine, "processor") || !strings.Contains(firstLine, ":") {
424 return nil, fmt.Errorf("%w: %q", ErrFileParse, firstLine)
425 }
426 field := strings.SplitN(firstLine, ": ", 2)
427 v, err := strconv.ParseUint(field[1], 0, 32)
428 if err != nil {
429 return nil, err
430 }
431 firstcpu := CPUInfo{Processor: uint(v)}
432 cpuinfo := []CPUInfo{firstcpu}
433 i := 0
434
435 for scanner.Scan() {
436 line := scanner.Text()
437 if !strings.Contains(line, ":") {
438 continue
439 }
440 field := strings.SplitN(line, ": ", 2)
441 switch strings.TrimSpace(field[0]) {
442 case "processor":
443 cpuinfo = append(cpuinfo, CPUInfo{}) // start of the next processor
444 i++
445 v, err := strconv.ParseUint(field[1], 0, 32)
446 if err != nil {
447 return nil, err
448 }
449 cpuinfo[i].Processor = uint(v)
450 case "cpu":
451 cpuinfo[i].VendorID = field[1]
452 case "clock":
453 clock := cpuinfoClockRegexp.FindString(strings.TrimSpace(field[1]))
454 v, err := strconv.ParseFloat(clock, 64)
455 if err != nil {
456 return nil, err
457 }
458 cpuinfo[i].CPUMHz = v
459 }
460 }
461 return cpuinfo, nil
462}
463
464func parseCPUInfoRISCV(info []byte) ([]CPUInfo, error) {
465 scanner := bufio.NewScanner(bytes.NewReader(info))

Callers 1

TestCPUInfoParsePPCFunction · 0.85

Calls 1

firstNonEmptyLineFunction · 0.85

Tested by 1

TestCPUInfoParsePPCFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…