pgbench-logging-v4.patch
text/plain
Filename: pgbench-logging-v4.patch
Type: text/plain
Part: 0
Message:
Re: too much pgbench init output
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v4
| File | + | − |
|---|---|---|
| contrib/pgbench/pgbench.c | 18 | 10 |
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 334ce4c..14d8ad5 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -39,6 +39,7 @@
#include "portability/instr_time.h"
#include <ctype.h>
+#include <math.h>
#ifndef WIN32
#include <sys/time.h>
@@ -102,6 +103,7 @@ extern int optind;
#define MAXCLIENTS 1024
#endif
+#define LOG_STEP_SECONDS 5 /* seconds between log messages */
#define DEFAULT_NXACTS 10 /* default nxacts */
int nxacts = 0; /* number of transactions per client */
@@ -135,11 +137,6 @@ int unlogged_tables = 0;
double sample_rate = 0.0;
/*
- * logging steps (seconds between log messages)
- */
-int log_step_seconds = 5;
-
-/*
* tablespace selection
*/
char *tablespace = NULL;
@@ -155,6 +152,7 @@ char *index_tablespace = NULL;
#define naccounts 100000
bool use_log; /* log transaction latencies to a file */
+bool use_quiet; /* quiet logging onto stderr */
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 */
@@ -394,6 +392,7 @@ usage(void)
" -v vacuum all four standard tables before tests\n"
"\nCommon options:\n"
" -d print debugging output\n"
+ " -q quiet logging (a message each 5 seconds)\n"
" -h HOSTNAME database server host or socket directory\n"
" -p PORT database server port number\n"
" -U USERNAME connect as specified database user\n"
@@ -1453,8 +1452,14 @@ init(bool is_no_vacuum)
exit(1);
}
+ /* If we want to stick with the original logging, print a message each
+ * 100k inserted rows. */
+ if ((! use_quiet) && (j % 100000 == 0))
+ fprintf(stderr, "%d of %d tuples (%d%%) done.\n",
+ j, naccounts * scale,
+ (int) (((int64) j * 100) / (naccounts * scale)));
/* let's not call the timing for each row, but only each 100 rows */
- if (j % 100 == 0 || j == scale * naccounts)
+ else if (use_quiet && (j % 100 == 0))
{
INSTR_TIME_SET_CURRENT(diff);
INSTR_TIME_SUBTRACT(diff, start);
@@ -1462,15 +1467,15 @@ init(bool is_no_vacuum)
elapsed_sec = INSTR_TIME_GET_DOUBLE(diff);
remaining_sec = (scale * naccounts - j) * elapsed_sec / j;
- /* have we reached the next interval? */
- if (elapsed_sec >= log_interval * log_step_seconds) {
+ /* have we reached the next interval (or end)? */
+ if ((j == scale * naccounts) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS)) {
fprintf(stderr, "%d of %d tuples (%d%%) done (elapsed %.2f s, remaining %.2f s).\n",
j, naccounts * scale,
(int) (((int64) j * 100) / (naccounts * scale)), elapsed_sec, remaining_sec);
/* skip to the next interval */
- log_interval = (int)ceil(elapsed_sec/log_step_seconds);
+ log_interval = (int)ceil(elapsed_sec/LOG_STEP_SECONDS);
}
}
@@ -2016,7 +2021,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:dSNc: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:", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -2124,6 +2129,9 @@ main(int argc, char **argv)
case 'l':
use_log = true;
break;
+ case 'q':
+ use_quiet = true;
+ break;
case 'f':
ttype = 3;
filename = pg_strdup(optarg);