home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trash / part01 / resource.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-22  |  1.7 KB  |  83 lines

  1. #include    <bsd43/sys/syscall.h>
  2. #include    <bsd43/sys/time.h>
  3. #include    <bsd43/sys/resource.h>
  4. #include    <stdio.h>
  5. #include    "res.h"
  6.  
  7. #define    USE_GETTIMEOFDAY    1
  8.  
  9. extern FILE            *outfp;
  10.  
  11. #if    USE_GETTIMEOFDAY
  12. static struct bsd43_timeval    starttd;
  13. static struct bsd43_timeval    stoptd;
  14. #else    /* USE_GETTIMEOFDAY */
  15. static struct bsd43_rusage    start;
  16. static struct bsd43_rusage    stop;
  17. #endif    /* USE_GETTIMEOFDAY */
  18.  
  19. int
  20. res_sys_start()
  21. {
  22. #if    USE_GETTIMEOFDAY
  23.     if (syscall(BSD43_SYS_gettimeofday, &starttd, (struct bsd43_timezone *)0) == -1)
  24.     {
  25.         vcouldnot("gettimeofday(): start");
  26.         return -1;
  27.     }
  28. #else    /* USE_GETTIMEOFDAY */
  29.     if (syscall(BSD43_SYS_getrusage, BSD43_RUSAGE_SELF, &start) == -1)
  30.     {
  31.         vcouldnot("getrusage(): start");
  32.         return -1;
  33.     }
  34. #endif    /* USE_GETTIMEOFDAY */
  35.  
  36.     return 0;
  37. }
  38.  
  39. int
  40. res_sys_stop()
  41. {
  42. #if    USE_GETTIMEOFDAY
  43.     if (syscall(BSD43_SYS_gettimeofday, &stoptd, (struct bsd43_timezone *)0) == -1)
  44.     {
  45.         vcouldnot("gettimeofday(): stop");
  46.         return -1;
  47.     }
  48. #else    /* USE_GETTIMEOFDAY */
  49.     if (syscall(BSD43_SYS_getrusage, BSD43_RUSAGE_SELF, &stop) == -1)
  50.     {
  51.         vcouldnot("getrusage(): stop");
  52.         return -1;
  53.     }
  54. #endif    /* USE_GETTIMEOFDAY */
  55.  
  56.     return 0;
  57. }
  58.  
  59. void
  60. res_print()
  61. {
  62.     fprintf
  63.     (
  64.         outfp,
  65.         " <Ds=%dus>",
  66. #if    USE_GETTIMEOFDAY
  67.         (stoptd.tv_sec - starttd.tv_sec) * 1000000 +
  68.         (stoptd.tv_usec - starttd.tv_usec)
  69. #else    /* USE_GETTIMEOFDAY */
  70.         (stop.ru_stime.tv_sec - start.ru_stime.tv_sec) * 1000000 +
  71.         (stop.ru_stime.tv_usec - start.ru_stime.tv_usec)
  72. #endif    /* USE_GETTIMEOFDAY */
  73.     );
  74.  
  75. #if    USE_GETTIMEOFDAY
  76.     stoptd.tv_sec = starttd.tv_sec;
  77.     stoptd.tv_usec = starttd.tv_usec;
  78. #else    /* USE_GETTIMEOFDAY */
  79.     stop.ru_stime.tv_sec = start.ru_stime.tv_sec;
  80.     stop.ru_stime.tv_usec = start.ru_stime.tv_usec;
  81. #endif    /* USE_GETTIMEOFDAY */
  82. }
  83.