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

Commit 7bdc55c

Browse files
committed
enable \timing oputput for \copy commands
1 parent 281f401 commit 7bdc55c

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

src/bin/psql/command.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.174 2006/10/06 17:14:00 petere Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.175 2006/12/16 00:38:43 adunstan Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -303,10 +303,26 @@ exec_command(const char *cmd,
303303
/* \copy */
304304
else if (pg_strcasecmp(cmd, "copy") == 0)
305305
{
306+
/* Default fetch-it-all-and-print mode */
307+
TimevalStruct before,
308+
after;
309+
double elapsed_msec = 0;
310+
306311
char *opt = psql_scan_slash_option(scan_state,
307312
OT_WHOLE_LINE, NULL, false);
308-
313+
if (pset.timing)
314+
GETTIMEOFDAY(&before);
315+
309316
success = do_copy(opt);
317+
318+
if (pset.timing && success)
319+
{
320+
GETTIMEOFDAY(&after);
321+
elapsed_msec = DIFF_MSEC(&after, &before);
322+
printf(_("Time: %.3f ms\n"), elapsed_msec);
323+
324+
}
325+
310326
free(opt);
311327
}
312328

src/bin/psql/common.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.130 2006/10/04 00:30:05 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.131 2006/12/16 00:38:43 adunstan Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
1010

1111
#include <ctype.h>
1212
#include <signal.h>
1313
#ifndef WIN32
14-
#include <sys/time.h>
1514
#include <unistd.h> /* for write() */
1615
#else
1716
#include <io.h> /* for _write() */
1817
#include <win32.h>
19-
#include <sys/timeb.h> /* for _ftime() */
2018
#endif
2119

2220
#include "pqsignal.h"
@@ -28,28 +26,6 @@
2826
#include "mbprint.h"
2927

3028

31-
/* Workarounds for Windows */
32-
/* Probably to be moved up the source tree in the future, perhaps to be replaced by
33-
* more specific checks like configure-style HAVE_GETTIMEOFDAY macros.
34-
*/
35-
#ifndef WIN32
36-
37-
typedef struct timeval TimevalStruct;
38-
39-
#define GETTIMEOFDAY(T) gettimeofday(T, NULL)
40-
#define DIFF_MSEC(T, U) \
41-
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
42-
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
43-
#else
44-
45-
typedef struct _timeb TimevalStruct;
46-
47-
#define GETTIMEOFDAY(T) _ftime(T)
48-
#define DIFF_MSEC(T, U) \
49-
(((T)->time - (U)->time) * 1000.0 + \
50-
((T)->millitm - (U)->millitm))
51-
#endif
52-
5329

5430
static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec);
5531
static bool command_no_begin(const char *query);

src/bin/psql/common.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.51 2006/10/04 00:30:05 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.52 2006/12/16 00:38:43 adunstan Exp $
77
*/
88
#ifndef COMMON_H
99
#define COMMON_H
@@ -63,4 +63,31 @@ extern const char *session_username(void);
6363

6464
extern char *expand_tilde(char **filename);
6565

66+
/* Workarounds for Windows */
67+
/* Probably to be moved up the source tree in the future, perhaps to be replaced by
68+
* more specific checks like configure-style HAVE_GETTIMEOFDAY macros.
69+
*/
70+
#ifndef WIN32
71+
72+
#include <sys/time.h>
73+
74+
typedef struct timeval TimevalStruct;
75+
76+
#define GETTIMEOFDAY(T) gettimeofday(T, NULL)
77+
#define DIFF_MSEC(T, U) \
78+
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
79+
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
80+
#else
81+
82+
typedef struct _timeb TimevalStruct;
83+
84+
#include <sys/types.h>
85+
#include <sys/timeb.h>
86+
87+
#define GETTIMEOFDAY(T) _ftime(T)
88+
#define DIFF_MSEC(T, U) \
89+
(((T)->time - (U)->time) * 1000.0 + \
90+
((T)->millitm - (U)->millitm))
91+
#endif
92+
6693
#endif /* COMMON_H */

0 commit comments

Comments
 (0)