aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2007-04-13 20:40:59 +0000
committerMagnus Hagander <magnus@hagander.net>2007-04-13 20:40:59 +0000
commitbf3b8d8ad840180188b79996fa4635bdd298301a (patch)
tree69ac1c4d5d6737801314a64236c270efe2a28cc4 /src
parent5b464e1196cf8a7df73b47d58282273f45983231 (diff)
downloadpostgresql-bf3b8d8ad840180188b79996fa4635bdd298301a.tar.gz
postgresql-bf3b8d8ad840180188b79996fa4635bdd298301a.zip
Allow \timing in psql to have a better resolution than ~15ms on Windows.
ITAGAKI Takahiro
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/common.h29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h
index 45d9c2d3210..44203b5fc68 100644
--- a/src/bin/psql/common.h
+++ b/src/bin/psql/common.h
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.54 2007/01/05 22:19:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.55 2007/04/13 20:40:59 mha Exp $
*/
#ifndef COMMON_H
#define COMMON_H
@@ -63,10 +63,6 @@ extern const char *session_username(void);
extern char *expand_tilde(char **filename);
-/* Workarounds for Windows */
-/* Probably to be moved up the source tree in the future, perhaps to be replaced by
- * more specific checks like configure-style HAVE_GETTIMEOFDAY macros.
- */
#ifndef WIN32
#include <sys/time.h>
@@ -78,16 +74,25 @@ typedef struct timeval TimevalStruct;
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
#else
+/*
+ * To get good resolution (better than ~15ms) on Windows, use
+ * the high resolution performance counters. They can't be used
+ * to get absolute times, but are good for measuring differences.
+ */
+static __inline__ double
+GetTimerFrequency(void)
+{
+ LARGE_INTEGER f;
-#include <sys/types.h>
-#include <sys/timeb.h>
+ QueryPerformanceFrequency(&f);
+ return (double) f.QuadPart;
+}
-typedef struct _timeb TimevalStruct;
+typedef LARGE_INTEGER TimevalStruct;
-#define GETTIMEOFDAY(T) _ftime(T)
+#define GETTIMEOFDAY(T) QueryPerformanceCounter((T))
#define DIFF_MSEC(T, U) \
- (((T)->time - (U)->time) * 1000.0 + \
- ((T)->millitm - (U)->millitm))
-#endif
+ (((T)->QuadPart - (U)->QuadPart) * 1000.0 / GetTimerFrequency())
+#endif /* WIN32 */
#endif /* COMMON_H */