// SPDX-License-Identifier: GPL-3.0-or-later // // This file is part of CProof. // See LICENSE for the full GPLv3 text and the special OpenSSL linking exception. #include "config.h" #include "bench_csv.h" #include #include #include #include #include "common.h" static char* _csv_clean(const char* in) { if (!in) return g_strdup(""); GString* s = g_string_sized_new(strlen(in)); for (const char* p = in; *p; p++) { if (*p == ',' || *p == '\n' || *p == '\r') g_string_append_c(s, ' '); else g_string_append_c(s, *p); } return g_string_free(s, FALSE); } void bench_csv_append(const char* path, const char* scenario, const char* volume, uint64_t bytes, uint64_t lines, double wall_ms, long peak_rss_kb, const char* note) { if (!path) return; struct stat st; int fresh = (stat(path, &st) != 0 || st.st_size == 0); FILE* fp = fopen(path, "a"); if (!fp) return; if (fresh) { fprintf(fp, "scenario,volume,bytes,lines,wall_ms,peak_rss_kb,note\n"); } auto_gchar gchar* sc = _csv_clean(scenario); auto_gchar gchar* vol = _csv_clean(volume); auto_gchar gchar* nt = _csv_clean(note); fprintf(fp, "%s,%s,%" G_GUINT64_FORMAT ",%" G_GUINT64_FORMAT ",%.3f,%ld,%s\n", sc, vol, bytes, lines, wall_ms, peak_rss_kb, nt); fclose(fp); }