From: Marko Kreen Date: Mon, 11 Jan 2010 05:01:41 +0000 (+0200) Subject: X-Git-Tag: pgbouncer_1_4_rc3~82 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21d703ae1600e75c39262ff9c01a11ca0456be70;p=pgbouncer --- diff --git a/include/bouncer.h b/include/bouncer.h index 8f46a45..93911f0 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -22,6 +22,8 @@ #include "system.h" +#include + #include #ifdef DBGVER diff --git a/include/system.h b/include/system.h index 50df02b..d91444c 100644 --- a/include/system.h +++ b/include/system.h @@ -26,7 +26,6 @@ #include "win32support.h" #endif -#include #include #ifdef HAVE_SYS_SOCKET_H @@ -48,7 +47,6 @@ #include #endif -#include #include #include #include @@ -92,10 +90,6 @@ do { \ #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. */ diff --git a/include/util.h b/include/util.h index 29ca9ca..0c242bd 100644 --- a/include/util.h +++ b/include/util.h @@ -16,12 +16,6 @@ * 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 */ @@ -100,8 +94,6 @@ void tune_socket(int sock, bool is_unix); 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); diff --git a/src/pktbuf.c b/src/pktbuf.c index 16167d8..be0a32e 100644 --- a/src/pktbuf.c +++ b/src/pktbuf.c @@ -390,7 +390,7 @@ void pktbuf_write_DataRow(PktBuf *buf, const char *tupdesc, ...) 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); diff --git a/src/util.c b/src/util.c index 2815bb4..75b6d11 100644 --- a/src/util.c +++ b/src/util.c @@ -55,18 +55,6 @@ static struct FacName facility_names [] = { * 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) { @@ -141,7 +129,7 @@ static void _log_write(const char *pfx, const char *msg) 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); @@ -476,34 +464,6 @@ void get_random_bytes(uint8_t *dest, int len) 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; @@ -652,14 +612,6 @@ loop: 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;