return r;
}
-static int collecty_proc_read_pressure_line(collecty_ctx* ctx,
- const char* line, collecty_pressure_stats* stats) {
- int r;
-
- // Try parsing the some line
- r = sscanf(line, "some avg10=%lf avg60=%lf avg300=%lf total=%lu\n",
- &stats->some.avg10, &stats->some.avg60, &stats->some.avg300, &stats->some.total);
- if (r)
- return r;
-
- // Try parsing the full line
- r = sscanf(line, "full avg10=%lf avg60=%lf avg300=%lf total=%lu\n",
- &stats->full.avg10, &stats->full.avg60, &stats->full.avg300, &stats->full.total);
- if (r)
- return r;
-
- return 0;
-}
-
int collecty_proc_read_pressure(collecty_ctx* ctx,
const char* what, collecty_pressure_stats* stats) {
char path[PATH_MAX];
- char* line = NULL;
- size_t length = 0;
- FILE* f = NULL;
int r;
// Make the path
if (r < 0)
return -errno;
- // Open the file
- f = fopen(path, "r");
- if (!f) {
- ERROR(ctx, "Failed to open %s: %m\n", path);
- r = -errno;
- goto ERROR;
- }
-
- // Walk through all lines
- for (;;) {
- r = getline(&line, &length, f);
- if (r < 0)
- break;
-
- // Process the line
- r = collecty_proc_read_pressure_line(ctx, line, stats);
- if (r < 0)
- goto ERROR;
- }
-
- // Reset r
- r = 0;
-
-ERROR:
- if (line)
- free(line);
- if (f)
- fclose(f);
+ collecty_file_parser parser[] = {
+ PARSE4("some avg10=%lf avg60=%lf avg300=%lf total=%lu\n",
+ &stats->some.avg10, &stats->some.avg60, &stats->some.avg300, &stats->some.total),
+ PARSE4("full avg10=%lf avg60=%lf avg300=%lf total=%lu\n",
+ &stats->full.avg10, &stats->full.avg60, &stats->full.avg300, &stats->full.total),
+ { NULL },
+ };
- return r;
+ // Run the parser
+ return collecty_parse(ctx, path, parser);
}
typedef struct collecty_proc_softirq_state {