home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / sps3 / part01 / prcpu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-08  |  1.6 KB  |  72 lines

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