]> granicus.if.org Git - postgresql/commitdiff
enable \timing oputput for \copy commands
authorAndrew Dunstan <andrew@dunslane.net>
Sat, 16 Dec 2006 00:38:43 +0000 (00:38 +0000)
committerAndrew Dunstan <andrew@dunslane.net>
Sat, 16 Dec 2006 00:38:43 +0000 (00:38 +0000)
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/common.h

index 12895a1c7f6f90a27afc1dab70e51632496740b6..4f87fe45f73a903fa1e80eef566c8abf15e75767 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.174 2006/10/06 17:14:00 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.175 2006/12/16 00:38:43 adunstan Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -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);
        }
 
index 2e30c4e9a26c2106dfdb53bab61b75e86905d4d1..76e0c0e6b890282fedd552b92c72c90f044ff693 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.130 2006/10/04 00:30:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.131 2006/12/16 00:38:43 adunstan Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
 #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"
 #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);
index 3b6d566b33c355ca75d0e2ea491e4c37e918cd53..3802333e60265d8e0647b1ac48da3d5578e3bb95 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.51 2006/10/04 00:30:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.52 2006/12/16 00:38:43 adunstan Exp $
  */
 #ifndef COMMON_H
 #define 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 */