From 96e80aee6c484bba59f38415d1e4e4ff066e40f2 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 8 Oct 2025 16:07:13 +0000 Subject: [PATCH] proc: Use the new parser to parse PSI information Signed-off-by: Michael Tremer --- src/daemon/proc.c | 60 +++++++---------------------------------------- 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/src/daemon/proc.c b/src/daemon/proc.c index e8a6bd9..c8579ea 100644 --- a/src/daemon/proc.c +++ b/src/daemon/proc.c @@ -170,31 +170,9 @@ ERROR: 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 @@ -202,36 +180,16 @@ int collecty_proc_read_pressure(collecty_ctx* ctx, 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 { -- 2.47.3