home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / rusage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-07  |  1.9 KB  |  59 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1986, 1988 Regents of the University of California
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /* routine to print neat program statistics */
  9.  
  10. #include <sys/time.h>
  11. #include <sys/resource.h>
  12.  
  13. void DoPrintUsage()
  14. {
  15.     struct rusage ru;
  16.     double ut, st, up, sp, tot;
  17.  
  18.     getrusage(RUSAGE_SELF, &ru);
  19.  
  20.     ut = (ru.ru_utime.tv_sec) + (ru.ru_utime.tv_usec / 1e06);
  21.     st = (ru.ru_stime.tv_sec) + (ru.ru_stime.tv_usec / 1e06);
  22.     tot = ut + st;
  23.     up = (ut / tot) * 100.0;
  24.     sp = (st / tot) * 100.0;
  25.  
  26.     printf("\nUser Time:   %6.2f sec. (%5.1f%%)\n", ut, up);
  27.     printf("System Time: %6.2f sec. (%5.1f%%)\n", st, sp);
  28.     printf("Total Time:  %6.2f sec. (%5.1f%%)\n", tot, up + sp);
  29.  
  30.     printf("Maximum resident set size: %d Kbytes\n", ru.ru_maxrss);
  31.     printf("Shared memory size:  %d Kbyte*seconds\n", ru.ru_ixrss);
  32.     printf("Unshared data size:  %d Kbytes*seconds\n", ru.ru_idrss);
  33.     printf("Unshared stack size: %d Kbytes*seconds\n", ru.ru_isrss);
  34.  
  35.     printf("Page faults without io: %d\n", ru.ru_minflt);
  36.     printf("Page faults with io:    %d\n", ru.ru_majflt);
  37.  
  38.     printf("Number of times swapped: %d\n", ru.ru_nswap);
  39.  
  40.     printf("Number of file system inputs:  %d\n", ru.ru_inblock);
  41.     printf("Number of file system outputs: %d\n", ru.ru_oublock);
  42.  
  43.     printf("Number of ipc messages sent:     %d\n", ru.ru_msgsnd);
  44.     printf("Number of ipc messages received: %d\n", ru.ru_msgrcv);
  45.  
  46.     printf("Number of signals received: %d\n", ru.ru_nsignals);
  47.  
  48.     tot = ru.ru_nvcsw + ru.ru_nivcsw;
  49.     up = (ru.ru_nvcsw / tot) * 100.0;
  50.     sp = (ru.ru_nivcsw / tot) * 100.0;
  51.  
  52.     printf("Number of voluntary context switches:   %4d (%5.1f%%)\n", 
  53.        ru.ru_nvcsw, up);
  54.     printf("Number of involuntary context switches: %4d (%5.1f%%)\n", 
  55.        ru.ru_nivcsw, sp);
  56.     printf("Total number of context switches:       %4d (%5.1f%%)\n", 
  57.        (int) tot, up + sp);
  58. }
  59.