MCPcopy Create free account
hub / github.com/apache/cloudberry / pqTraceFormatTimestamp

Function pqTraceFormatTimestamp

src/interfaces/libpq/fe-trace.c:79–100  ·  view source on GitHub ↗

* Print the current time, with microseconds, into a caller-supplied * buffer. * Cribbed from setup_formatted_log_time, but much simpler. */

Source from the content-addressed store, hash-verified

77 * Cribbed from setup_formatted_log_time, but much simpler.
78 */
79static void
80pqTraceFormatTimestamp(char *timestr, size_t ts_len)
81{
82 struct timeval tval;
83 time_t now;
84
85 gettimeofday(&tval, NULL);
86
87 /*
88 * MSVC's implementation of timeval uses a long for tv_sec, however,
89 * localtime() expects a time_t pointer. Here we'll assign tv_sec to a
90 * local time_t variable so that we pass localtime() the correct pointer
91 * type.
92 */
93 now = tval.tv_sec;
94 strftime(timestr, ts_len,
95 "%Y-%m-%d %H:%M:%S",
96 localtime(&now));
97 /* append microseconds */
98 snprintf(timestr + strlen(timestr), ts_len - strlen(timestr),
99 ".%06u", (unsigned int) (tval.tv_usec));
100}
101
102/*
103 * pqTraceOutputByte1: output a 1-char message to the log

Callers 2

pqTraceOutputMessageFunction · 0.85

Calls 1

gettimeofdayFunction · 0.85

Tested by

no test coverage detected