aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/common.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-05-14 19:10:29 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-05-14 19:10:29 +0000
commit3bc25384d7a698f25e418bdc5aa7cdd038477d9c (patch)
tree0d17e084e418a335ec4eb48470bf7847a9102a6e /src/bin/psql/common.c
parent719a115874226f6e294a7d1d81d7a8ae559768ad (diff)
downloadpostgresql-3bc25384d7a698f25e418bdc5aa7cdd038477d9c.tar.gz
postgresql-3bc25384d7a698f25e418bdc5aa7cdd038477d9c.zip
Move the "instr_time" typedef and associated macros into a new header
file portability/instr_time.h, and add a couple more macros to eliminate some abstraction leakage we formerly had. Also update psql to use this header instead of its own copy of nearly the same code. This commit in itself is just code cleanup and shouldn't change anything. It lays some groundwork for the upcoming function-stats patch, though.
Diffstat (limited to 'src/bin/psql/common.c')
-rw-r--r--src/bin/psql/common.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 72aad262f5a..ab1f03f3109 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.138 2008/01/01 19:45:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.139 2008/05/14 19:10:29 tgl Exp $
*/
#include "postgres_fe.h"
#include "common.h"
@@ -17,6 +17,8 @@
#include <win32.h>
#endif
+#include "portability/instr_time.h"
+
#include "pqsignal.h"
#include "settings.h"
@@ -844,11 +846,11 @@ SendQuery(const char *query)
if (pset.fetch_count <= 0 || !is_select_command(query))
{
/* Default fetch-it-all-and-print mode */
- TimevalStruct before,
+ instr_time before,
after;
if (pset.timing)
- GETTIMEOFDAY(&before);
+ INSTR_TIME_SET_CURRENT(before);
results = PQexec(pset.db, query);
@@ -858,8 +860,9 @@ SendQuery(const char *query)
if (pset.timing)
{
- GETTIMEOFDAY(&after);
- elapsed_msec = DIFF_MSEC(&after, &before);
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ elapsed_msec = INSTR_TIME_GET_MILLISEC(after);
}
/* but printing results isn't: */
@@ -961,7 +964,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
bool did_pager = false;
int ntuples;
char fetch_cmd[64];
- TimevalStruct before,
+ instr_time before,
after;
*elapsed_msec = 0;
@@ -972,7 +975,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
my_popt.topt.prior_records = 0;
if (pset.timing)
- GETTIMEOFDAY(&before);
+ INSTR_TIME_SET_CURRENT(before);
/* if we're not in a transaction, start one */
if (PQtransactionStatus(pset.db) == PQTRANS_IDLE)
@@ -1001,8 +1004,9 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
if (pset.timing)
{
- GETTIMEOFDAY(&after);
- *elapsed_msec += DIFF_MSEC(&after, &before);
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ *elapsed_msec += INSTR_TIME_GET_MILLISEC(after);
}
snprintf(fetch_cmd, sizeof(fetch_cmd),
@@ -1028,15 +1032,16 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
for (;;)
{
if (pset.timing)
- GETTIMEOFDAY(&before);
+ INSTR_TIME_SET_CURRENT(before);
/* get FETCH_COUNT tuples at a time */
results = PQexec(pset.db, fetch_cmd);
if (pset.timing)
{
- GETTIMEOFDAY(&after);
- *elapsed_msec += DIFF_MSEC(&after, &before);
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ *elapsed_msec += INSTR_TIME_GET_MILLISEC(after);
}
if (PQresultStatus(results) != PGRES_TUPLES_OK)
@@ -1112,7 +1117,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
cleanup:
if (pset.timing)
- GETTIMEOFDAY(&before);
+ INSTR_TIME_SET_CURRENT(before);
/*
* We try to close the cursor on either success or failure, but on failure
@@ -1137,8 +1142,9 @@ cleanup:
if (pset.timing)
{
- GETTIMEOFDAY(&after);
- *elapsed_msec += DIFF_MSEC(&after, &before);
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ *elapsed_msec += INSTR_TIME_GET_MILLISEC(after);
}
return OK;