#include "win32support.h"
#endif
-#include <sys/time.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/resource.h>
#endif
-#include <time.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#define UNIX_PATH_MAX 128 /* actual sizeof() will be applied later anyway */
#endif
-/* how many microseconds in a second */
-#define USEC (1000000LL)
-
-typedef uint64_t usec_t;
/*
* PostgreSQL type OIDs for resultsets.
*/
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/*
- * time tools
- */
-usec_t get_cached_time(void);
-void reset_time_cache(void);
-
/*
* load file into malloced buffer
*/
bool strlist_contains(const char *liststr, const char *str);
-const char *format_date(usec_t uval);
-
void fill_remote_addr(PgSocket *sk, int fd, bool is_unix);
void fill_local_addr(PgSocket *sk, int fd, bool is_unix);
val = va_arg(ap, char *);
} else if (tupdesc[i] == 'T') {
usec_t time = va_arg(ap, usec_t);
- val = format_date(time);
+ val = format_time_s(time, tmp, sizeof(tmp));
} else
fatal("bad tupdesc: %s", tupdesc);
* Generic logging
*/
-static void render_time(char *buf, int max)
-{
- struct tm *tm;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- tm = localtime(&tv.tv_sec);
- snprintf(buf, max, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec,
- (int)(tv.tv_usec / 1000));
-}
-
static void close_syslog(void)
{
if (syslog_started) {
int len;
int old_errno = errno;
- render_time(tbuf, sizeof(tbuf));
+ format_time_ms(0, tbuf, sizeof(tbuf));
len = snprintf(buf, sizeof(buf), "%s %u %s %s\n",
tbuf, (unsigned)getpid(), pfx, msg);
dest[i] = random() & 255;
}
-/*
- * high-precision time
- */
-
-static usec_t get_time_usec(void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (usec_t)tv.tv_sec * USEC + tv.tv_usec;
-}
-
-/*
- * cache time, as we don't need sub-second precision
- */
-static usec_t time_cache = 0;
-
-usec_t get_cached_time(void)
-{
- if (!time_cache)
- time_cache = get_time_usec();
- return time_cache;
-}
-
-void reset_time_cache(void)
-{
- time_cache = 0;
-}
-
void socket_set_nonblocking(int fd, int val)
{
int flags, res;
return true;
}
-const char *format_date(usec_t uval)
-{
- static char buf[128];
- time_t tval = uval / USEC;
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&tval));
- return buf;
-}
-
void fill_remote_addr(PgSocket *sk, int fd, bool is_unix)
{
PgAddr *dst = &sk->remote_addr;