From 061b2c43652570c067ca93391cec9940a24d474f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 3 Jun 2013 19:44:44 +0900 Subject: [PATCH] test: determine number of transactions per second rather than time per transaction This way the measurements are not skewed by twoo short total measurement times, and results become stabler. --- .../test-bus-kernel-benchmark.c | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/libsystemd-bus/test-bus-kernel-benchmark.c b/src/libsystemd-bus/test-bus-kernel-benchmark.c index 0cf685e6d..01074dd4f 100644 --- a/src/libsystemd-bus/test-bus-kernel-benchmark.c +++ b/src/libsystemd-bus/test-bus-kernel-benchmark.c @@ -24,6 +24,7 @@ #include "util.h" #include "log.h" +#include "time-util.h" #include "sd-bus.h" #include "bus-message.h" @@ -31,9 +32,10 @@ #include "bus-kernel.h" #include "bus-internal.h" -#define N_TRIES 10000 #define MAX_SIZE (1*1024*1024) +static usec_t arg_loop_usec = 10 * USEC_PER_SEC; + static void server(sd_bus *b, size_t *result) { int r; @@ -107,8 +109,8 @@ static void client(const char *address) { rsize = MAX_SIZE; for (;;) { - usec_t copy, memfd, t; - unsigned i; + usec_t t; + unsigned n_copying, n_memfd; csize = (lsize + rsize) / 2; @@ -122,24 +124,32 @@ static void client(const char *address) { log_info("copying..."); b->use_memfd = 0; + t = now(CLOCK_MONOTONIC); - for (i = 0; i < N_TRIES; i++) + for (n_copying = 0;; n_copying++) { transaction(b, csize); - copy = (now(CLOCK_MONOTONIC) - t); - log_info("%llu usec per copy transaction", (unsigned long long) (copy / N_TRIES)); + if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec) + break; + } + + log_info("%u copy transactions per second", (unsigned) ((n_copying * USEC_PER_SEC) / arg_loop_usec)); log_info("sending memfd..."); b->use_memfd = -1; + t = now(CLOCK_MONOTONIC); - for (i = 0; i < N_TRIES; i++) + for (n_memfd = 0;; n_memfd++) { transaction(b, csize); - memfd = (now(CLOCK_MONOTONIC) - t); - log_info("%llu usec per memfd transaction", (unsigned long long) (memfd / N_TRIES)); + if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec) + break; + } - if (copy == memfd) + log_info("%u memfd transactions per second", (unsigned) ((n_memfd * USEC_PER_SEC) / arg_loop_usec)); + + if (n_copying == n_memfd) break; - if (copy < memfd) + if (n_copying > n_memfd) lsize = csize; else rsize = csize; @@ -163,6 +173,11 @@ int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); + if (argc > 1) + assert_se(parse_sec(argv[1], &arg_loop_usec) >= 0); + + assert_se(arg_loop_usec > 0); + bus_ref = bus_kernel_create("deine-mutter", &bus_name); if (bus_ref == -ENOENT) exit(EXIT_TEST_SKIP); -- 2.30.2