#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 156 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(). 00156 {
00157
00158 unsigned long memtotal = 0;
00159 const char* s = "ERROR";
00160
00161 if ( ! CmiMemoryIs(CMI_MEMORY_IS_OS) ) {
00162 memtotal = CmiMemoryUsage(); s = "CmiMemoryUsage";
00163 }
00164
00165 #if CMK_BLUEGENEQ
00166 if( ! memtotal) { memtotal = memusage_bgq(); s="Kernel_GetMemorySize on BG/Q"; }
00167 #endif
00168
00169 #if CMK_BLUEGENEP
00170 if( ! memtotal) { memtotal = memusage_bgp(); s="mallinfo on BG/P"; }
00171 #endif
00172
00173 #if defined(WIN32) && !defined(__CYGWIN__) && CHARM_VERSION > 60102
00174 if ( ! memtotal ) {
00175 memtotal = CmiMemoryUsage(); s = "GetProcessMemoryInfo";
00176 }
00177 #endif
00178
00179 if ( ! memtotal ) {
00180 memtotal = memusage_proc_self_stat(); s = "/proc/self/stat";
00181 }
00182
00183 if ( ! memtotal ) { memtotal = memusage_mstats(); s = "mstats"; }
00184
00185 if ( ! memtotal ) { memtotal = memusage_mallinfo(); s = "mallinfo"; }
00186
00187 if ( ! memtotal ) { memtotal = memusageinit::memusage_sbrk(); s = "sbrk"; }
00188
00189 if ( ! memtotal ) { memtotal = memusage_ps(); s = "ps"; }
00190
00191 if ( ! memtotal ) { memtotal = CmiMemoryUsage(); s = "CmiMemoryUsage"; }
00192
00193 if ( ! memtotal ) s = "nothing";
00194
00195 if ( source ) *source = s;
00196
00197 return memtotal;
00198
00199 }
|
|
|
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 129 of file memusage.C. Referenced by memusage(). 00129 {
00130 #ifdef NO_PS
00131 return 0;
00132 #else
00133 static int failed_once = 0;
00134 if ( failed_once ) return 0; // no point in retrying
00135
00136 FILE *f = fopen("/proc/self/stat","r");
00137 if ( ! f ) { failed_once = 1; return 0; }
00138 for ( int i=0; i<22; ++i ) fscanf(f,"%*s");
00139 #ifdef NAMD_CUDA
00140 // skip vss, next value is rss in pages
00141 fscanf(f,"%*s");
00142 #endif
00143 unsigned long vsz = 0; // should remain 0 on failure
00144 fscanf(f,"%lu",&vsz);
00145 fclose(f);
00146 #ifdef NAMD_CUDA
00147 vsz *= sysconf(_SC_PAGESIZE);
00148 #endif
00149 if ( ! vsz ) failed_once = 1;
00150 // printf("/proc/self/stat reports %d MB\n", vsz/(1024*1024));
00151 return vsz;
00152 #endif
00153 }
|
|
|
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