Changeset: f08f0896589c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f08f0896589c Modified Files: gdk/gdk_posix.c gdk/gdk_posix.h monetdb5/mal/mal_profiler.c monetdb5/modules/mal/wlc.c sql/backends/monet5/sql_result.c sql/backends/monet5/wlr.c Branch: cmake-fun Log Message:
Use consistently ftime on Windows instead of gettimeofday. No necessity to implement it there. diffs (229 lines): diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c --- a/gdk/gdk_posix.c +++ b/gdk/gdk_posix.c @@ -684,11 +684,9 @@ MT_init_posix(void) size_t MT_getrss(void) { -#ifdef _WIN64 PROCESS_MEMORY_COUNTERS ctr; if (GetProcessMemoryInfo(GetCurrentProcess(), &ctr, sizeof(ctr))) return ctr.WorkingSetSize; -#endif return 0; } @@ -842,34 +840,6 @@ MT_path_absolute(const char *pathname) (pathname[0] == '\\' && pathname[1] == '\\')); } -#ifdef _MSC_VER -static int nodays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - -#define LEAPYEAR(y) ((((y)%4)==0 && ((y)%100)!=0) || ((y)%400)==0) -#define NODAYS(m,y) (((m)!=2)?nodays[(m)-1]:LEAPYEAR(y)?29:28) - -int -gettimeofday(struct timeval *tv, int *ignore_zone) -{ - unsigned int year, day, month; - SYSTEMTIME st; - - (void) ignore_zone; - GetSystemTime(&st); - day = 0; - for (year = 1970; year < st.wYear; year++) - day += LEAPYEAR(year) ? 366 : 365; - - for (month = 1; month < st.wMonth; month++) - day += NODAYS(month, st.wYear); - - day += st.wDay; - tv->tv_sec = 60 * (day * 24 * 60 + st.wMinute) + st.wSecond; - tv->tv_usec = 1000 * st.wMilliseconds; - return 0; -} -#endif - void * mdlopen(const char *file, int mode) { diff --git a/gdk/gdk_posix.h b/gdk/gdk_posix.h --- a/gdk/gdk_posix.h +++ b/gdk/gdk_posix.h @@ -145,9 +145,6 @@ gdk_export int dlclose(void *handle); gdk_export void *dlsym(void *handle, const char *name); gdk_export char *dlerror(void); -#ifdef _MSC_VER -gdk_export int gettimeofday(struct timeval *tv, int *ignore_zone); -#endif gdk_export int win_stat(const char *, struct stat *); gdk_export int win_rmdir(const char *); gdk_export int win_rename(const char *, const char *); diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c --- a/monetdb5/mal/mal_profiler.c +++ b/monetdb5/mal/mal_profiler.c @@ -24,7 +24,9 @@ #include "mal_utils.h" #include "mal_resource.h" -#ifndef NATIVE_WIN32 +#ifdef NATIVE_WIN32 +#include <sys/timeb.h> /* ftime */ +#else #include <sys/time.h> #endif @@ -42,7 +44,11 @@ static int highwatermark = 5; // conserv static int TRACE_init = 0; int malProfileMode = 0; /* global flag to indicate profiling mode */ +#ifdef NATIVE_WIN32 +static struct timeb startup_time; +#else static struct timeval startup_time; +#endif static ATOMIC_TYPE hbdelay = ATOMIC_VAR_INIT(0); @@ -142,7 +148,11 @@ renderProfilerEvent(MalBlkPtr mb, MalStk str stmt, c; str stmtq; lng usec= GDKusec(); +#ifdef NATIVE_WIN32 + uint64_t microseconds = (uint64_t)startup_time.time*1000000 + ((int64_t) startup_time.millitm) * 1000 + (uint64_t)usec; +#else uint64_t microseconds = (uint64_t)startup_time.tv_sec*1000000 + (uint64_t)startup_time.tv_usec + (uint64_t)usec; +#endif // ignore generation of events for instructions that are called too often if(highwatermark && highwatermark + (start == 0) < pci->calls) @@ -449,7 +459,11 @@ profilerHeartbeatEvent(char *alter) char logbuffer[LOGLEN], *logbase; int loglen; lng usec = GDKusec(); +#ifdef NATIVE_WIN32 + uint64_t microseconds = (uint64_t)startup_time.time*1000000 + ((int64_t) startup_time.millitm) * 1000 + (uint64_t)usec; +#else uint64_t microseconds = (uint64_t)startup_time.tv_sec*1000000 + (uint64_t)startup_time.tv_usec + (uint64_t)usec; +#endif if (ATOMIC_GET(&hbdelay) == 0 || eventstream == NULL) return; @@ -1034,7 +1048,6 @@ getDiskSpace(void) return size; } - void profilerGetCPUStat(lng *user, lng *nice, lng *sys, lng *idle, lng *iowait) { (void) getCPULoad(0); @@ -1087,7 +1100,11 @@ void setHeartbeat(int delay) void initProfiler(void) { +#ifdef NATIVE_WIN32 + ftime(&startup_time); +#else gettimeofday(&startup_time, NULL); +#endif } void initHeartbeat(void) diff --git a/monetdb5/modules/mal/wlc.c b/monetdb5/modules/mal/wlc.c --- a/monetdb5/modules/mal/wlc.c +++ b/monetdb5/modules/mal/wlc.c @@ -151,6 +151,7 @@ #include "wlc.h" #ifdef NATIVE_WIN32 +#include <sys/timeb.h> /* ftime */ #define access _access #endif @@ -466,15 +467,23 @@ WLCstopmaster(Client cntxt, MalBlkPtr mb static str WLCsettime(Client cntxt, InstrPtr pci, InstrPtr p, str call) { - struct timeval clock; - time_t clk ; + time_t clk; struct tm ctm; char wlc_time[26]; - (void) pci; +#ifdef NATIVE_WIN32 + struct timeb tb; + + ftime(&tb); + clk = tb.time; +#else + struct timeval clock; + if(gettimeofday(&clock,NULL) == -1) throw(MAL,call,"Unable to retrieve current time"); clk = clock.tv_sec; +#endif + (void) pci; ctm = *localtime(&clk); strftime(wlc_time, 26, "%Y-%m-%dT%H:%M:%S",&ctm); if (pushStr(cntxt->wlc, p, wlc_time) == NULL) diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c --- a/sql/backends/monet5/sql_result.c +++ b/sql/backends/monet5/sql_result.c @@ -19,10 +19,6 @@ #include "bat/bat_storage.h" #include "rel_exp.h" -#ifndef HAVE_LLABS -#define llabs(x) ((x) < 0 ? -(x) : (x)) -#endif - #ifdef _MSC_VER /* use intrinsic functions on Windows */ #define short_int_SWAP(s) ((short) _byteswap_ushort((unsigned short) (s))) diff --git a/sql/backends/monet5/wlr.c b/sql/backends/monet5/wlr.c --- a/sql/backends/monet5/wlr.c +++ b/sql/backends/monet5/wlr.c @@ -29,6 +29,10 @@ #include "mal_client.h" #include "querylog.h" +#ifdef NATIVE_WIN32 +#include <sys/timeb.h> /* ftime */ +#endif + #define WLR_START 0 #define WLR_RUN 100 #define WLR_PAUSE 200 @@ -379,7 +383,6 @@ static void WLRprocessScheduler(void *arg) { Client cntxt = (Client) arg; int duration; - struct timeval clock; time_t clk; struct tm ctm; char clktxt[26]; @@ -396,8 +399,20 @@ WLRprocessScheduler(void *arg) MT_thread_setworking("sleeping"); duration = (wlc_beat? wlc_beat:1) * 1000 ; if( wlr_timelimit[0]){ - gettimeofday(&clock, NULL); +#ifdef NATIVE_WIN32 + struct timeb tb; + + ftime(&tb); + clk = tb.time; +#else + struct timeval clock; + + if(gettimeofday(&clock,NULL) == -1) { + mnstr_printf(GDKerr,"Unable to retrieve current time\n"); + return; + } clk = clock.tv_sec; +#endif ctm = *localtime(&clk); strftime(clktxt, 26, "%Y-%m-%dT%H:%M:%S.000",&ctm); mnstr_printf(cntxt->fdout,"#now %s tlimit %s\n",clktxt, wlr_timelimit); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list