35 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
39 #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX || TE_PLATFORM == TE_PLATFORMCODE_AIX || TE_PLATFORM == TE_PLATFORMCODE_FREEBSD || TE_PLATFORM == TE_PLATFORMCODE_OPENBSD
44 #include <sys/resource.h>
46 #include <sys/sysctl.h>
47 #include <sys/types.h>
50 #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
54 #include <sys/sysctl.h>
57 #error "Unsuported plataform for physical memory checking"
69 unsigned long int freemem = 0;
71 #if TE_PLATFORM == TE_PLATFORMCODE_FREEBSD || TE_PLATFORM == TE_PLATFORMCODE_OPENBSD || TE_PLATFORM == TE_PLATFORMCODE_APPLE
74 std::size_t usermem_len =
sizeof(usermem);
76 int mib[2] = { CTL_HW, HW_USERMEM };
78 if(sysctl(mib, (2 *
sizeof(
int)), &usermem, &usermem_len, NULL, 0) == 0)
80 freemem =
static_cast<unsigned long int>(usermem);
84 throw Exception(
"Could not get free physical memory!");
87 #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
88 freemem =
static_cast<unsigned long int>( sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES) );
90 #elif TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
91 LPMEMORYSTATUS status_buffer =
new MEMORYSTATUS;
92 GlobalMemoryStatus(status_buffer);
93 freemem =
static_cast<unsigned long int>(status_buffer->dwAvailPhys);
96 #error "Unsuported plataform for physical memory checking"
104 unsigned long int totalmem = 0;
106 #if TE_PLATFORM == TE_PLATFORMCODE_FREEBSD || TE_PLATFORM == TE_PLATFORMCODE_OPENBSD || TE_PLATFORM == TE_PLATFORMCODE_APPLE
107 unsigned int physmem = 0;
109 std::size_t physmem_len =
sizeof(physmem);
111 int mib[2] = { CTL_HW, HW_PHYSMEM };
113 if(sysctl(mib, (2 *
sizeof(
int)), &physmem, &physmem_len, NULL, 0) == 0)
115 totalmem =
static_cast<unsigned long int>(physmem);
119 throw Exception(
"Could not get total physical memory!");
122 #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
123 totalmem =
static_cast<unsigned long int>( sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES) );
125 #elif TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
126 LPMEMORYSTATUS status_buffer =
new MEMORYSTATUS;
127 GlobalMemoryStatus(status_buffer);
128 totalmem =
static_cast<unsigned long int>(status_buffer->dwTotalPhys);
129 delete status_buffer;
131 #error "Unsuported plataform for physical memory checking"
139 unsigned long int usedmem = 0;
141 #if TE_PLATFORM == TE_PLATFORMCODE_FREEBSD || TE_PLATFORM == TE_PLATFORMCODE_OPENBSD
142 struct rusage rusageinfo;
143 getrusage( RUSAGE_SELF, &rusageinfo );
144 usedmem =
static_cast<unsigned long int>(1024 * rusageinfo.ru_maxrss);
146 #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
147 std::string pid, comm, state, ppid, pgrp, session, tty_nr,
148 tpgid, flags, minflt, cminflt, majflt, cmajflt,
149 utime, stime, cutime, cstime, priority, nice,
150 stringO, itrealvalue, starttime;
152 std::ifstream stat_stream(
"/proc/self/stat", std::ios_base::in);
154 stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
155 >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
156 >> utime >> stime >> cutime >> cstime >> priority >> nice
157 >> stringO >> itrealvalue >> starttime >> usedmem;
159 #elif TE_PLATFORM == TE_PLATFORMCODE_AIX || TE_PLATFORM == TE_PLATFORMCODE_APPLE
160 struct rusage rusageinfo;
161 getrusage(RUSAGE_SELF, &rusageinfo);
162 usedmem =
static_cast<unsigned long int>(1024 * rusageinfo.ru_maxrss);
164 #elif TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
165 LPMEMORYSTATUS status_buffer =
new MEMORYSTATUS;
166 GlobalMemoryStatus( status_buffer );
167 usedmem =
static_cast<unsigned long int>(status_buffer->dwTotalVirtual - status_buffer->dwAvailVirtual);
168 delete status_buffer;
171 #error "Unsuported plataform for virtual memory checking"
180 unsigned long int totalmem = 0;
182 #if (TE_PLATFORM == TE_PLATFORMCODE_FREEBSD) || (TE_PLATFORM == TE_PLATFORMCODE_OPENBSD) || (TE_PLATFORM == TE_PLATFORMCODE_APPLE) || (TE_PLATFORM == TE_PLATFORMCODE_LINUX)
185 if( getrlimit( RLIMIT_AS, &info ) == 0 )
187 totalmem = (
unsigned long int)info.rlim_max;
190 #elif TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
191 LPMEMORYSTATUS status_buffer =
new MEMORYSTATUS;
192 GlobalMemoryStatus( status_buffer );
193 totalmem = (
unsigned long int) status_buffer->dwTotalVirtual;
194 delete status_buffer;
197 #error
"Unsuported plataform for virtual memory checking"
205 unsigned int procnmb = 0;
207 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
208 SYSTEM_INFO siSysInfo;
209 GetSystemInfo(&siSysInfo);
210 procnmb =
static_cast<unsigned int>(siSysInfo.dwNumberOfProcessors);
212 #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX || TE_PLATFORM == TE_PLATFORMCODE_AIX || TE_PLATFORM == TE_PLATFORMCODE_APPLE
213 procnmb =
static_cast<unsigned int>(sysconf(_SC_NPROCESSORS_ONLN));
216 #error "ERROR: Unsupported platform"
226 char* varValuePtr = getenv(
"PATH");
228 std::string separator;
229 #if (TE_PLATFORM == TE_PLATFORMCODE_FREEBSD) || (TE_PLATFORM == TE_PLATFORMCODE_OPENBSD) || (TE_PLATFORM == TE_PLATFORMCODE_APPLE) || (TE_PLATFORM == TE_PLATFORMCODE_LINUX)
231 #elif TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
234 #error "Unsuported plataform for virtual memory checking"
239 Tokenize( std::string( varValuePtr ), paths, separator );
247 char* varValuePtr = getenv(
"LD_LIBRARY_PATH");
249 std::string separator;
250 #if (TE_PLATFORM == TE_PLATFORMCODE_FREEBSD) || (TE_PLATFORM == TE_PLATFORMCODE_OPENBSD) || (TE_PLATFORM == TE_PLATFORMCODE_APPLE) || (TE_PLATFORM == TE_PLATFORMCODE_LINUX)
252 #elif TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
255 #error "Unsuported plataform for virtual memory checking"
260 Tokenize( std::string( varValuePtr ), paths, separator );
Utility functions for dealing with strings.
void GetDecompostedPathEnvVar(std::vector< std::string > &paths)
Returns the system PATH enviroment variable, decomposed into directory names, or an empty vector if n...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
This file is a wrapper around platform specific include files.
unsigned int GetPhysProcNumber()
Returns the number of physical processors.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void GetDecompostedLDPathEnvVar(std::vector< std::string > &paths)
Returns the system LD_LIBRARY_PATH enviroment variable, decomposed into directory names...
unsigned long int GetFreePhysicalMemory()
Returns the amount of free physical memory (bytes).
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
unsigned long int GetTotalPhysicalMemory()
Returns the amount of total physical memory (bytes).
unsigned long int GetUsedVirtualMemory()
Returns the amount of used virtual memory (bytes) for the current process (physical + swapped)...
unsigned long int GetTotalVirtualMemory()
Returns the amount of total virtual memory (bytes) that can be claimed by the current process (physic...