source: icGREP/icgrep-devel/cudd-2.5.1/util/cpu_stats.c @ 5820

Last change on this file since 5820 was 4597, checked in by nmedfort, 4 years ago

Upload of the CUDD library.

File size: 3.1 KB
Line 
1/* LINTLIBRARY */
2
3#include "util.h"
4
5
6#ifdef BSD
7#include <sys/types.h>
8#include <sys/time.h>
9#include <sys/resource.h>
10
11#if defined(_IBMR2)
12#define etext _etext
13#define edata _edata
14#define end _end
15#endif
16
17extern int end, etext, edata;
18
19#endif
20
21void
22util_print_cpu_stats(FILE *fp)
23{
24#ifdef BSD
25    struct rusage rusage;
26    struct rlimit rlp;
27    long text, data, vm_limit, vm_soft_limit;
28    double user, system, scale;
29    char hostname[257];
30    long vm_text, vm_init_data, vm_uninit_data, vm_sbrk_data;
31
32    /* Get the hostname */
33    (void) gethostname(hostname, 256);
34    hostname[256] = '\0';               /* just in case */
35
36    /* Get the virtual memory sizes */
37    vm_text = (long) (((long) (&etext)) / 1024.0 + 0.5);
38    vm_init_data = (long) (((long) (&edata) - (long) (&etext)) / 1024.0 + 0.5);
39    vm_uninit_data = (long) (((long) (&end) - (long) (&edata)) / 1024.0 + 0.5);
40    vm_sbrk_data = (long) (((long) sbrk(0) - (long) (&end)) / 1024.0 + 0.5);
41
42    /* Get virtual memory limits */
43    (void) getrlimit(RLIMIT_DATA, &rlp);
44    vm_limit = (long) (rlp.rlim_max / 1024.0 + 0.5);
45    vm_soft_limit = (long) (rlp.rlim_cur / 1024.0 + 0.5);
46
47    /* Get usage stats */
48    (void) getrusage(RUSAGE_SELF, &rusage);
49    user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec/1.0e6;
50    system = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec/1.0e6;
51    scale = (user + system)*100.0;
52    if (scale == 0.0) scale = 0.001;
53
54    (void) fprintf(fp, "Runtime Statistics\n");
55    (void) fprintf(fp, "------------------\n");
56    (void) fprintf(fp, "Machine name: %s\n", hostname);
57    (void) fprintf(fp, "User time   %6.1f seconds\n", user);
58    (void) fprintf(fp, "System time %6.1f seconds\n\n", system);
59
60    text = (int) (rusage.ru_ixrss / scale + 0.5);
61    data = (int) ((rusage.ru_idrss + rusage.ru_isrss) / scale + 0.5);
62    (void) fprintf(fp, "Average resident text size       = %5ldK\n", text);
63    (void) fprintf(fp, "Average resident data+stack size = %5ldK\n", data);
64    (void) fprintf(fp, "Maximum resident size            = %5ldK\n\n",
65        rusage.ru_maxrss/2);
66    (void) fprintf(fp, "Virtual text size                = %5ldK\n",
67        vm_text);
68    (void) fprintf(fp, "Virtual data size                = %5ldK\n",
69        vm_init_data + vm_uninit_data + vm_sbrk_data);
70    (void) fprintf(fp, "    data size initialized        = %5ldK\n",
71        vm_init_data);
72    (void) fprintf(fp, "    data size uninitialized      = %5ldK\n",
73        vm_uninit_data);
74    (void) fprintf(fp, "    data size sbrk               = %5ldK\n",
75        vm_sbrk_data);
76    (void) fprintf(fp, "Virtual memory limit             = %5ldK (%ldK)\n\n",
77        vm_soft_limit, vm_limit);
78
79    (void) fprintf(fp, "Major page faults = %ld\n", rusage.ru_majflt);
80    (void) fprintf(fp, "Minor page faults = %ld\n", rusage.ru_minflt);
81    (void) fprintf(fp, "Swaps = %ld\n", rusage.ru_nswap);
82    (void) fprintf(fp, "Input blocks = %ld\n", rusage.ru_inblock);
83    (void) fprintf(fp, "Output blocks = %ld\n", rusage.ru_oublock);
84    (void) fprintf(fp, "Context switch (voluntary) = %ld\n", rusage.ru_nvcsw);
85    (void) fprintf(fp, "Context switch (involuntary) = %ld\n", rusage.ru_nivcsw);
86#else
87    (void) fprintf(fp, "Usage statistics not available\n");
88#endif
89}
Note: See TracBrowser for help on using the repository browser.