diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 1303217..32805ea 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -164,6 +164,7 @@ bool use_log; /* log transaction latencies to a file */ bool use_quiet; /* quiet logging onto stderr */ int agg_interval; /* log aggregates instead of individual * transactions */ +int progress = 0; /* thread progress report every this seconds */ bool is_connect; /* establish connection for each transaction */ bool is_latencies; /* report per-command latencies */ int main_pid; /* main process id used in log filename */ @@ -354,6 +355,8 @@ usage(void) " protocol for submitting queries to server (default: simple)\n" " -n do not run VACUUM before tests\n" " -N do not update tables \"pgbench_tellers\" and \"pgbench_branches\"\n" + " -P NUM, --progress NUM\n" + " show thread progress report about every NUM seconds\n" " -r report average latency per command\n" " -s NUM report this scale factor in output\n" " -S perform SELECT-only transactions\n" @@ -2115,6 +2118,7 @@ main(int argc, char **argv) {"unlogged-tables", no_argument, &unlogged_tables, 1}, {"sampling-rate", required_argument, NULL, 4}, {"aggregate-interval", required_argument, NULL, 5}, + {"progress", required_argument, NULL, 'P'}, {NULL, 0, NULL, 0} }; @@ -2181,7 +2185,7 @@ main(int argc, char **argv) state = (CState *) pg_malloc(sizeof(CState)); memset(state, 0, sizeof(CState)); - while ((c = getopt_long(argc, argv, "ih:nvp:dqSNc:j:Crs:t:T:U:lf:D:F:M:", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "ih:nvp:dqSNc:j:Crs:t:T:U:lf:D:F:M:P:", long_options, &optindex)) != -1) { switch (c) { @@ -2336,6 +2340,16 @@ main(int argc, char **argv) exit(1); } break; + case 'P': + progress = atoi(optarg); + if (progress <= 0) + { + fprintf(stderr, + "thread progress delay (-P) must not be negative (%s)\n", + optarg); + exit(1); + } + break; case 0: /* This covers long options which take no argument. */ break; @@ -2712,6 +2726,10 @@ threadRun(void *arg) int nstate = thread->nstate; int remains = nstate; /* number of remaining clients */ int i; + /* for reporting progress in benchmark result */ + int64 start_report = INSTR_TIME_GET_MICROSEC(thread->start_time); + int64 last_report = start_report; + int64 last_count = 0; AggVals aggs; @@ -2875,6 +2893,32 @@ threadRun(void *arg) st->con = NULL; } } + + /* per thread progress report, about every specified seconds */ + if (progress) + { + instr_time now_time; + int64 now, run; + INSTR_TIME_SET_CURRENT(now_time); + now = INSTR_TIME_GET_MICROSEC(now_time); + run = now - last_report; + if (run >= progress * 1000000) + { + /* generate and show report */ + int64 count = 0; + double tps; + + for (i=0; itid, tps, (long double) (1.0 / tps) + ); + last_count = count; + last_report = now; + } + } } done: diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml index 8775606..5d633d4 100644 --- a/doc/src/sgml/pgbench.sgml +++ b/doc/src/sgml/pgbench.sgml @@ -392,6 +392,16 @@ pgbench options dbname + seconds + seconds + + + Show thread progress report about every specified seconds. + + + + + scale_factor