X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fbenchmark.c;h=3b00f130a2275ce24ef72a90cf33215503c924b0;hp=71deae8042cd9338c07d5e6ca6bca29b889d846c;hb=dc86a5103817732735d2591d3775114a86de94ae;hpb=b0663a3c3827d354e197fa9b8d42526bd3785cdd diff --git a/util/benchmark.c b/util/benchmark.c index 71deae8..3b00f13 100644 --- a/util/benchmark.c +++ b/util/benchmark.c @@ -1,75 +1,142 @@ -/* $Id: benchmark.c,v 1.3 2004-01-07 20:33:57 adam Exp $ - * Copyright (C) 2003-2004 Index Data Aps - * - * This file is part of the YAZ toolkit. - * - * See the file LICENSE. - * - * This is an elementary benchmarker for server performance. It works - * by repeatedly connecting to, seaching in and retrieving from the - * specified server, and keeps statistics about the minimum, maximum - * and average times for each operation. +/* This file is part of the YAZ toolkit. + * Copyright (C) Index Data + * See the file LICENSE for details. */ +#if HAVE_CONFIG_H +#include +#endif #include #include #include +#include +#include #include -struct options { - int nconnect; /* number of connections to make */ - int nsearch; /* number of searches on each connection */ - int npresent; /* number of presents for each search */ - int full; /* 1 = fetch full records, 0 = brief */ - int delay; /* number of ms to delay between ops */ - int random; /* if true, delay is random 0-specified */ -} options = { +struct boptions { + int nconnect; /* number of connections to make */ + int nsearch; /* number of searches on each connection */ + int npresent; /* number of presents for each search */ + int full; /* 1 = fetch full records, 0 = brief */ + int delay; /* number of ms to delay between ops */ + int random; /* if true, delay is random 0-specified */ + int verbosity; /* 0 = quiet, higher => more verbose */ +} boptions = { 3, 3, 3, 0, 1000, 1, + 0, }; +static int test(char *host, int port); +static void db_printf(int level, char *fmt, ...); +static void usage(const char *prog); + int main(int argc, char **argv) { - char *host; - int port; + char *host = 0; + int port = 0; int c; + int i; + int ok; + int nok = 0; + char *arg; - while ((c = getopt(argc, argv, "c:s:p:fbd:r")) != -1) { - switch (c) { - case 'c': options.nconnect = atoi(optarg); break; - case 's': options.nsearch = atoi(optarg); break; - case 'p': options.npresent = atoi(optarg); break; - case 'f': options.full = 1; break; - case 'b': options.full = 0; break; - case 'd': options.delay = atoi(optarg); break; - case 'r': options.random = 1; break; - default: goto USAGE; - } + while ((c = options("c:s:p:fbd:rv:", argv, argc, &arg)) != -2) { + switch (c) { + case 0: + if (!host) + host = arg; + else if (!port) + port = atoi(arg); + else + usage(*argv); + break; + case 'c': boptions.nconnect = atoi(arg); break; + case 's': boptions.nsearch = atoi(arg); break; + case 'p': boptions.npresent = atoi(arg); break; + case 'f': boptions.full = 1; break; + case 'b': boptions.full = 0; break; + case 'd': boptions.delay = atoi(arg); break; + case 'r': boptions.random = 1; break; + case 'v': boptions.verbosity = atoi(arg); break; + default: usage(*argv); + } } - if (argc-optind != 2) { - USAGE: - fprintf(stderr, "Usage: %s [options] \n" -" -c Make connection to the server [default: 3]\n" -" -s Perform searches on each connection [3]\n" -" -p Make present requests after each search [3]\n" -" -f Fetch full records [default: brief]\n" -" -b Fetch brief records\n" -" -d Delay ms after each operation\n" -" -r Delays are random between 0 and the specified number of ms\n" -, argv[0]); - return 1; + if (!host || !port) + usage(*argv); + + for (i = 0; i < boptions.nconnect; i++) { + db_printf(2, "iteration %d of %d", i+1, boptions.nconnect); + ok = test(host, port); + if (ok) nok++; } - host = argv[optind]; - port = atoi(argv[optind+1]); + db_printf(1, "passed %d of %d tests", nok, boptions.nconnect); + if (nok < boptions.nconnect) + printf("Failed %d of %d tests\n", + boptions.nconnect-nok, boptions.nconnect); return 0; } + +static void usage(const char *prog) +{ + fprintf(stderr, "Usage: %s [options] \n" +" -c Make connection to the server [default: 3]\n" +" -s Perform searches on each connection [3]\n" +" -p Make present requests after each search [3]\n" +" -f Fetch full records [default: brief]\n" +" -b Fetch brief records\n" +" -d Delay ms after each operation\n" +" -r Delays are random between 0 and the specified number of ms\n" +" -v Set verbosity level to [0, silent on success]\n" + , prog); + exit(1); +} + +static int test(char *host, int port) +{ + ZOOM_connection conn; + int error; + const char *errmsg, *addinfo; + + conn = ZOOM_connection_new(host, port); + if ((error = ZOOM_connection_error(conn, &errmsg, &addinfo))) { + fprintf(stderr, "ZOOM error: %s (%d): %s\n", errmsg, error, addinfo); + return 0; + } + + ZOOM_connection_destroy(conn); + return 1; +} + +static void db_printf(int level, char *fmt, ...) +{ + va_list ap; + + if (level > boptions.verbosity) + return; + + fprintf(stderr, "DEBUG(%d): ", level); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fputc('\n', stderr); + va_end(ap); +} +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +