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

Function parseCounterFile

bcachefs/get.go:327–367  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

325}
326
327func parseCounterFile(path string) (CounterStats, error) {
328 file, err := openIfExists(path)
329 if err != nil || file == nil {
330 return CounterStats{}, err
331 }
332 defer file.Close()
333
334 var stats CounterStats
335 var seenCreation bool
336 var seenMount bool
337
338 scanner := bufio.NewScanner(file)
339 for scanner.Scan() {
340 line := scanner.Text()
341 if valueStr, ok := strings.CutPrefix(line, "since mount:"); ok {
342 value, err := parseHumanReadableBytes(valueStr)
343 if err != nil {
344 return CounterStats{}, err
345 }
346 stats.SinceMount = value
347 seenMount = true
348 continue
349 }
350 if valueStr, ok := strings.CutPrefix(line, "since filesystem creation:"); ok {
351 value, err := parseHumanReadableBytes(valueStr)
352 if err != nil {
353 return CounterStats{}, err
354 }
355 stats.SinceFilesystemCreation = value
356 seenCreation = true
357 continue
358 }
359 }
360 if err := scanner.Err(); err != nil {
361 return CounterStats{}, err
362 }
363 if !seenCreation && !seenMount {
364 return CounterStats{}, fmt.Errorf("counter file format not recognized")
365 }
366 return stats, nil
367}
368
369func parseBtreeWriteStats(path string) (map[string]BtreeWriteStats, error) {
370 file, err := openIfExists(path)

Callers 2

parseCountersFunction · 0.85

Calls 3

openIfExistsFunction · 0.85
parseHumanReadableBytesFunction · 0.85
ErrMethod · 0.80

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…