Allow \timing in psql to have a better resolution than ~15ms on Windows.
ITAGAKI Takahiro
This commit is contained in:
parent
5b464e1196
commit
bf3b8d8ad8
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
|
* 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
|
#ifndef COMMON_H
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
@ -63,10 +63,6 @@ extern const char *session_username(void);
|
|||||||
|
|
||||||
extern char *expand_tilde(char **filename);
|
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
|
#ifndef WIN32
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -78,16 +74,25 @@ typedef struct timeval TimevalStruct;
|
|||||||
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
|
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
|
||||||
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
|
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
|
||||||
#else
|
#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>
|
QueryPerformanceFrequency(&f);
|
||||||
#include <sys/timeb.h>
|
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) \
|
#define DIFF_MSEC(T, U) \
|
||||||
(((T)->time - (U)->time) * 1000.0 + \
|
(((T)->QuadPart - (U)->QuadPart) * 1000.0 / GetTimerFrequency())
|
||||||
((T)->millitm - (U)->millitm))
|
#endif /* WIN32 */
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* COMMON_H */
|
#endif /* COMMON_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user