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

Function parseCPUInfoRISCV

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

Source from the content-addressed store, hash-verified

462}
463
464func parseCPUInfoRISCV(info []byte) ([]CPUInfo, error) {
465 scanner := bufio.NewScanner(bytes.NewReader(info))
466
467 firstLine := firstNonEmptyLine(scanner)
468 if !strings.HasPrefix(firstLine, "processor") || !strings.Contains(firstLine, ":") {
469 return nil, fmt.Errorf("%w: %q", ErrFileParse, firstLine)
470 }
471 field := strings.SplitN(firstLine, ": ", 2)
472 v, err := strconv.ParseUint(field[1], 0, 32)
473 if err != nil {
474 return nil, err
475 }
476 firstcpu := CPUInfo{Processor: uint(v)}
477 cpuinfo := []CPUInfo{firstcpu}
478 i := 0
479
480 for scanner.Scan() {
481 line := scanner.Text()
482 if !strings.Contains(line, ":") {
483 continue
484 }
485 field := strings.SplitN(line, ": ", 2)
486 switch strings.TrimSpace(field[0]) {
487 case "processor":
488 v, err := strconv.ParseUint(field[1], 0, 32)
489 if err != nil {
490 return nil, err
491 }
492 i = int(v)
493 cpuinfo = append(cpuinfo, CPUInfo{}) // start of the next processor
494 cpuinfo[i].Processor = uint(v)
495 case "hart":
496 cpuinfo[i].CoreID = field[1]
497 case "isa":
498 cpuinfo[i].ModelName = field[1]
499 }
500 }
501 return cpuinfo, nil
502}
503
504func parseCPUInfoDummy(_ []byte) ([]CPUInfo, error) { //nolint:unused
505 return nil, errors.New("not implemented")

Callers 1

TestCPUInfoParseRISCV64Function · 0.85

Calls 1

firstNonEmptyLineFunction · 0.85

Tested by 1

TestCPUInfoParseRISCV64Function · 0.68