home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / sps / part2 / prcpu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.5 KB  |  68 lines

  1. # include       "sps.h"
  2.  
  3. # ifdef BSD42
  4.  
  5. /* PRCPU - Print cpu time */
  6. prcpu ( time, utime )
  7.  
  8. register time_t                 time ;
  9. time_t                          utime ;
  10.  
  11. {
  12.     time += utime / 1000000 ;
  13.     utime %= 1000000 ;
  14.     if ( time < 0L )
  15.     {       /* Ignore negative times */
  16.         printf( "     " ) ;     
  17.         return ;
  18.     }
  19.     if ( time < 60L*10L )
  20.     {       /* Print as seconds if less than 1000 seconds */
  21.         printf( "%3d.%1d", (int)time, (int)utime/100000 ) ;
  22.         return ;
  23.     }
  24.     /* Print as minutes if less than 10 hours ; print as hours if less than
  25.        10 days, else print as days. */
  26.     if ( time < 60L*60L*10L )               
  27.         printf( "%3D M", time/60L ) ;
  28.     else if ( time < 24L*60L*60L*10L )
  29.         printf( "%3D H", time/60L/60L ) ;
  30.     else
  31.         printf( "%3D D", time/60L/60L/24L ) ;
  32. }
  33.  
  34. # else
  35.  
  36. /* PRCPU - Print cpu time */
  37. prcpu ( time )
  38.  
  39. register time_t                 time ;
  40.  
  41. {
  42.     extern struct info      Info ;
  43.  
  44.     if ( time < 0L )
  45.     {       /* Ignore negative times */
  46.         printf( "     " ) ;     
  47.         return ;
  48.     }
  49.     if ( time < Info.i_hz*60L*10L )
  50.     {       /* Less than 10 minutes */
  51.         printf( "%3D.%1D", time/Info.i_hz,
  52.             (time % Info.i_hz / (Info.i_hz/10L)) ) ;
  53.         return ;
  54.     }
  55.     /* If less than 10 hours, print as minutes */
  56.     time /= Info.i_hz ;
  57.     /* Print as minutes if less than 10 hours ; print as hours if less than
  58.        10 days, else print as days. */
  59.     if ( time < 60L*60L*10L )               
  60.         printf( "%3D M", time/60L ) ;
  61.     else if ( time < 24L*60L*60L*10L )
  62.         printf( "%3D H", time/60L/60L ) ;
  63.     else
  64.         printf( "%3D D", time/60L/60L/24L ) ;
  65. }
  66.  
  67. # endif
  68.