#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.
◆ memusage()
unsigned long memusage |
( |
const char ** |
source = 0 | ) |
|
Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.
Definition at line 158 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().
160 unsigned long memtotal = 0;
161 const char* s =
"ERROR";
163 if ( ! CmiMemoryIs(CMI_MEMORY_IS_OS) ) {
164 memtotal = CmiMemoryUsage(); s =
"CmiMemoryUsage";
168 if( ! memtotal) { memtotal = memusage_bgq(); s=
"Kernel_GetMemorySize on BG/Q"; }
172 if( ! memtotal) { memtotal = memusage_bgp(); s=
"mallinfo on BG/P"; }
175 #if defined(WIN32) && !defined(__CYGWIN__) 177 memtotal = CmiMemoryUsage(); s =
"GetProcessMemoryInfo";
189 if ( ! memtotal ) { memtotal = memusageinit::memusage_sbrk(); s =
"sbrk"; }
191 if ( ! memtotal ) { memtotal =
memusage_ps(); s =
"ps"; }
193 if ( ! memtotal ) { memtotal = CmiMemoryUsage(); s =
"CmiMemoryUsage"; }
195 if ( ! memtotal ) s =
"nothing";
197 if ( source ) *source = s;
199 #if NODEGROUP_FORCE_REGISTER unsigned long memusage_mallinfo()
unsigned long memusage_ps()
unsigned long memusage_proc_self_stat()
unsigned long memusage_mstats()
◆ memusage_mallinfo()
unsigned long memusage_mallinfo |
( |
| ) |
|
Definition at line 68 of file memusage.C.
Referenced by memusage().
69 struct mallinfo mi = mallinfo();
71 unsigned long memtotal = (
unsigned int) mi.uordblks;
72 unsigned long memtotal2 = (
unsigned int) mi.usmblks;
73 memtotal2 += (
unsigned int) mi.hblkhd;
74 if ( memtotal2 > memtotal ) memtotal = memtotal2;
◆ memusage_mstats()
unsigned long memusage_mstats |
( |
| ) |
|
|
inline |
◆ memusage_proc_self_stat()
unsigned long memusage_proc_self_stat |
( |
| ) |
|
|
inline |
Definition at line 131 of file memusage.C.
Referenced by memusage().
135 static int failed_once = 0;
136 if ( failed_once )
return 0;
138 FILE *f = fopen(
"/proc/self/stat",
"r");
139 if ( ! f ) { failed_once = 1;
return 0; }
140 for (
int i=0; i<22; ++i ) fscanf(f,
"%*s");
141 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC) 145 unsigned long vsz = 0;
146 fscanf(f,
"%lu",&vsz);
148 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC) 149 vsz *= sysconf(_SC_PAGESIZE);
151 if ( ! vsz ) failed_once = 1;
◆ memusage_ps()
unsigned long memusage_ps |
( |
| ) |
|
|
inline |
Definition at line 86 of file memusage.C.
Referenced by memusage().
91 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC) 92 sprintf(pscmd,
"/bin/ps -o rss= -p %d", getpid());
94 sprintf(pscmd,
"/bin/ps -o vsz= -p %d", getpid());
96 unsigned long vsz = 0;
97 FILE *p = popen(pscmd,
"r");
99 fscanf(p,
"%ld", &vsz);
102 return ( vsz * (
unsigned long) 1024 );