ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/utils/residentMem.c
Revision: 2759
Committed: Wed May 17 21:51:42 2006 UTC (18 years, 1 month ago) by tim
Content type: text/plain
File size: 1010 byte(s)
Log Message:
Adding single precision capabilities to c++ side

File Contents

# User Rev Content
1 gezelter 2024 #include <config.h>
2     #include <string.h>
3     #include <stdio.h>
4 gezelter 2029 #include <stdlib.h>
5     #ifdef __sgi
6     #include <unistd.h>
7     #endif
8 gezelter 2024
9 gezelter 2029 /*
10     * returns an estimate of the resident memory size in kB
11     */
12 tim 2759 RealType residentMem () {
13 gezelter 2024
14     FILE* procresults;
15     char buf[150];
16     char* foo;
17     long int myRSS, totRSS;
18 gezelter 2026 char pscommand[150];
19 gezelter 2027 char* psPath;
20 gezelter 2024
21 gezelter 2027 STR_DEFINE(psPath, PSCOMMAND );
22 gezelter 2028
23 tim 2263
24 gezelter 2028 strncpy(pscommand, psPath, strlen(psPath)+1);
25 gezelter 2024
26 gezelter 2029 #ifdef PSTYPE_IS_BSD
27 gezelter 2024 strcat(pscommand, " ax -o rss");
28     #else
29 gezelter 2029 #ifdef PSTYPE_IS_POSIX
30 gezelter 2024 strcat(pscommand, " -ef -o rss");
31 gezelter 2029 #else
32     printf("Unknown ps syntax!\n");
33 gezelter 2024 #endif
34 gezelter 2029 #endif
35 gezelter 2024
36 gezelter 2028 printf("doing %s\n", pscommand);
37    
38 gezelter 2024 procresults = popen(pscommand, "r");
39    
40     totRSS = 0;
41     while (!feof(procresults)) {
42     fgets( buf, 150, procresults);
43     if (!strcmp(buf, " RSS")) continue;
44    
45     foo = strtok(buf, " ,;\t");
46     myRSS = atoi(foo);
47     totRSS += myRSS;
48     }
49     pclose(procresults);
50    
51 gezelter 2029 #ifdef __sgi
52 tim 2263
53    
54 gezelter 2029 totRSS *= getpagesize() / 1024;
55     #endif
56    
57 tim 2263
58 tim 2041 totRSS *= 1024;
59 gezelter 2024 return(totRSS);
60    
61     }