| 1 |
|
#include <config.h> |
| 2 |
|
#include <string.h> |
| 3 |
|
#include <stdio.h> |
| 4 |
+ |
#include <stdlib.h> |
| 5 |
+ |
#ifdef __sgi |
| 6 |
+ |
#include <unistd.h> |
| 7 |
+ |
#endif |
| 8 |
|
|
| 9 |
+ |
#define to_string( s ) # s |
| 10 |
+ |
#define STR_DEFINE(t, s) t = to_string(s) |
| 11 |
+ |
|
| 12 |
+ |
/* |
| 13 |
+ |
* returns an estimate of the resident memory size in kB |
| 14 |
+ |
*/ |
| 15 |
|
double residentMem () { |
| 16 |
|
|
| 17 |
|
FILE* procresults; |
| 19 |
|
char* foo; |
| 20 |
|
long int myRSS, totRSS; |
| 21 |
|
char pscommand[150]; |
| 22 |
+ |
char* psPath; |
| 23 |
|
|
| 24 |
< |
strncpy(pscommand, PSCOMMAND, strlen(PSCOMMAND)); |
| 24 |
> |
STR_DEFINE(psPath, PSCOMMAND ); |
| 25 |
> |
|
| 26 |
> |
// null terminated string is one longer.... |
| 27 |
> |
strncpy(pscommand, psPath, strlen(psPath)+1); |
| 28 |
|
|
| 29 |
< |
#if PSTYPE == BSD |
| 29 |
> |
#ifdef PSTYPE_IS_BSD |
| 30 |
|
strcat(pscommand, " ax -o rss"); |
| 31 |
|
#else |
| 32 |
+ |
#ifdef PSTYPE_IS_POSIX |
| 33 |
|
strcat(pscommand, " -ef -o rss"); |
| 34 |
+ |
#else |
| 35 |
+ |
printf("Unknown ps syntax!\n"); |
| 36 |
|
#endif |
| 37 |
+ |
#endif |
| 38 |
|
|
| 39 |
+ |
printf("doing %s\n", pscommand); |
| 40 |
+ |
|
| 41 |
|
procresults = popen(pscommand, "r"); |
| 42 |
|
|
| 43 |
|
totRSS = 0; |
| 51 |
|
} |
| 52 |
|
pclose(procresults); |
| 53 |
|
|
| 54 |
+ |
#ifdef __sgi |
| 55 |
+ |
// Damn IRIX machines uses pages for RSS and pagesize is variable |
| 56 |
+ |
// depending on version of the OS. |
| 57 |
+ |
totRSS *= getpagesize() / 1024; |
| 58 |
+ |
#endif |
| 59 |
+ |
|
| 60 |
|
return(totRSS); |
| 61 |
|
|
| 62 |
|
} |