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)
| 77 | // |
| 78 | // we should export some helper functions like MemoryEvents(cgroupPath) directly. |
| 79 | func 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 | |
| 97 | func parseKV(raw string) (string, uint64, error) { |
| 98 | parts := strings.Fields(raw) |