MCPcopy Index your code
hub / github.com/containerd/containerd / readKVStatsFile

Function readKVStatsFile

internal/oom/utils.go:79–95  ·  view source on GitHub ↗

readKVStatsFile is copied from cgroupsv2 package TODO(fuweid): we should export some helper functions like MemoryEvents(cgroupPath) directly.

(path string, file string, out map[string]uint64)

Source from the content-addressed store, hash-verified

77//
78// we should export some helper functions like MemoryEvents(cgroupPath) directly.
79func readKVStatsFile(path string, file string, out map[string]uint64) error {
80 f, err := os.Open(filepath.Join(path, file))
81 if err != nil {
82 return err
83 }
84 defer f.Close()
85
86 s := bufio.NewScanner(f)
87 for s.Scan() {
88 name, value, err := parseKV(s.Text())
89 if err != nil {
90 return fmt.Errorf("error while parsing %s (line=%q): %w", filepath.Join(path, file), s.Text(), err)
91 }
92 out[name] = value
93 }
94 return s.Err()
95}
96
97func parseKV(raw string) (string, uint64, error) {
98 parts := strings.Fields(raw)

Callers 1

startMethod · 0.85

Calls 4

parseKVFunction · 0.85
CloseMethod · 0.65
ErrMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…