Re: libpq debug log
Kyotaro Horiguchi <horikyota.ntt@gmail.com>
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: tsunakawa.takay@fujitsu.com
Cc: iwata.aya@fujitsu.com, k.jamison@fujitsu.com, alvherre@alvh.no-ip.org,
pgsql-hackers@lists.postgresql.org
Date: 2021-02-09T06:49:49Z
Lists: pgsql-hackers
At Tue, 9 Feb 2021 02:26:25 +0000, "tsunakawa.takay@fujitsu.com" <tsunakawa.takay@fujitsu.com> wrote in
> From: Iwata, Aya/岩田 彩 <iwata.aya@fujitsu.com>
> > I update the patch.
> > I modified code according to review comments of Tsunakawa san and
> > Horiguchi san.
>
>
> I confirmed that all the previous feedback was reflected. Here are some minor comments:
>
>
> (45)
> void PQtrace(PGconn *conn, FILE *stream);
> </synopsis>
> </para>
>
> + <para>
> + Calls <function>PQtraceEx</function> to output with or without a timestamp
> + using <literal>flags</literal>.
> + </para>
> +
> + <para>
> + <literal>flags</literal> contains flag bits describing the operating mode
> + of tracing. If (<literal>flags</literal> contains <literal>PQTRACE_SUPPRESS_TIMESTAMPS</literal>),
> + then timestamp is not printed with each message.
>
> The description of PQtrace() should be written independent of PQtraceEx(). It is an unnecessary implementation detail to the user that PQtrace() calls PQtraceEx() internally. Plus, a separate entry for PQtraceEx() needs to be added.
This looks like a fusion of PQtrace and PQtraceEX. By the way, the
timestamp flag is needed at log emittion. So we can change the state
anytime.
PQtrace(conn, of);
PQtraceSetFlags(conn, PQTRACE_SUPPRESS_TIMESTAMPS);
<logging without timestamps>
PQtraceSetFlags(conn, 0);
<logging with timestamps>
..
> (46)
>
> If skipLogging is intended for use with backend -> frontend messages only, shouldn't it be placed in conn->b_msg?
The name skipLogging is somewhat obscure. The flag doesn't inhibit all
logs from being emitted. It seems like it represents how far bytes
the logging mechanism consumed for the limited cases. Thus, I think it
can be a cursor variable like inCursor.
If we have conn->be_msg->inLogged, for example, pqGetc and
pqLogMessageByte1() are written as the follows.
pqGetc(char *result, PGconn *conn)
{
if (conn->inCursor >= conn->inEnd)
return EOF;
*result = conn->inBuffer[conn->inCursor++];
if (conn->Pfdebug)
pqLogMessageByte1(conn, *result);
return 0;
}
pqLogMessageByte1(...)
{
switch()
{
case LOG_FIRST_BYTE:
/* No point in logging already logged bytes */
if (conn->be_msg->inLogged >= conn->inCursor)
return;
...
}
conn->be_msg->inLogged = conn->inCursor;
}
(pqCheckInBufferSpace needs to adjust inLogged.)
I'm not sure this is easier to read than the skipLogging.
> (47)
> + /* Deallocate FE/BE message tracking memory. */
> + if (conn->fe_msg &&
> + /*
> + * If fields is allocated the initial size, we reuse it next time,
> + * because it would be allocated same size and the size is not big.
> + */
> + conn->fe_msg->max_fields != DEF_FE_MSGFIELDS)
>
> I'm not completely sure if other places interpose a block comment like this between if/for/while conditions, but I think it's better to put the comment before if.
(s/is/are/)
Agreed. At least it doesn't look good.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Commits
-
Rename PQtraceSetFlags() to PQsetTraceFlags().
- d0e750c0acaf 14.0 landed
-
Suppress length of Notice/Error msgs in PQtrace regress mode
- e7e341409a3d 14.0 landed
-
Strip file names reported in error messages on Windows, too.
- 53aafdb9ff6a 14.0 landed
-
Fix setvbuf()-induced crash in libpq_pipeline
- a68a894f0198 14.0 landed
-
libpq_pipeline: Must strdup(optarg) to avoid crash
- dde1a35aee62 14.0 landed
-
Remove setvbuf() call from PQtrace()
- 6ec578e60101 14.0 landed
-
Initialize conn->Pfdebug to NULL when creating a connection
- aba24b51cc1b 14.0 landed
-
Disable force_parallel_mode in libpq_pipeline
- a6d3dea8e5e0 14.0 landed
-
libpq_pipeline: add PQtrace() support and tests
- 7bebd0d00998 14.0 landed
-
Improve PQtrace() output format
- 198b3716dba6 14.0 landed
-
Re-simplify management of inStart in pqParseInput3's subroutines.
- d3a557894ce0 11.12 landed
- d2be6cdc55ad 10.17 landed
- a98e53e10dd5 9.6.22 landed
- 56defbdd0f4e 12.7 landed
- 51c54bb60309 14.0 landed
- 3580b4a0cde0 13.3 landed