home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd3.lzh
/
SBPROLOG2.2
/
SIM
/
BUILTIN
/
time.c
< prev
next >
Wrap
Text File
|
1991-08-10
|
3KB
|
107 lines
/************************************************************************
* *
* The SB-Prolog System *
* Copyright SUNY at Stony Brook, 1986 *
* *
************************************************************************/
/*-----------------------------------------------------------------
SB-Prolog is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the SB-Prolog General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
SB-Prolog, but only under the conditions described in the
SB-Prolog General Public License. A copy of this license is
supposed to have been given to you along with SB-Prolog so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
------------------------------------------------------------------ */
/* time.c */
#ifndef OS9
#include <sys/time.h>
#include <sys/resource.h>
#else
#include <time.h>
#endif
#include "builtin.h"
b_CPUTIME() /* R1: miliseconds */
{
#ifndef OS9
struct rusage usage;
int msec;
getrusage(0, &usage);
msec = usage.ru_utime.tv_sec * 1000 + usage.ru_utime.tv_usec / 1000;
if (!unify(gregc(1), makeint(msec))) {Fail0;}
#else
#if 0 /* hmm... never seen this struct... stp 91/08/10 */
struct tms current_time;
times(¤t_time);
if (!unify(gregc(1),
makeint((int)(current_time.tms_utime+current_time.tms_stime))))
{Fail0;}
#else
if (!unify(gregc(1),
makeint((int)(clock()*1000/CLK_TCK))))
{Fail0;}
#endif
#endif
}
b_STATS() /* r1: code to indicate desired stat; r2: returned stat */
{
register word op1;
register pw top;
int stat;
#ifndef OS9
struct rusage usage;
#else
/* struct tms current_time; */
#endif
op1 = gregc(1); deref(op1);
switch ((int)(intval(op1))) {
case 0:
#ifndef OS9
getrusage(0, &usage);
stat = usage.ru_utime.tv_sec*1000 + usage.ru_utime.tv_usec/1000;
#else
#if 0
times(¤t_time);
stat = current_time.tms_utime+current_time.tms_stime;
#else
stat = clock();
#endif
#endif
break;
case 1: stat = maxmem; break; /* max available stack size */
case 2: stat = local_bottom -
((breg < ereg) ? breg : ereg - *(cpreg-5));
break; /* local stack in use */
case 3: stat = local_bottom-mlocaltop; /* local stack max used */
break;
case 4: stat = hreg-heap_bottom; break; /* heap stack used */
case 5: stat = mheaptop-heap_bottom; break; /* max heap used */
case 6: stat = maxpspace; break; /* max available perm space */
case 7: stat = ((int) curr_fence - (int) pspace)/4;
break; /* perm space in use */
case 8: stat = maxtrail; break; /* max available trail size */
case 9: stat = trail_bottom-trreg; break; /* trail stack in use */
case 10: stat = trail_bottom-mtrailtop; /* max trail stk used */
break;
case 11: stat = ((breg < ereg) ? breg : ereg - *(cpreg-5)) - hreg;
break;
default: stat = 0;
}
if (!unify(gregc(2), makeint(stat))) {Fail0;}
}