src/util/cpu_stats.c File Reference

#include <stdio.h>
#include "util.h"
#include <sys/types.h>
#include <sys/time.h>
Include dependency graph for cpu_stats.c:

Go to the source code of this file.

Functions

void util_print_cpu_stats (FILE *fp)

Variables

int end
int etext
int edata

Function Documentation

void util_print_cpu_stats ( FILE *  fp  ) 

Definition at line 30 of file cpu_stats.c.

00031 {
00032 #if HAVE_SYS_RESOURCE_H && !defined(__CYGWIN32__)
00033     struct rusage rusage;
00034 #ifdef RLIMIT_DATA
00035     struct rlimit rlp;
00036     long vm_limit, vm_soft_limit;
00037 #endif
00038     long text, data;
00039     double user, system, scale;
00040     char hostname[257];
00041 #if !defined(__APPLE__)
00042     long vm_text, vm_init_data, vm_uninit_data, vm_sbrk_data;
00043 #endif
00044 
00045     /* Get the hostname */
00046     (void) gethostname(hostname, 256);
00047     hostname[256] = '\0';               /* just in case */
00048 
00049 #if !defined(__APPLE__)
00050     /* Get the virtual memory sizes */
00051     vm_text = (long) (((long) (&etext)) / 1024.0 + 0.5);
00052     vm_init_data = (long) (((&edata) - (&etext)) / 1024.0 + 0.5);
00053     vm_uninit_data = (long) (((&end) - (&edata)) / 1024.0 + 0.5);
00054     vm_sbrk_data = (long) ((sizeof(char) * ((char *) sbrk(0) - (char *) (&end))) / 1024.0 + 0.5);
00055 #endif
00056 
00057     /* Get virtual memory limits */
00058 #ifdef RLIMIT_DATA /* In HP-UX, with cc, this constant does not exist */
00059     (void) getrlimit(RLIMIT_DATA, &rlp);
00060     vm_limit = (long) (rlp.rlim_max / 1024.0 + 0.5);
00061     vm_soft_limit = (long) (rlp.rlim_cur / 1024.0 + 0.5);
00062 #endif
00063 
00064     /* Get usage stats */
00065     (void) getrusage(RUSAGE_SELF, &rusage);
00066     user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec/1.0e6;
00067     system = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec/1.0e6;
00068     scale = (user + system)*100.0;
00069     if (scale == 0.0) scale = 0.001;
00070 
00071     (void) fprintf(fp, "Runtime Statistics\n");
00072     (void) fprintf(fp, "------------------\n");
00073     (void) fprintf(fp, "Machine name: %s\n", hostname);
00074     (void) fprintf(fp, "User time   %6.1f seconds\n", user);
00075     (void) fprintf(fp, "System time %6.1f seconds\n\n", system);
00076 
00077     text = (long) (rusage.ru_ixrss / scale + 0.5);
00078     data = (long) ((rusage.ru_idrss + rusage.ru_isrss) / scale + 0.5);
00079     (void) fprintf(fp, "Average resident text size       = %5ldK\n", text);
00080     (void) fprintf(fp, "Average resident data+stack size = %5ldK\n", data);
00081     (void) fprintf(fp, "Maximum resident size            = %5ldK\n\n",
00082         rusage.ru_maxrss/2);
00083 #if !defined(__APPLE__)
00084     (void) fprintf(fp, "Virtual text size                = %5ldK\n",
00085         vm_text);
00086     (void) fprintf(fp, "Virtual data size                = %5ldK\n",
00087         vm_init_data + vm_uninit_data + vm_sbrk_data);
00088     (void) fprintf(fp, "    data size initialized        = %5ldK\n",
00089         vm_init_data);
00090     (void) fprintf(fp, "    data size uninitialized      = %5ldK\n",
00091         vm_uninit_data);
00092     (void) fprintf(fp, "    data size sbrk               = %5ldK\n",
00093         vm_sbrk_data);
00094 #endif
00095     /* In some platforms, this constant does not exist */
00096 #ifdef RLIMIT_DATA
00097     (void) fprintf(fp, "Virtual memory limit             = %5ldK (%ldK)\n\n",
00098         vm_soft_limit, vm_limit);
00099 #endif
00100     (void) fprintf(fp, "Major page faults = %ld\n", rusage.ru_majflt);
00101     (void) fprintf(fp, "Minor page faults = %ld\n", rusage.ru_minflt);
00102     (void) fprintf(fp, "Swaps = %ld\n", rusage.ru_nswap);
00103     (void) fprintf(fp, "Input blocks = %ld\n", rusage.ru_inblock);
00104     (void) fprintf(fp, "Output blocks = %ld\n", rusage.ru_oublock);
00105     (void) fprintf(fp, "Context switch (voluntary) = %ld\n", rusage.ru_nvcsw);
00106     (void) fprintf(fp, "Context switch (involuntary) = %ld\n", rusage.ru_nivcsw);
00107 #else /* Do not have sys/resource.h */
00108     (void) fprintf(fp, "Usage statistics not available\n");
00109 #endif
00110 }


Variable Documentation

int edata
int end
int etext

Generated on Tue Jan 12 13:57:28 2010 for glu-2.2 by  doxygen 1.6.1