On Mon, 2015-09-07 at 18:28 -0300, Alvaro Herrera wrote: > I noticed %t, but I don't think we care since the precision is so poor. > Making m and n work in unison seems enough. I think it would be > reasonably simple to handle %t in the same way, but I'm not sure we > care.
OK. > I think the extra ugliness is warranted, since it's not THAT much > additional ugliness, and not doing it could be considered a regression; > apparently strftime can be slower even than snprintf, so doing it twice > per log message might be excessive overhead. Patch attached. Please take a quick look. Regards, Jeff Davis
*** a/src/backend/utils/error/elog.c --- b/src/backend/utils/error/elog.c *************** *** 143,152 **** static int errordata_stack_depth = -1; /* index of topmost active frame */ 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. */ #define FORMATTED_TS_LEN 128 static char formatted_start_time[FORMATTED_TS_LEN]; static char formatted_log_time[FORMATTED_TS_LEN]; --- 143,156 ---- static int recursion_depth = 0; /* to detect actual recursion */ ! /* ! * 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]; *************** *** 2195,2206 **** write_console(const char *line, int 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; /* * Note: we expect that guc.c will ensure that log_timezone is set up (at --- 2199,2214 ---- static void setup_formatted_log_time(void) { pg_time_t stamp_time; char msbuf[8]; ! 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 *************** *** 2213,2219 **** setup_formatted_log_time(void) pg_localtime(&stamp_time, log_timezone)); /* 'paste' milliseconds into place... */ ! sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000)); memcpy(formatted_log_time + 19, msbuf, 4); } --- 2221,2227 ---- pg_localtime(&stamp_time, log_timezone)); /* 'paste' milliseconds into place... */ ! sprintf(msbuf, ".%03d", (int) (saved_timeval.tv_usec / 1000)); memcpy(formatted_log_time + 19, msbuf, 4); } *************** *** 2440,2450 **** log_line_prefix(StringInfo buf, ErrorData *edata) 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 (padding != 0) appendStringInfo(buf, "%*s", padding, strfbuf); --- 2448,2463 ---- break; case 'n': { char strfbuf[128]; ! 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); *************** *** 2825,2830 **** send_message_to_server_log(ErrorData *edata) --- 2838,2844 ---- initStringInfo(&buf); + saved_timeval_set = false; formatted_log_time[0] = '\0'; log_line_prefix(&buf, edata);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers