]> granicus.if.org Git - libevent/commitdiff
bench: Allow backend method selection
authorNick Grifka <nigri@microsoft.com>
Thu, 16 Apr 2020 19:08:02 +0000 (12:08 -0700)
committerNick Grifka <nigri@microsoft.com>
Mon, 27 Apr 2020 17:03:28 +0000 (10:03 -0700)
-l         list available methods
-m <name>  use method

test/bench.c

index 3a6886dba69c44cbc355e8202ce06dd83690eb3b..f2af4d3f30d1ff3703fd574b8014f7cef1f344a6 100644 (file)
@@ -70,6 +70,7 @@ static int writes, failures;
 static evutil_socket_t *pipes;
 static int num_pipes, num_active, num_writes;
 static struct event *events;
+static struct event_base *base;
 
 
 static void
@@ -105,11 +106,11 @@ run_once(void)
        for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
                if (event_initialized(&events[i]))
                        event_del(&events[i]);
-               event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *)(ev_intptr_t) i);
+               event_assign(&events[i], base, cp[0], EV_READ | EV_PERSIST, read_cb, (void *)(ev_intptr_t) i);
                event_add(&events[i], NULL);
        }
 
-       event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
+       event_base_loop(base, EVLOOP_ONCE | EVLOOP_NONBLOCK);
 
        fired = 0;
        space = num_pipes / num_active;
@@ -123,7 +124,7 @@ run_once(void)
                int xcount = 0;
                evutil_gettimeofday(&ts, NULL);
                do {
-                       event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
+                       event_base_loop(base, EVLOOP_ONCE | EVLOOP_NONBLOCK);
                        xcount++;
                } while (count != fired);
                evutil_gettimeofday(&te, NULL);
@@ -147,6 +148,9 @@ main(int argc, char **argv)
        int i, c;
        struct timeval *tv;
        evutil_socket_t *cp;
+       const char **methods;
+       const char *method = NULL;
+       struct event_config *cfg = NULL;
 
 #ifdef _WIN32
        WSADATA WSAData;
@@ -155,7 +159,7 @@ main(int argc, char **argv)
        num_pipes = 100;
        num_active = 1;
        num_writes = num_pipes;
-       while ((c = getopt(argc, argv, "n:a:w:")) != -1) {
+       while ((c = getopt(argc, argv, "n:a:w:m:l")) != -1) {
                switch (c) {
                case 'n':
                        num_pipes = atoi(optarg);
@@ -166,6 +170,16 @@ main(int argc, char **argv)
                case 'w':
                        num_writes = atoi(optarg);
                        break;
+               case 'm':
+                       method = optarg;
+                       break;
+               case 'l':
+                       methods = event_get_supported_methods();
+                       fprintf(stdout, "Using Libevent %s. Available methods are:\n",
+                               event_get_version());
+                       for (i = 0; methods[i] != NULL; ++i)
+                               printf("    %s\n", methods[i]);
+                       exit(0);
                default:
                        fprintf(stderr, "Illegal argument \"%c\"\n", c);
                        exit(1);
@@ -187,7 +201,16 @@ main(int argc, char **argv)
                exit(1);
        }
 
-       event_init();
+       if (method != NULL) {
+               cfg = event_config_new();
+               methods = event_get_supported_methods();
+               for (i = 0; methods[i] != NULL; ++i)
+                       if (strcmp(methods[i], method))
+                               event_config_avoid_method(cfg, methods[i]);
+               base = event_base_new_with_config(cfg);
+               event_config_free(cfg);
+       } else
+               base = event_base_new();
 
        for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
 #ifdef USE_PIPES