bench: Allow backend method selection

-l         list available methods
-m <name>  use method

(cherry picked from commit 5caffa7a5b3ce67e074e2ee99fc553c1cac0712c)
This commit is contained in:
Nick Grifka 2020-04-16 12:08:02 -07:00 committed by Azat Khuzhin
parent 9ed49f2d64
commit 1fce771dc8

View 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