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 >
Text File  |  1991-08-10  |  3KB  |  107 lines

  1. /************************************************************************
  2. *                                    *
  3. *    The SB-Prolog System                        *
  4. *    Copyright SUNY at Stony Brook, 1986                *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25. /* time.c */
  26.  
  27. #ifndef OS9
  28. #include <sys/time.h>
  29. #include <sys/resource.h>
  30. #else
  31. #include <time.h>
  32. #endif
  33. #include "builtin.h"
  34.  
  35. b_CPUTIME()   /* R1: miliseconds */
  36. {
  37. #ifndef OS9
  38.     struct rusage usage;
  39.     int msec;
  40.  
  41.     getrusage(0, &usage);
  42.     msec =  usage.ru_utime.tv_sec * 1000 + usage.ru_utime.tv_usec / 1000;
  43.     if (!unify(gregc(1), makeint(msec))) {Fail0;}
  44. #else
  45. #if 0 /* hmm... never seen this struct... stp 91/08/10 */
  46.     struct tms current_time;
  47.  
  48.     times(¤t_time);
  49.     if (!unify(gregc(1),
  50.                 makeint((int)(current_time.tms_utime+current_time.tms_stime))))
  51.         {Fail0;}
  52. #else
  53.     if (!unify(gregc(1),
  54.                 makeint((int)(clock()*1000/CLK_TCK))))
  55.         {Fail0;}
  56. #endif
  57. #endif
  58. }
  59.  
  60. b_STATS()   /* r1: code to indicate desired stat; r2: returned stat */
  61. {
  62.     register word op1;
  63.     register pw top;
  64.     int stat;
  65. #ifndef OS9
  66.     struct rusage usage;
  67. #else
  68. /*    struct tms current_time; */
  69. #endif
  70.  
  71.     op1 = gregc(1); deref(op1);
  72.     switch ((int)(intval(op1))) {
  73.         case 0:
  74. #ifndef OS9
  75.         getrusage(0, &usage);
  76.         stat = usage.ru_utime.tv_sec*1000 + usage.ru_utime.tv_usec/1000;
  77. #else
  78. #if 0
  79.     times(¤t_time);
  80.     stat = current_time.tms_utime+current_time.tms_stime;
  81. #else
  82.     stat = clock();
  83. #endif
  84. #endif
  85.         break;
  86.     case 1: stat = maxmem; break; /* max available stack size */
  87.     case 2:    stat = local_bottom -
  88.                 ((breg < ereg) ? breg : ereg - *(cpreg-5));
  89.         break; /* local stack in use */
  90.     case 3: stat = local_bottom-mlocaltop;  /* local stack max used */
  91.         break;
  92.     case 4: stat = hreg-heap_bottom; break; /* heap stack used */
  93.     case 5: stat = mheaptop-heap_bottom; break; /* max heap used */
  94.     case 6: stat = maxpspace; break; /* max available perm space */
  95.     case 7: stat = ((int) curr_fence - (int) pspace)/4;
  96.         break; /* perm space in use */
  97.     case 8: stat = maxtrail; break; /* max available trail size */
  98.     case 9: stat = trail_bottom-trreg; break; /* trail stack in use */
  99.     case 10: stat = trail_bottom-mtrailtop; /* max trail stk used */
  100.         break;
  101.     case 11: stat = ((breg < ereg) ? breg : ereg - *(cpreg-5)) - hreg;
  102.         break;
  103.     default: stat = 0;
  104.     }
  105.     if (!unify(gregc(2), makeint(stat))) {Fail0;}
  106. }
  107.