Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7bdc55c

Browse files
committed
enable \timing oputput for \copy commands
1 parent281f401 commit7bdc55c

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
elseif (pg_strcasecmp(cmd,"copy")==0)
305305
{
306+
/* Default fetch-it-all-and-print mode */
307+
TimevalStructbefore,
308+
after;
309+
doubleelapsed_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
#ifndefWIN32
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-
#ifndefWIN32
36-
37-
typedefstructtimevalTimevalStruct;
38-
39-
#defineGETTIMEOFDAY(T) gettimeofday(T, NULL)
40-
#defineDIFF_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-
typedefstruct_timebTimevalStruct;
46-
47-
#defineGETTIMEOFDAY(T) _ftime(T)
48-
#defineDIFF_MSEC(T,U) \
49-
(((T)->time - (U)->time) * 1000.0 + \
50-
((T)->millitm - (U)->millitm))
51-
#endif
52-
5329

5430
staticboolExecQueryUsingCursor(constchar*query,double*elapsed_msec);
5531
staticboolcommand_no_begin(constchar*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
#ifndefCOMMON_H
99
#defineCOMMON_H
@@ -63,4 +63,31 @@ extern const char *session_username(void);
6363

6464
externchar*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+
#ifndefWIN32
71+
72+
#include<sys/time.h>
73+
74+
typedefstructtimevalTimevalStruct;
75+
76+
#defineGETTIMEOFDAY(T) gettimeofday(T, NULL)
77+
#defineDIFF_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+
typedefstruct_timebTimevalStruct;
83+
84+
#include<sys/types.h>
85+
#include<sys/timeb.h>
86+
87+
#defineGETTIMEOFDAY(T) _ftime(T)
88+
#defineDIFF_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)

[8]ページ先頭

©2009-2025 Movatter.jp