Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1e1862

Browse files
committed
Coordinate log_line_prefix options 'm' and 'n' to share a timeval.
Commitf828654 introduced the 'n' option, but it invokedgettimeofday() independently of the 'm' option. If both options werein use (or multiple 'n' options), or if 'n' was in use along withcsvlog, then the reported times could be different for the same logmessage.To fix, initialize a global variable with gettimeofday() once per logmessage, and use that for both formats.Don't bother coordinating the time for the 't' option, which has muchlower resolution.Per complaint by Alvaro Herrera.
1 parentd94c36a commitb1e1862

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ static interrordata_stack_depth = -1; /* index of topmost active frame */
143143

144144
staticintrecursion_depth=0;/* to detect actual recursion */
145145

146-
/* buffers for formatted timestamps that might be used by both
147-
* log_line_prefix and csv logs.
146+
/*
147+
* Saved timeval and buffers for formatted timestamps that might be used by
148+
* both log_line_prefix and csv logs.
148149
*/
149150

151+
staticstructtimevalsaved_timeval;
152+
staticboolsaved_timeval_set= false;
153+
150154
#defineFORMATTED_TS_LEN 128
151155
staticcharformatted_start_time[FORMATTED_TS_LEN];
152156
staticcharformatted_log_time[FORMATTED_TS_LEN];
@@ -2195,12 +2199,16 @@ write_console(const char *line, int len)
21952199
staticvoid
21962200
setup_formatted_log_time(void)
21972201
{
2198-
structtimevaltv;
21992202
pg_time_tstamp_time;
22002203
charmsbuf[8];
22012204

2202-
gettimeofday(&tv,NULL);
2203-
stamp_time= (pg_time_t)tv.tv_sec;
2205+
if (!saved_timeval_set)
2206+
{
2207+
gettimeofday(&saved_timeval,NULL);
2208+
saved_timeval_set= true;
2209+
}
2210+
2211+
stamp_time= (pg_time_t)saved_timeval.tv_sec;
22042212

22052213
/*
22062214
* Note: we expect that guc.c will ensure that log_timezone is set up (at
@@ -2213,7 +2221,7 @@ setup_formatted_log_time(void)
22132221
pg_localtime(&stamp_time,log_timezone));
22142222

22152223
/* 'paste' milliseconds into place... */
2216-
sprintf(msbuf,".%03d", (int) (tv.tv_usec /1000));
2224+
sprintf(msbuf,".%03d", (int) (saved_timeval.tv_usec /1000));
22172225
memcpy(formatted_log_time+19,msbuf,4);
22182226
}
22192227

@@ -2440,11 +2448,16 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
24402448
break;
24412449
case'n':
24422450
{
2443-
structtimevaltv;
24442451
charstrfbuf[128];
24452452

2446-
gettimeofday(&tv,NULL);
2447-
sprintf(strfbuf,"%ld.%03d",tv.tv_sec, (int)(tv.tv_usec /1000));
2453+
if (!saved_timeval_set)
2454+
{
2455+
gettimeofday(&saved_timeval,NULL);
2456+
saved_timeval_set= true;
2457+
}
2458+
2459+
sprintf(strfbuf,"%ld.%03d",saved_timeval.tv_sec,
2460+
(int)(saved_timeval.tv_usec /1000));
24482461

24492462
if (padding!=0)
24502463
appendStringInfo(buf,"%*s",padding,strfbuf);
@@ -2825,6 +2838,7 @@ send_message_to_server_log(ErrorData *edata)
28252838

28262839
initStringInfo(&buf);
28272840

2841+
saved_timeval_set= false;
28282842
formatted_log_time[0]='\0';
28292843

28302844
log_line_prefix(&buf,edata);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp