]> granicus.if.org Git - pgbouncer/commitdiff
<usual/time.h>
authorMarko Kreen <markokr@gmail.com>
Mon, 11 Jan 2010 05:01:41 +0000 (07:01 +0200)
committerMarko Kreen <markokr@gmail.com>
Tue, 4 May 2010 11:30:48 +0000 (14:30 +0300)
include/bouncer.h
include/system.h
include/util.h
src/pktbuf.c
src/util.c

index 8f46a4511bc3eae77a22fc930e83b557f0768a2d..93911f057262ccbc3ad1204c8c1037cc06f47c9b 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "system.h"
 
+#include <usual/time.h>
+
 #include <event.h>
 
 #ifdef DBGVER
index 50df02bb07804b96e74141edc3c52e98e68caddb..d91444c8c72abff3c7fe7841fc528a46b25cc3e2 100644 (file)
@@ -26,7 +26,6 @@
 #include "win32support.h"
 #endif
 
-#include <sys/time.h>
 #include <sys/stat.h>
 
 #ifdef HAVE_SYS_SOCKET_H
@@ -48,7 +47,6 @@
 #include <sys/resource.h>
 #endif
 
-#include <time.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
@@ -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.
  */
index 29ca9ca5d7b1189832f829429b9c145662bd3196..0c242bde798549e44a7499fa1667f6a80671a480 100644 (file)
  * 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);
 
index 16167d8bd96db342516ebf5b3acb7e08a011c3c9..be0a32e403aafdc209b16ce9f3d8e3ea056131c1 100644 (file)
@@ -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);
 
index 2815bb41214cc8c7d0cb5968a45b564053ebf92c..75b6d1139ff82ad9863751de4d7c812cf5e0dd82 100644 (file)
@@ -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;