3939#include "portability/instr_time.h"
4040
4141#include <ctype.h>
42+ #include <math.h>
4243
4344#ifndef WIN32
4445#include <sys/time.h>
@@ -102,6 +103,7 @@ extern intoptind;
102103#define MAXCLIENTS 1024
103104#endif
104105
106+ #define LOG_STEP_SECONDS 5/* seconds between log messages */
105107#define DEFAULT_NXACTS 10/* default nxacts */
106108
107109int nxacts = 0 ;/* number of transactions per client */
@@ -150,6 +152,7 @@ char *index_tablespace = NULL;
150152#define naccounts 100000
151153
152154bool use_log ;/* log transaction latencies to a file */
155+ bool use_quiet ;/* quiet logging onto stderr */
153156bool is_connect ;/* establish connection for each transaction */
154157bool is_latencies ;/* report per-command latencies */
155158int main_pid ;/* main process id used in log filename */
@@ -359,6 +362,7 @@ usage(void)
359362" -n do not run VACUUM after initialization\n"
360363" -F NUM fill factor\n"
361364" -s NUM scaling factor\n"
365+ " -q quiet logging (one message each 5 seconds)\n"
362366" --foreign-keys\n"
363367" create foreign key constraints between tables\n"
364368" --index-tablespace=TABLESPACE\n"
@@ -1362,6 +1366,11 @@ init(bool is_no_vacuum)
13621366char sql [256 ];
13631367int i ;
13641368
1369+ /* used to track elapsed time and estimate of the remaining time */
1370+ instr_time start ,diff ;
1371+ double elapsed_sec ,remaining_sec ;
1372+ int log_interval = 1 ;
1373+
13651374if ((con = doConnect ())== NULL )
13661375exit (1 );
13671376
@@ -1430,6 +1439,8 @@ init(bool is_no_vacuum)
14301439}
14311440PQclear (res );
14321441
1442+ INSTR_TIME_SET_CURRENT (start );
1443+
14331444for (i = 0 ;i < naccounts * scale ;i ++ )
14341445{
14351446int j = i + 1 ;
@@ -1441,10 +1452,42 @@ init(bool is_no_vacuum)
14411452exit (1 );
14421453}
14431454
1444- if (j %100000 == 0 )
1445- fprintf (stderr ,"%d of %d tuples (%d%%) done.\n" ,
1446- j ,naccounts * scale ,
1447- (int ) (((int64 )j * 100 ) / (naccounts * scale )));
1455+ /* If we want to stick with the original logging, print a message each
1456+ * 100k inserted rows. */
1457+ if ((!use_quiet )&& (j %100000 == 0 ))
1458+ {
1459+ INSTR_TIME_SET_CURRENT (diff );
1460+ INSTR_TIME_SUBTRACT (diff ,start );
1461+
1462+ elapsed_sec = INSTR_TIME_GET_DOUBLE (diff );
1463+ remaining_sec = (scale * naccounts - j )* elapsed_sec /j ;
1464+
1465+ fprintf (stderr ,"%d of %d tuples (%d%%) done (elapsed %.2f s, remaining %.2f s).\n" ,
1466+ j ,naccounts * scale ,
1467+ (int ) (((int64 )j * 100 ) / (naccounts * scale )),
1468+ elapsed_sec ,remaining_sec );
1469+ }
1470+ /* let's not call the timing for each row, but only each 100 rows */
1471+ else if (use_quiet && (j %100 == 0 ))
1472+ {
1473+ INSTR_TIME_SET_CURRENT (diff );
1474+ INSTR_TIME_SUBTRACT (diff ,start );
1475+
1476+ elapsed_sec = INSTR_TIME_GET_DOUBLE (diff );
1477+ remaining_sec = (scale * naccounts - j )* elapsed_sec /j ;
1478+
1479+ /* have we reached the next interval (or end)? */
1480+ if ((j == scale * naccounts )|| (elapsed_sec >=log_interval * LOG_STEP_SECONDS )) {
1481+
1482+ fprintf (stderr ,"%d of %d tuples (%d%%) done (elapsed %.2f s, remaining %.2f s).\n" ,
1483+ j ,naccounts * scale ,
1484+ (int ) (((int64 )j * 100 ) / (naccounts * scale )),elapsed_sec ,remaining_sec );
1485+
1486+ /* skip to the next interval */
1487+ log_interval = (int )ceil (elapsed_sec /LOG_STEP_SECONDS );
1488+ }
1489+ }
1490+
14481491}
14491492if (PQputline (con ,"\\.\n" ))
14501493{
@@ -1987,7 +2030,7 @@ main(int argc, char **argv)
19872030state = (CState * )pg_malloc (sizeof (CState ));
19882031memset (state ,0 ,sizeof (CState ));
19892032
1990- while ((c = getopt_long (argc ,argv ,"ih:nvp:dSNc :j:Crs:t:T:U:lf:D:F:M:" ,long_options ,& optindex ))!= -1 )
2033+ while ((c = getopt_long (argc ,argv ,"ih:nvp:dqSNc :j:Crs:t:T:U:lf:D:F:M:" ,long_options ,& optindex ))!= -1 )
19912034{
19922035switch (c )
19932036{
@@ -2095,6 +2138,9 @@ main(int argc, char **argv)
20952138case 'l' :
20962139use_log = true;
20972140break ;
2141+ case 'q' :
2142+ use_quiet = true;
2143+ break ;
20982144case 'f' :
20992145ttype = 3 ;
21002146filename = pg_strdup (optarg );
@@ -2198,6 +2244,13 @@ main(int argc, char **argv)
21982244exit (1 );
21992245}
22002246
2247+ /* -q may be used only with -i */
2248+ if (use_quiet && !is_init_mode )
2249+ {
2250+ fprintf (stderr ,"quiet-logging is allowed only in initialization mode (-i)\n" );
2251+ exit (1 );
2252+ }
2253+
22012254/*
22022255 * is_latencies only works with multiple threads in thread-based
22032256 * implementations, not fork-based ones, because it supposes that the