diff options
author | Andrew Dunstan | 2006-12-16 00:38:43 +0000 |
---|---|---|
committer | Andrew Dunstan | 2006-12-16 00:38:43 +0000 |
commit | ea671c2f2fb44cade8f8b55a25b1a8219ca4d2f5 (patch) | |
tree | b4dfe8777a1e3cefce6924b3595bbc184657407e | |
parent | 8a936e911f12384c12eb283882eecdfe9e823260 (diff) |
enable \timing oputput for \copy commands
-rw-r--r-- | src/bin/psql/command.c | 18 | ||||
-rw-r--r-- | src/bin/psql/common.c | 24 | ||||
-rw-r--r-- | src/bin/psql/common.h | 27 |
3 files changed, 44 insertions, 25 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 7a68a9606c..eaf07537f2 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -303,10 +303,26 @@ exec_command(const char *cmd, /* \copy */ else if (pg_strcasecmp(cmd, "copy") == 0) { + /* Default fetch-it-all-and-print mode */ + TimevalStruct before, + after; + double elapsed_msec = 0; + char *opt = psql_scan_slash_option(scan_state, OT_WHOLE_LINE, NULL, false); - + if (pset.timing) + GETTIMEOFDAY(&before); + success = do_copy(opt); + + if (pset.timing && success) + { + GETTIMEOFDAY(&after); + elapsed_msec = DIFF_MSEC(&after, &before); + printf(_("Time: %.3f ms\n"), elapsed_msec); + + } + free(opt); } diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 7d1910bf89..5f90ca64c6 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -11,12 +11,10 @@ #include <ctype.h> #include <signal.h> #ifndef WIN32 -#include <sys/time.h> #include <unistd.h> /* for write() */ #else #include <io.h> /* for _write() */ #include <win32.h> -#include <sys/timeb.h> /* for _ftime() */ #endif #include "pqsignal.h" @@ -28,28 +26,6 @@ #include "mbprint.h" -/* Workarounds for Windows */ -/* Probably to be moved up the source tree in the future, perhaps to be replaced by - * more specific checks like configure-style HAVE_GETTIMEOFDAY macros. - */ -#ifndef WIN32 - -typedef struct timeval TimevalStruct; - -#define GETTIMEOFDAY(T) gettimeofday(T, NULL) -#define DIFF_MSEC(T, U) \ - ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ - ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) -#else - -typedef struct _timeb TimevalStruct; - -#define GETTIMEOFDAY(T) _ftime(T) -#define DIFF_MSEC(T, U) \ - (((T)->time - (U)->time) * 1000.0 + \ - ((T)->millitm - (U)->millitm)) -#endif - static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec); static bool command_no_begin(const char *query); diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h index 37fa14958f..b284e44006 100644 --- a/src/bin/psql/common.h +++ b/src/bin/psql/common.h @@ -63,4 +63,31 @@ extern const char *session_username(void); extern char *expand_tilde(char **filename); +/* Workarounds for Windows */ +/* Probably to be moved up the source tree in the future, perhaps to be replaced by + * more specific checks like configure-style HAVE_GETTIMEOFDAY macros. + */ +#ifndef WIN32 + +#include <sys/time.h> + +typedef struct timeval TimevalStruct; + +#define GETTIMEOFDAY(T) gettimeofday(T, NULL) +#define DIFF_MSEC(T, U) \ + ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ + ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) +#else + +typedef struct _timeb TimevalStruct; + +#include <sys/types.h> +#include <sys/timeb.h> + +#define GETTIMEOFDAY(T) _ftime(T) +#define DIFF_MSEC(T, U) \ + (((T)->time - (U)->time) * 1000.0 + \ + ((T)->millitm - (U)->millitm)) +#endif + #endif /* COMMON_H */ |