diff --git a/contrib/pgbench/README.pgbench b/contrib/pgbench/README.pgbench index 2afd4db25e..b8572319e1 100644 --- a/contrib/pgbench/README.pgbench +++ b/contrib/pgbench/README.pgbench @@ -1,4 +1,4 @@ -$PostgreSQL: pgsql/contrib/pgbench/README.pgbench,v 1.19 2007/07/06 13:36:55 wieck Exp $ +$PostgreSQL: pgsql/contrib/pgbench/README.pgbench,v 1.20 2007/07/06 20:17:02 wieck Exp $ pgbench README @@ -231,15 +231,15 @@ o -f option Variables can also be defined by using -D option. - \usleep usec + \sleep num [us|ms|s] - causes script execution to sleep for the specified duration in - microseconds. + causes script execution to sleep for the specified duration of + microseconds (us), milliseconds (ms) or the default seconds (s). example: - \setrandom usec 1000000 3000000 - \usleep :usec + \setrandom millisec 1000 2500 + \sleep :millisec ms Example, TPC-B like benchmark can be defined as follows(scaling factor = 1): diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 77d3a735d0..ae8bfaa167 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.67 2007/07/06 13:36:55 wieck Exp $ + * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.68 2007/07/06 20:17:02 wieck Exp $ * * pgbench: a simple benchmark program for PostgreSQL * written by Tatsuo Ishii @@ -727,7 +727,7 @@ top: st->listen = 1; } - else if (pg_strcasecmp(argv[0], "usleep") == 0) + else if (pg_strcasecmp(argv[0], "sleep") == 0) { char *var; int usec; @@ -746,6 +746,16 @@ top: else usec = atoi(argv[1]); + if (argc > 2) + { + if (pg_strcasecmp(argv[2], "ms") == 0) + usec *= 1000; + else if (pg_strcasecmp(argv[2], "s") == 0) + usec *= 1000000; + } + else + usec *= 1000000; + gettimeofday(&now, NULL); st->until.tv_sec = now.tv_sec + (now.tv_usec + usec) / 1000000; st->until.tv_usec = (now.tv_usec + usec) % 1000000; @@ -963,7 +973,7 @@ process_commands(char *buf) fprintf(stderr, "%s: extra argument \"%s\" ignored\n", my_commands->argv[0], my_commands->argv[j]); } - else if (pg_strcasecmp(my_commands->argv[0], "usleep") == 0) + else if (pg_strcasecmp(my_commands->argv[0], "sleep") == 0) { if (my_commands->argc < 2) { @@ -971,7 +981,19 @@ process_commands(char *buf) return NULL; } - for (j = 2; j < my_commands->argc; j++) + if (my_commands->argc >= 3) + { + if (pg_strcasecmp(my_commands->argv[2], "us") != 0 && + pg_strcasecmp(my_commands->argv[2], "ms") != 0 && + pg_strcasecmp(my_commands->argv[2], "s")) + { + fprintf(stderr, "%s: unknown time unit '%s' - must be us, ms or s\n", + my_commands->argv[0], my_commands->argv[2]); + return NULL; + } + } + + for (j = 3; j < my_commands->argc; j++) fprintf(stderr, "%s: extra argument \"%s\" ignored\n", my_commands->argv[0], my_commands->argv[j]); }