From 5233a3cdb46564d95b073631c9331a5c58e0baf0 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Wed, 30 Oct 2019 17:12:46 +0300 Subject: [PATCH] mdbx-test: add resource usage (CPU time). Change-Id: I96b9bc9e748186ef122c809386ec3f52259d3b33 --- test/main.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/main.cc b/test/main.cc index 8089b69f..1e2465ab 100644 --- a/test/main.cc +++ b/test/main.cc @@ -14,6 +14,11 @@ #include "test.h" +#if !(defined(_WIN32) || defined(_WIN64)) +#include +#include +#endif /* !Windows */ + void __noreturn usage(void) { printf("usage:\n" "\tFIXME\n"); @@ -494,5 +499,25 @@ int main(int argc, char *const argv[]) { else cleanup(); } + +#if !(defined(_WIN32) || defined(_WIN64)) + struct rusage spent; + if (getrusage(RUSAGE_CHILDREN, &spent) == 0) { + log_notice("%6s: user %f, system %f", "CPU", + spent.ru_utime.tv_sec + spent.ru_utime.tv_usec * 1e-6, + spent.ru_stime.tv_sec + spent.ru_stime.tv_usec * 1e-6); +#if defined(__linux__) || defined(__gnu_linux__) || defined(__FreeBSD__) || \ + defined(__NetBSD__) || defined(__OpenBSD__) || defined(__BSD__) || \ + defined(__NETBSD__) || defined(__bsdi__) || defined(__DragonFly__) || \ + defined(__APPLE__) || defined(__MACH__) + log_notice("%6s: read %ld, write %ld", "IOPs", spent.ru_inblock, + spent.ru_oublock); + log_notice("%6s: %ld Kb", "RAM", spent.ru_maxrss); + log_notice("%6s: reclaims %ld, faults %ld, swaps %ld", "Paging", + spent.ru_minflt, spent.ru_majflt, spent.ru_nswap); +#endif /* Linux */ + } +#endif /* !Windows */ + return failed ? EXIT_FAILURE : EXIT_SUCCESS; }