\timing on/off
\timing on/off
От:
"Heikki Linnakangas" <heikki@enterprisedb.com>
Дата:
I started to look at David Fetter's patch to enable "\timing on/off", in addition to toggling the mod with just "\timing". I gather that the conclusion of the thread "Making sure \timing is on", starting at: http://archives.postgresql.org/pgsql-general/2008-05/msg00324.php was that we should leave \H and \a alone for now, because it's not clear what "\H off" would do. And \a is already documented as deprecated; we might want to do that for \H as well. Here's a patch, based on David's patch, that turns timing into a \pset variable, and makes \timing an alias for \pset timing. This makes \timing behave the same as \x. I also moved the help line from the "External" section into "Formatting". I don't think \timing is "external" in the same sense as \cd or \! are. Rather, it controls the output, like \x or \pset options. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com
Re: \timing on/off
От:
"Heikki Linnakangas" <heikki@enterprisedb.com>
Дата:
And here is the patch I forgot to attach.
Heikki Linnakangas wrote:
> I started to look at David Fetter's patch to enable "\timing on/off", in
> addition to toggling the mod with just "\timing".
>
> I gather that the conclusion of the thread "Making sure \timing is on",
> starting at:
> http://archives.postgresql.org/pgsql-general/2008-05/msg00324.php
>
> was that we should leave \H and \a alone for now, because it's not clear
> what "\H off" would do. And \a is already documented as deprecated; we
> might want to do that for \H as well.
>
> Here's a patch, based on David's patch, that turns timing into a \pset
> variable, and makes \timing an alias for \pset timing. This makes
> \timing behave the same as \x.
>
> I also moved the help line from the "External" section into
> "Formatting". I don't think \timing is "external" in the same sense as
> \cd or \! are. Rather, it controls the output, like \x or \pset options.
>
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
Index: doc/src/sgml/ref/psql-ref.sgml
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/doc/src/sgml/ref/psql-ref.sgml,v
retrieving revision 1.207
diff -c -r1.207 psql-ref.sgml
*** doc/src/sgml/ref/psql-ref.sgml 1 Jun 2008 16:23:08 -0000 1.207
--- doc/src/sgml/ref/psql-ref.sgml 9 Jun 2008 12:19:35 -0000
***************
*** 1721,1726 ****
--- 1721,1739 ----
+
+
+ timing
+
+
+ You can specify an optional second argument, if it is provided it
+ may be either on or off which
+ will enable or disable display of how long each SQL statement takes,
+ in milliseconds. If the second argument is not provided then we will
+ toggle between on and off.
+
+
+
***************
*** 1734,1740 ****
There are various shortcut commands for \pset. See
\a, \C, \H,
! \t, \T, and \x.
--- 1747,1754 ----
There are various shortcut commands for \pset. See
\a, \C, \H,
! \t, \T, \x,
! and \timing.
***************
*** 1864,1870 ****
\timing
! Toggles a display of how long each SQL statement takes, in milliseconds.
--- 1878,1885 ----
\timing
! Toggles a display of how long each SQL statement takes. As such it
! is equivalent to \pset timing.
Index: src/bin/psql/command.c
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/bin/psql/command.c,v
retrieving revision 1.189
diff -c -r1.189 command.c
*** src/bin/psql/command.c 14 May 2008 19:10:29 -0000 1.189
--- src/bin/psql/command.c 9 Jun 2008 10:56:25 -0000
***************
*** 290,301 ****
char *opt = psql_scan_slash_option(scan_state,
OT_WHOLE_LINE, NULL, false);
! if (pset.timing)
INSTR_TIME_SET_CURRENT(before);
success = do_copy(opt);
! if (pset.timing && success)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
--- 290,301 ----
char *opt = psql_scan_slash_option(scan_state,
OT_WHOLE_LINE, NULL, false);
! if (pset.popt.timing)
INSTR_TIME_SET_CURRENT(before);
success = do_copy(opt);
! if (pset.popt.timing && success)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
***************
*** 884,897 ****
/* \timing -- toggle timing of queries */
else if (strcmp(cmd, "timing") == 0)
{
! pset.timing = !pset.timing;
! if (!pset.quiet)
! {
! if (pset.timing)
! puts(_("Timing is on."));
! else
! puts(_("Timing is off."));
! }
}
/* \unset */
--- 884,894 ----
/* \timing -- toggle timing of queries */
else if (strcmp(cmd, "timing") == 0)
{
! char *opt = psql_scan_slash_option(scan_state,
! OT_NORMAL, NULL, true);
!
! success = do_pset("timing", opt, &pset.popt, pset.quiet);
! free(opt);
}
/* \unset */
***************
*** 1739,1744 ****
--- 1736,1752 ----
printf(_("Target width for \"wrapped\" format is %d.\n"), popt->topt.columns);
}
+ /* set timing mode */
+ else if (strcmp(param, "timing") == 0)
+ {
+ if (value)
+ popt->timing = ParseVariableBool(value);
+ else
+ popt->timing = !popt->timing;
+ if (!quiet)
+ puts(popt->timing ? _("Timing is on.") : _("Timing is off."));
+ }
+
else
{
psql_error("\\pset: unknown option: %s\n", param);
Index: src/bin/psql/common.c
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/bin/psql/common.c,v
retrieving revision 1.139
diff -c -r1.139 common.c
*** src/bin/psql/common.c 14 May 2008 19:10:29 -0000 1.139
--- src/bin/psql/common.c 9 Jun 2008 10:57:25 -0000
***************
*** 849,855 ****
instr_time before,
after;
! if (pset.timing)
INSTR_TIME_SET_CURRENT(before);
results = PQexec(pset.db, query);
--- 849,855 ----
instr_time before,
after;
! if (pset.popt.timing)
INSTR_TIME_SET_CURRENT(before);
results = PQexec(pset.db, query);
***************
*** 858,864 ****
ResetCancelConn();
OK = (AcceptResult(results) && ProcessCopyResult(results));
! if (pset.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
--- 858,864 ----
ResetCancelConn();
OK = (AcceptResult(results) && ProcessCopyResult(results));
! if (pset.popt.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
***************
*** 920,926 ****
PQclear(results);
/* Possible microtiming output */
! if (OK && pset.timing && !pset.quiet)
printf(_("Time: %.3f ms\n"), elapsed_msec);
/* check for events that may occur during query execution */
--- 920,926 ----
PQclear(results);
/* Possible microtiming output */
! if (OK && pset.popt.timing && !pset.quiet)
printf(_("Time: %.3f ms\n"), elapsed_msec);
/* check for events that may occur during query execution */
***************
*** 974,980 ****
my_popt.topt.stop_table = false;
my_popt.topt.prior_records = 0;
! if (pset.timing)
INSTR_TIME_SET_CURRENT(before);
/* if we're not in a transaction, start one */
--- 974,980 ----
my_popt.topt.stop_table = false;
my_popt.topt.prior_records = 0;
! if (pset.popt.timing)
INSTR_TIME_SET_CURRENT(before);
/* if we're not in a transaction, start one */
***************
*** 1002,1008 ****
if (!OK)
goto cleanup;
! if (pset.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
--- 1002,1008 ----
if (!OK)
goto cleanup;
! if (pset.popt.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
***************
*** 1031,1043 ****
for (;;)
{
! if (pset.timing)
INSTR_TIME_SET_CURRENT(before);
/* get FETCH_COUNT tuples at a time */
results = PQexec(pset.db, fetch_cmd);
! if (pset.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
--- 1031,1043 ----
for (;;)
{
! if (pset.popt.timing)
INSTR_TIME_SET_CURRENT(before);
/* get FETCH_COUNT tuples at a time */
results = PQexec(pset.db, fetch_cmd);
! if (pset.popt.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
***************
*** 1116,1122 ****
}
cleanup:
! if (pset.timing)
INSTR_TIME_SET_CURRENT(before);
/*
--- 1116,1122 ----
}
cleanup:
! if (pset.popt.timing)
INSTR_TIME_SET_CURRENT(before);
/*
***************
*** 1140,1146 ****
PQclear(results);
}
! if (pset.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
--- 1140,1146 ----
PQclear(results);
}
! if (pset.popt.timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
Index: src/bin/psql/help.c
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/bin/psql/help.c,v
retrieving revision 1.128
diff -c -r1.128 help.c
*** src/bin/psql/help.c 16 May 2008 17:17:00 -0000 1.128
--- src/bin/psql/help.c 9 Jun 2008 12:27:48 -0000
***************
*** 233,238 ****
--- 233,240 ----
fprintf(output, _(" \\T [STRING] set HTML Re: \timing on/off
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Heikki Linnakangas" writes: >> I gather that the conclusion of the thread "Making sure \timing is on", >> starting at: >> http://archives.postgresql.org/pgsql-general/2008-05/msg00324.php >> >> was that we should leave \H and \a alone for now, because it's not clear >> what "\H off" would do. Yeah, I think that was the consensus. >> Here's a patch, based on David's patch, that turns timing into a \pset >> variable, and makes \timing an alias for \pset timing. This makes >> \timing behave the same as \x. This seems a bit random to me. AFAIR all of the \pset properties are associated with formatting of table output. \timing doesn't belong. regards, tom lane
Re: \timing on/off
От:
"Heikki Linnakangas" <heikki@enterprisedb.com>
Дата:
Tom Lane wrote: > "Heikki Linnakangas" writes: >>> Here's a patch, based on David's patch, that turns timing into a \pset >>> variable, and makes \timing an alias for \pset timing. This makes >>> \timing behave the same as \x. > > This seems a bit random to me. AFAIR all of the \pset properties are > associated with formatting of table output. \timing doesn't belong. Hmm, yes, so it seems. This patch http://archives.postgresql.org/pgsql-general/2008-05/msg00427.php from David seems the most appropriate thing to do then. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com