5 * Revision 1.1.1.1 1996/02/15 17:49:31 mclareni
10 CERN PROGLIB# Z007 TIMEST .VERSION KERNFOR 4.38 931108
11 ORIG. 01/03/85 FCA, mod 03/11/93 GF
14 #include <sys\types.h>
16 #include <sys/types.h>
20 #include <sys/times.h>
21 #include <sys/param.h>
23 #include <sys/resource.h>
26 #ifndef CLOCKS_PER_SEC
27 #define CLOCKS_PER_SEC CLK_TCK
32 #define RLIMIT_CPU 0 /* For HP-UX... */
35 #define RLIM_INFINITY 0x7fffffff /* For HP-UX... */
38 #if defined(CERNLIB_QSYSBSD)||defined(CERNLIB_QMVMI)||defined(CERNLIB_QMVAOS)
46 #define HZ 1./CLOCKS_PER_SEC
50 #if defined(CERNLIB_QMDOS)
52 #define sectim 1./timsec
54 double timfac = 1./CLOCKS_PER_SEC;
55 double timsec = (double) 0x7fffffff/CLOCKS_PER_SEC;
60 /**************************************************************************\
62 * For some reason 'clock()' returns elapsed time on at least the AXP
63 * systems. Substitute the routine 'ntclock()' for 'clock()'.
65 \**************************************************************************/
72 #if !defined(CERNLIB_QMDOS)
76 static time_t timstart, timlast;
77 static int tml_init = 1;
80 #if defined(CERNLIB_QX_SC)
81 #define timest timest_
86 #if defined(CERNLIB_QXCAPT)
93 /* local routine called by timst, and time_init */
94 static void time_st(timl)
97 #if !defined(CERNLIB_QMDOS)
101 #if !defined(CERNLIB_QMDOS)
102 timstart = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
104 #if defined(CERNLIB_QMDOS)
106 timstart= (long)((time(NULL)&0xfffff)*sectim) * timsec
107 + (double)(clock()*timfac);
117 /* local routine to start by default */
118 static void time_init()
120 #if !defined(CERNLIB_QMDOS)
121 struct rlimit rlimit;
127 #if !defined(CERNLIB_QMDOS)
128 if (getrlimit(RLIMIT_CPU, &rlimit)==0) {
129 if ( rlimit.rlim_cur != RLIM_INFINITY )
130 maxtime = (float) rlimit.rlim_cur;
141 #if !defined(CERNLIB_QMDOS)
142 struct rlimit rlimit;
148 /* get maximum time allowed by system, and do not allow more */
150 #if !defined(CERNLIB_QMDOS)
151 if (getrlimit(RLIMIT_CPU, &rlimit)==0) {
152 maxtime = (float) rlimit.rlim_cur;
153 maxtime = ( maxtime > *timl ) ? *timl : maxtime;
163 CERN PROGLIB# Z007 TIMEX .VERSION KERNFOR 4.38 931108
174 #if !defined(CERNLIB_QMDOS)
176 timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
178 #if defined(CERNLIB_QMDOS)
180 timnow= (long)((time(NULL)&0xfffff)*sectim) * timsec
181 + (double)(clock()*timfac);
186 *tx = (float) (timnow - timstart) / HZ;
194 CERN PROGLIB# Z007 TIMED .VERSION KERNFOR 4.38 931108
205 #if !defined(CERNLIB_QMDOS)
207 timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
209 #if defined(CERNLIB_QMDOS)
211 timnow= (long)((time(NULL)&0xfffff)*sectim) * timsec
212 + (double)(clock()*timfac);
217 *td = (float) (timnow - timlast) / HZ;
226 CERN PROGLIB# Z007 TIMEL .VERSION KERNFOR 4.38 931108
237 #if !defined(CERNLIB_QMDOS)
239 timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
241 #if defined(CERNLIB_QMDOS)
243 timnow= (long)((time(NULL)&0xfffff)*sectim) * timsec
244 + (double)(clock()*timfac);
249 *tl = timlim - (float) (timnow - timstart) / HZ;
260 /**************************************************************************\
261 * ntclock.c -- function to return sum of user and kernel time
263 * For some reason 'clock()' returns elapsed time on at least the AXP
264 * systems. Call native WIN32 routines to get process CPU time, and
265 * return in the same (weird) units defined by 'clock()'.
267 \**************************************************************************/
277 FILETIME ftKernel, ftUser, ftCreate, ftExit;
279 static HANDLE hProcess = 0;
284 hProcess = GetCurrentProcess();
286 ret = GetProcessTimes (hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser);
288 ret = GetLastError ();
289 printf ("\n* Error on GetProcessTimes in ntclock() 0x%lx", (int)ret);
294 * Process times are returned in a 64-bit structure, as the number of
295 * 100 nanosecond ticks since 1 January 1601. User mode and kernel mode
296 * times for this process are in separate 64-bit structures.
297 * To convert to floating point seconds, we will:
299 * Convert sum of high 32-bit quantities to 64-bit float
301 * Add low 32-bit tick counts
302 * Divide by 10,000,000 to convert to seconds
303 * Convert to 'clock_t' value in "clock ticks"
306 tTotal = ftKernel.dwHighDateTime + ftUser.dwHighDateTime;
307 tTotal = tTotal * 4294967296.0;
308 tTotal = tTotal + (ftKernel.dwLowDateTime + ftUser.dwLowDateTime);
309 tTotal = tTotal * 1.0E-7;
310 cTotal = tTotal * CLOCKS_PER_SEC;
317 /*> END <----------------------------------------------------------*/