(path string)
| 325 | } |
| 326 | |
| 327 | func 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 | |
| 369 | func parseBtreeWriteStats(path string) (map[string]BtreeWriteStats, error) { |
| 370 | file, err := openIfExists(path) |
searching dependent graphs…