* Print the current time, with microseconds, into a caller-supplied * buffer. * Cribbed from setup_formatted_log_time, but much simpler. */
| 77 | * Cribbed from setup_formatted_log_time, but much simpler. |
| 78 | */ |
| 79 | static void |
| 80 | pqTraceFormatTimestamp(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 |
no test coverage detected