static int recursion_depth = 0; /* to detect actual recursion */
-/* buffers for formatted timestamps that might be used by both
- * log_line_prefix and csv logs.
+/*
+ * Saved timeval and buffers for formatted timestamps that might be used by
+ * both log_line_prefix and csv logs.
*/
+static struct timeval saved_timeval;
+static bool saved_timeval_set = false;
+
#define FORMATTED_TS_LEN 128
static char formatted_start_time[FORMATTED_TS_LEN];
static char formatted_log_time[FORMATTED_TS_LEN];
static void
setup_formatted_log_time(void)
{
- struct timeval tv;
pg_time_t stamp_time;
char msbuf[8];
- gettimeofday(&tv, NULL);
- stamp_time = (pg_time_t) tv.tv_sec;
+ if (!saved_timeval_set)
+ {
+ gettimeofday(&saved_timeval, NULL);
+ saved_timeval_set = true;
+ }
+
+ stamp_time = (pg_time_t) saved_timeval.tv_sec;
/*
* Note: we expect that guc.c will ensure that log_timezone is set up (at
pg_localtime(&stamp_time, log_timezone));
/* 'paste' milliseconds into place... */
- sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
+ sprintf(msbuf, ".%03d", (int) (saved_timeval.tv_usec / 1000));
memcpy(formatted_log_time + 19, msbuf, 4);
}
break;
case 'n':
{
- struct timeval tv;
char strfbuf[128];
- gettimeofday(&tv, NULL);
- sprintf(strfbuf, "%ld.%03d", tv.tv_sec, (int)(tv.tv_usec / 1000));
+ if (!saved_timeval_set)
+ {
+ gettimeofday(&saved_timeval, NULL);
+ saved_timeval_set = true;
+ }
+
+ sprintf(strfbuf, "%ld.%03d", saved_timeval.tv_sec,
+ (int)(saved_timeval.tv_usec / 1000));
if (padding != 0)
appendStringInfo(buf, "%*s", padding, strfbuf);
initStringInfo(&buf);
+ saved_timeval_set = false;
formatted_log_time[0] = '\0';
log_line_prefix(&buf, edata);