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 ----
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><literal>timing</literal></term>
+ <listitem>
+ <para>
+ You can specify an optional second argument, if it is provided it
+ may be either <literal>on</literal> or <literal>off</literal> 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.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</para>
***************
*** 1734,1740 ****
<para>
There are various shortcut commands for <command>\pset</command>. See
<command>\a</command>, <command>\C</command>, <command>\H</command>,
! <command>\t</command>, <command>\T</command>, and <command>\x</command>.
</para>
</tip>
--- 1747,1754 ----
<para>
There are various shortcut commands for <command>\pset</command>. See
<command>\a</command>, <command>\C</command>, <command>\H</command>,
! <command>\t</command>, <command>\T</command>, <command>\x</command>,
! and <command>\timing</command>.
</para>
</tip>
***************
*** 1864,1870 ****
<term><literal>\timing</literal></term>
<listitem>
<para>
! Toggles a display of how long each SQL statement takes, in milliseconds.
</para>
</listitem>
</varlistentry>
--- 1878,1885 ----
<term><literal>\timing</literal></term>
<listitem>
<para>
! Toggles a display of how long each SQL statement takes. As such it
! is equivalent to <literal>\pset timing</literal>.
</para>
</listitem>
</varlistentry>
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 <table> tag attributes, or unset if none\n"));
fprintf(output, _(" \\x toggle expanded output (currently %s)\n"),
ON(pset.popt.topt.expanded));
+ fprintf(output, _(" \\timing toggle timing of commands (currently %s)\n"),
+ ON(pset.popt.timing));
fprintf(output, "\n");
fprintf(output, _("Connection\n"));
***************
*** 245,252 ****
fprintf(output, _("External\n"));
fprintf(output, _(" \\cd [DIR] change the current working directory\n"));
- fprintf(output, _(" \\timing toggle timing of commands (currently %s)\n"),
- ON(pset.timing));
fprintf(output, _(" \\! [COMMAND] execute command in shell or start interactive shell\n"));
fprintf(output, "\n");
--- 247,252 ----
Index: src/bin/psql/print.h
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/bin/psql/print.h,v
retrieving revision 1.37
diff -c -r1.37 print.h
*** src/bin/psql/print.h 12 May 2008 22:59:58 -0000 1.37
--- src/bin/psql/print.h 9 Jun 2008 10:55:47 -0000
***************
*** 92,97 ****
--- 92,98 ----
bool default_footer; /* print default footer if footers==NULL */
bool trans_headers; /* do gettext on column headers */
const bool *trans_columns; /* trans_columns[i-1] => do gettext on col i */
+ bool timing; /* enable timing of all queries */
} printQueryOpt;
Index: src/bin/psql/settings.h
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/bin/psql/settings.h,v
retrieving revision 1.33
diff -c -r1.33 settings.h
*** src/bin/psql/settings.h 1 Jan 2008 19:45:56 -0000 1.33
--- src/bin/psql/settings.h 9 Jun 2008 10:53:26 -0000
***************
*** 80,87 ****
uint64 lineno; /* also for error reporting */
- bool timing; /* enable timing of all queries */
-
FILE *logfile; /* session log file handle */
VariableSpace vars; /* "shell variable" repository */
--- 80,85 ----
--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches