Commit ce8f9467 authored by Thomas Munro's avatar Thomas Munro

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
parent bfdbac2a
...@@ -3931,32 +3931,48 @@ checkInitSteps(const char *initialize_steps) ...@@ -3931,32 +3931,48 @@ checkInitSteps(const char *initialize_steps)
static void static void
runInitSteps(const char *initialize_steps) runInitSteps(const char *initialize_steps)
{ {
PQExpBufferData stats;
PGconn *con; PGconn *con;
const char *step; const char *step;
double run_time = 0.0;
bool first = true;
initPQExpBuffer(&stats);
if ((con = doConnect()) == NULL) if ((con = doConnect()) == NULL)
exit(1); exit(1);
for (step = initialize_steps; *step != '\0'; step++) for (step = initialize_steps; *step != '\0'; step++)
{ {
instr_time start;
char *op = NULL;
INSTR_TIME_SET_CURRENT(start);
switch (*step) switch (*step)
{ {
case 'd': case 'd':
op = "drop tables";
initDropTables(con); initDropTables(con);
break; break;
case 't': case 't':
op = "create tables";
initCreateTables(con); initCreateTables(con);
break; break;
case 'g': case 'g':
op = "generate";
initGenerateData(con); initGenerateData(con);
break; break;
case 'v': case 'v':
op = "vacuum";
initVacuum(con); initVacuum(con);
break; break;
case 'p': case 'p':
op = "primary keys";
initCreatePKeys(con); initCreatePKeys(con);
break; break;
case 'f': case 'f':
op = "foreign keys";
initCreateFKeys(con); initCreateFKeys(con);
break; break;
case ' ': case ' ':
...@@ -3967,10 +3983,30 @@ runInitSteps(const char *initialize_steps) ...@@ -3967,10 +3983,30 @@ runInitSteps(const char *initialize_steps)
PQfinish(con); PQfinish(con);
exit(1); exit(1);
} }
if (op != NULL)
{
instr_time diff;
double elapsed_sec;
INSTR_TIME_SET_CURRENT(diff);
INSTR_TIME_SUBTRACT(diff, start);
elapsed_sec = INSTR_TIME_GET_DOUBLE(diff);
if (!first)
appendPQExpBufferStr(&stats, ", ");
else
first = false;
appendPQExpBuffer(&stats, "%s %.2f s", op, elapsed_sec);
run_time += elapsed_sec;
}
} }
fprintf(stderr, "done.\n"); fprintf(stderr, "done in %.2f s (%s).\n", run_time, stats.data);
PQfinish(con); PQfinish(con);
termPQExpBuffer(&stats);
} }
/* /*
......
...@@ -94,7 +94,7 @@ pgbench( ...@@ -94,7 +94,7 @@ pgbench(
[qr{^$}], [qr{^$}],
[ [
qr{creating tables}, qr{vacuuming}, qr{creating tables}, qr{vacuuming},
qr{creating primary keys}, qr{done\.} qr{creating primary keys}, qr{done in \d+\.\d\d s }
], ],
'pgbench scale 1 initialization',); 'pgbench scale 1 initialization',);
...@@ -109,7 +109,8 @@ pgbench( ...@@ -109,7 +109,8 @@ pgbench(
qr{vacuuming}, qr{vacuuming},
qr{creating primary keys}, qr{creating primary keys},
qr{creating foreign keys}, qr{creating foreign keys},
qr{done\.} qr{(?!vacuuming)}, # no vacuum
qr{done in \d+\.\d\d s }
], ],
'pgbench scale 1 initialization'); 'pgbench scale 1 initialization');
...@@ -124,7 +125,8 @@ pgbench( ...@@ -124,7 +125,8 @@ pgbench(
qr{creating primary keys}, qr{creating primary keys},
qr{.* of .* tuples \(.*\) done}, qr{.* of .* tuples \(.*\) done},
qr{creating foreign keys}, qr{creating foreign keys},
qr{done\.} qr{(?!vacuuming)}, # no vacuum
qr{done in \d+\.\d\d s }
], ],
'pgbench --init-steps'); 'pgbench --init-steps');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment