Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ce8f946

Browse files
committed
Report the time taken by pgbench initialization steps.
Author: Fabien Coelho Reviewed-by: Ibrar Ahmed Discussion: https://postgr.es/m/alpine.DEB.2.21.1904061810510.3678%40lancre
1 parent bfdbac2 commit ce8f946

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/bin/pgbench/pgbench.c

+37-1
Original file line numberDiff line numberDiff line change
@@ -3931,32 +3931,48 @@ checkInitSteps(const char *initialize_steps)
39313931
static void
39323932
runInitSteps(const char *initialize_steps)
39333933
{
3934+
PQExpBufferData stats;
39343935
PGconn *con;
39353936
const char *step;
3937+
double run_time = 0.0;
3938+
bool first = true;
3939+
3940+
initPQExpBuffer(&stats);
39363941

39373942
if ((con = doConnect()) == NULL)
39383943
exit(1);
39393944

39403945
for (step = initialize_steps; *step != '\0'; step++)
39413946
{
3947+
instr_time start;
3948+
char *op = NULL;
3949+
3950+
INSTR_TIME_SET_CURRENT(start);
3951+
39423952
switch (*step)
39433953
{
39443954
case 'd':
3955+
op = "drop tables";
39453956
initDropTables(con);
39463957
break;
39473958
case 't':
3959+
op = "create tables";
39483960
initCreateTables(con);
39493961
break;
39503962
case 'g':
3963+
op = "generate";
39513964
initGenerateData(con);
39523965
break;
39533966
case 'v':
3967+
op = "vacuum";
39543968
initVacuum(con);
39553969
break;
39563970
case 'p':
3971+
op = "primary keys";
39573972
initCreatePKeys(con);
39583973
break;
39593974
case 'f':
3975+
op = "foreign keys";
39603976
initCreateFKeys(con);
39613977
break;
39623978
case ' ':
@@ -3967,10 +3983,30 @@ runInitSteps(const char *initialize_steps)
39673983
PQfinish(con);
39683984
exit(1);
39693985
}
3986+
3987+
if (op != NULL)
3988+
{
3989+
instr_time diff;
3990+
double elapsed_sec;
3991+
3992+
INSTR_TIME_SET_CURRENT(diff);
3993+
INSTR_TIME_SUBTRACT(diff, start);
3994+
elapsed_sec = INSTR_TIME_GET_DOUBLE(diff);
3995+
3996+
if (!first)
3997+
appendPQExpBufferStr(&stats, ", ");
3998+
else
3999+
first = false;
4000+
4001+
appendPQExpBuffer(&stats, "%s %.2f s", op, elapsed_sec);
4002+
4003+
run_time += elapsed_sec;
4004+
}
39704005
}
39714006

3972-
fprintf(stderr, "done.\n");
4007+
fprintf(stderr, "done in %.2f s (%s).\n", run_time, stats.data);
39734008
PQfinish(con);
4009+
termPQExpBuffer(&stats);
39744010
}
39754011

39764012
/*

src/bin/pgbench/t/001_pgbench_with_server.pl

+5-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ sub pgbench
9494
[qr{^$}],
9595
[
9696
qr{creating tables}, qr{vacuuming},
97-
qr{creating primary keys}, qr{done\.}
97+
qr{creating primary keys}, qr{done in \d+\.\d\d s }
9898
],
9999
'pgbench scale 1 initialization',);
100100

@@ -109,7 +109,8 @@ sub pgbench
109109
qr{vacuuming},
110110
qr{creating primary keys},
111111
qr{creating foreign keys},
112-
qr{done\.}
112+
qr{(?!vacuuming)}, # no vacuum
113+
qr{done in \d+\.\d\d s }
113114
],
114115
'pgbench scale 1 initialization');
115116

@@ -124,7 +125,8 @@ sub pgbench
124125
qr{creating primary keys},
125126
qr{.* of .* tuples \(.*\) done},
126127
qr{creating foreign keys},
127-
qr{done\.}
128+
qr{(?!vacuuming)}, # no vacuum
129+
qr{done in \d+\.\d\d s }
128130
],
129131
'pgbench --init-steps');
130132

0 commit comments

Comments
 (0)