[systemd-commits] src/libsystemd-bus

Lennart Poettering lennart at kemper.freedesktop.org
Tue Jun 4 02:53:17 PDT 2013


 src/libsystemd-bus/test-bus-kernel-benchmark.c |   37 +++++++++++++++++--------
 1 file changed, 26 insertions(+), 11 deletions(-)

New commits:
commit 061b2c43652570c067ca93391cec9940a24d474f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jun 3 19:44:44 2013 +0900

    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.

diff --git a/src/libsystemd-bus/test-bus-kernel-benchmark.c b/src/libsystemd-bus/test-bus-kernel-benchmark.c
index 0cf685e..01074dd 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);



More information about the systemd-commits mailing list