00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "xsb_config.h"
00027
00028 #include <stdio.h>
00029
00030
00031 #include "xsb_time.h"
00032
00033 #ifndef WIN_NT
00034 #include <sys/resource.h>
00035
00036 #ifdef SOLARIS
00037
00038 extern int getrusage();
00039 extern int gettimeofday();
00040 #endif
00041
00042 #ifdef HP700
00043 #include <sys/syscall.h>
00044 extern int syscall();
00045 #define getrusage(T, USAGE) syscall(SYS_getrusage, T, USAGE);
00046 #endif
00047
00048 #endif
00049
00050 #ifdef WIN_NT
00051 #include "windows.h"
00052 #endif
00053
00054
00055
00056 double cpu_time(void)
00057 {
00058 double time_sec;
00059
00060 #if defined(WIN_NT)
00061 #ifndef _MSC_VER
00062 #define ULONGLONG unsigned long long
00063 #else
00064 #define ULONGLONG __int64
00065 #endif
00066
00067 static int win_version = -1;
00068
00069 if (win_version == -1) {
00070 OSVERSIONINFO winv;
00071 winv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00072 GetVersionEx(&winv);
00073 win_version = winv.dwPlatformId;
00074 }
00075
00076 if (win_version == VER_PLATFORM_WIN32_NT) {
00077 HANDLE thisproc;
00078 FILETIME creation, exit, kernel, user;
00079 ULONGLONG lkernel, luser;
00080 double stime, utime;
00081
00082 thisproc = GetCurrentProcess();
00083 GetProcessTimes(thisproc,&creation,&exit,&kernel,&user);
00084
00085 lkernel = ((ULONGLONG) kernel.dwHighDateTime << 32) +
00086 kernel.dwLowDateTime;
00087 luser = ((ULONGLONG) user.dwHighDateTime << 32) +
00088 user.dwLowDateTime;
00089
00090 stime = lkernel / 1.0e7;
00091 utime = luser / 1.0e7;
00092
00093 time_sec = stime + utime;
00094
00095 } else {
00096 time_sec = ( clock() / CLOCKS_PER_SEC);
00097 }
00098
00099 #else
00100 struct rusage usage;
00101
00102 getrusage(RUSAGE_SELF, &usage);
00103 time_sec = (float)usage.ru_utime.tv_sec +
00104 (float)usage.ru_utime.tv_usec / 1000000.0;
00105 #endif
00106
00107 return time_sec;
00108 }
00109
00110
00111
00112 void get_date(int *year, int *month, int *day,
00113 int *hour, int *minute, int *second)
00114 {
00115 #ifdef WIN_NT
00116 SYSTEMTIME SystemTime;
00117 GetSystemTime(&SystemTime);
00118 *year = SystemTime.wYear;
00119 *month = SystemTime.wMonth;
00120 *day = SystemTime.wDay;
00121 *hour = SystemTime.wHour;
00122 *minute = SystemTime.wMinute;
00123 *second = SystemTime.wSecond;
00124 #else
00125 #ifdef HAVE_GETTIMEOFDAY
00126 struct timeval tv;
00127 struct tm *tm;
00128
00129 gettimeofday(&tv,NULL);
00130 tm = gmtime(&tv.tv_sec);
00131 *year = tm->tm_year;
00132 if (*year < 1900)
00133 *year += 1900;
00134 *month = tm->tm_mon + 1;
00135 *day = tm->tm_mday;
00136 *hour = tm->tm_hour;
00137 *minute = tm->tm_min;
00138 *second = tm->tm_sec;
00139 #endif
00140 #endif
00141 }
00142
00143
00144
00145 double real_time(void)
00146 {
00147 #if defined(WIN_NT)
00148 double value = ((float) clock() / CLOCKS_PER_SEC);
00149 #else
00150 double value;
00151 struct timeval tvs;
00152
00153 gettimeofday(&tvs, 0);
00154 value = tvs.tv_sec + 0.000001 * tvs.tv_usec;
00155 #endif
00156 return value;
00157 }
00158
00159
00160
00161
00162
00163
00164 void gdb_dummy(void)
00165 {
00166 }