New submission which put option help in alphabetical position, as
per Peter Eisentraut f0ed3a8a99b052d2d5e0b6153a8907b90c486636

This is for reference to the next commitfest.

Patch update after conflict induced by pg-indentation, for the next commitfest.

--
Fabien.
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 8ff6623..c583f39 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 SEC, --progress SEC\n"
+		   "               show thread progress report about every SEC seconds\n"
 		   "  -r           report average latency per command\n"
 		   "  -s NUM       report this scale factor in output\n"
 		   "  -S           perform SELECT-only transactions\n"
@@ -2112,6 +2115,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}
 	};
 
@@ -2178,7 +2182,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)
 		{
@@ -2333,6 +2337,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;
@@ -2695,6 +2709,9 @@ threadRun(void *arg)
 	int			nstate = thread->nstate;
 	int			remains = nstate;		/* number of remaining clients */
 	int			i;
+	/* for reporting progress: */
+	int64		last_report = INSTR_TIME_GET_MICROSEC(thread->start_time);
+	int64		last_count = 0;
 
 	AggVals		aggs;
 
@@ -2858,6 +2875,29 @@ threadRun(void *arg)
 				st->con = NULL;
 			}
 		}
+
+		/* per thread progress report, about every 5s */
+		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;
+				for (i=0; i<nstate; i++)
+					count += state[i].cnt;
+				fprintf(stderr, "thread %d running at %f tps after %.1f s\n",
+						thread->tid, 1000000.0 * (count-last_count) / run,
+						(now - INSTR_TIME_GET_MICROSEC(thread->start_time))/
+						1000000.0);
+				last_count = count;
+				last_report = now;
+			}
+		}
 	}
 
 done:
diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml
index e9900d3..e58ea58 100644
--- a/doc/src/sgml/pgbench.sgml
+++ b/doc/src/sgml/pgbench.sgml
@@ -392,6 +392,16 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
      </varlistentry>
 
      <varlistentry>
+      <term><option>-P</option> <replaceable>sec</></term>
+      <term><option>--progress</option> <replaceable>sec</></term>
+      <listitem>
+       <para>
+	Show thread progress report about every <literal>sec</> seconds.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-s</option> <replaceable>scale_factor</></term>
       <listitem>
        <para>
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to