#include "memusage.h"#include "converse.h"#include <stdio.h>#include <sys/types.h>#include <unistd.h>#include <malloc.h>Go to the source code of this file.
Functions | |
| unsigned long | memusage_mstats () |
| unsigned long | memusage_mallinfo () |
| unsigned long | memusage_ps () |
| unsigned long | memusage_proc_self_stat () |
| unsigned long | memusage (const char **source) |
|
|
Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved. Definition at line 142 of file memusage.C. References memusage_mallinfo(), memusage_mstats(), memusage_proc_self_stat(), and memusage_ps(). Referenced by main::main(), memusage_kB(), and memusage_MB(). 00142 {
00143
00144 unsigned long memtotal = 0;
00145 const char* s = "ERROR";
00146
00147 if ( ! CmiMemoryIs(CMI_MEMORY_IS_OS) ) {
00148 memtotal = CmiMemoryUsage(); s = "CmiMemoryUsage";
00149 }
00150
00151 #if defined(WIN32) && !defined(__CYGWIN__) && CHARM_VERSION > 60102
00152 if ( ! memtotal ) {
00153 memtotal = CmiMemoryUsage(); s = "GetProcessMemoryInfo";
00154 }
00155 #endif
00156
00157 if ( ! memtotal ) {
00158 memtotal = memusage_proc_self_stat(); s = "/proc/self/stat";
00159 }
00160
00161 #if CMK_BLUEGENEP
00162 if( ! memtotal) { memtotal = memusage_bgp(); s="mallinfo on BG/P"; }
00163 #endif
00164
00165 if ( ! memtotal ) { memtotal = memusage_mstats(); s = "mstats"; }
00166
00167 if ( ! memtotal ) { memtotal = memusage_mallinfo(); s = "mallinfo"; }
00168
00169 if ( ! memtotal ) { memtotal = memusageinit::memusage_sbrk(); s = "sbrk"; }
00170
00171 if ( ! memtotal ) { memtotal = memusage_ps(); s = "ps"; }
00172
00173 if ( ! memtotal ) { memtotal = CmiMemoryUsage(); s = "CmiMemoryUsage"; }
00174
00175 if ( ! memtotal ) s = "nothing";
00176
00177 if ( source ) *source = s;
00178
00179 return memtotal;
00180
00181 }
|
|
|
Definition at line 66 of file memusage.C. Referenced by memusage(). 00066 {
00067 struct mallinfo mi = mallinfo();
00068 // unsigned long memtotal = mi.usmblks + mi.uordblks + mi.hblkhd;
00069 unsigned long memtotal = (unsigned int) mi.uordblks;
00070 unsigned long memtotal2 = (unsigned int) mi.usmblks;
00071 memtotal2 += (unsigned int) mi.hblkhd;
00072 if ( memtotal2 > memtotal ) memtotal = memtotal2;
00073
00074 // printf("mallinfo %d %d %d\n", mi.usmblks, mi.uordblks, mi.hblkhd);
00075
00076 return memtotal;
00077 }
|
|
|
Definition at line 58 of file memusage.C. Referenced by memusage(). 00058 { return 0; }
|
|
|
Definition at line 115 of file memusage.C. Referenced by memusage(). 00115 {
00116 #ifdef NO_PS
00117 return 0;
00118 #else
00119 static int failed_once = 0;
00120 if ( failed_once ) return 0; // no point in retrying
00121
00122 FILE *f = fopen("/proc/self/stat","r");
00123 if ( ! f ) { failed_once = 1; return 0; }
00124 for ( int i=0; i<22; ++i ) fscanf(f,"%*s");
00125 #ifdef NAMD_CUDA
00126 // skip vss, next value is rss in pages
00127 fscanf(f,"%*s");
00128 #endif
00129 unsigned long vsz = 0; // should remain 0 on failure
00130 fscanf(f,"%lu",&vsz);
00131 fclose(f);
00132 #ifdef NAMD_CUDA
00133 vsz *= sysconf(_SC_PAGESIZE);
00134 #endif
00135 if ( ! vsz ) failed_once = 1;
00136 // printf("/proc/self/stat reports %d MB\n", vsz/(1024*1024));
00137 return vsz;
00138 #endif
00139 }
|
|
|
Definition at line 84 of file memusage.C. Referenced by memusage(). 00084 {
00085 #ifdef NO_PS
00086 return 0;
00087 #else
00088 char pscmd[100];
00089 #ifdef NAMD_CUDA
00090 sprintf(pscmd, "/bin/ps -o rss= -p %d", getpid());
00091 #else
00092 sprintf(pscmd, "/bin/ps -o vsz= -p %d", getpid());
00093 #endif
00094 unsigned long vsz = 0;
00095 FILE *p = popen(pscmd, "r");
00096 if ( p ) {
00097 fscanf(p, "%ld", &vsz);
00098 pclose(p);
00099 }
00100 return ( vsz * (unsigned long) 1024 );
00101 #endif
00102 }
|
1.3.9.1