auxlry.c

00001 /* File:      auxlry.c
00002 ** Author(s): Warren, Sagonas, Xu
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** 
00007 ** XSB is free software; you can redistribute it and/or modify it under the
00008 ** terms of the GNU Library General Public License as published by the Free
00009 ** Software Foundation; either version 2 of the License, or (at your option)
00010 ** any later version.
00011 ** 
00012 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00013 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00015 ** more details.
00016 ** 
00017 ** You should have received a copy of the GNU Library General Public License
00018 ** along with XSB; if not, write to the Free Software Foundation,
00019 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 **
00021 ** $Id: auxlry.c,v 1.20 2005/12/17 02:46:28 dwarren Exp $
00022 ** 
00023 */
00024 
00025 
00026 #include "xsb_config.h"
00027 
00028 #include <stdio.h>
00029 
00030 /* take care of the time.h problems */
00031 #include "xsb_time.h"
00032 
00033 #ifndef WIN_NT
00034 #include <sys/resource.h>
00035 
00036 #ifdef SOLARIS
00037 /*--- Include the following to bypass header file inconcistencies ---*/
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 /* My version of gdb gets confused when I set a breakpoint in include
00162    files within emuloop.  Thus the use of gdb_dummy() */
00163 
00164 void gdb_dummy(void) 
00165   {
00166   }

Generated on Wed Jul 26 13:30:39 2006 for XSB by  doxygen 1.4.5