// 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. #ifndef BENCH_COMMON_H #define BENCH_COMMON_H #include #include #include #include // Wall-clock monotonic milliseconds since some epoch. Use for elapsed-time // arithmetic only (subtract two values). double bench_now_ms(void); // Format a byte count as "1.23 GB" / "500 MB" / "42 KB" / "9 B". // Returns a freshly allocated string; caller must g_free. char* bench_fmt_bytes(uint64_t bytes); // Format a duration in milliseconds as a human-friendly string. char* bench_fmt_ms(double ms); // Resolve BENCH_VOLUME env: "small" / "medium" / "max" / unset. typedef enum { BENCH_VOLUME_SMALL, // 10k lines / 1 contact / 1 year BENCH_VOLUME_MEDIUM, // 500k lines / 1 contact / 5 years BENCH_VOLUME_MAX, // 5M lines / 1 contact / 10 years } bench_volume_t; bench_volume_t bench_volume_from_env(void); const char* bench_volume_name(bench_volume_t v); // Drop OS page cache for a path (so a subsequent read measures cold I/O). // On Linux this is best-effort: we open the file, posix_fadvise(DONTNEED). // Returns TRUE on success. gboolean bench_drop_page_cache(const char* path); // Available bytes in the filesystem hosting `path`. Returns -1 on failure. int64_t bench_fs_free_bytes(const char* path); // Best-of-N timing: run `fn(arg)` `runs` times, return the minimum elapsed-ms. // Optionally records peak RSS over runs into *peak_rss_kb. typedef void (*bench_fn_t)(void* arg); double bench_run_best_of(int runs, bench_fn_t fn, void* arg, long* peak_rss_kb); // Get current peak RSS in KB via getrusage(). long bench_peak_rss_kb(void); #endif