Permalink
Browse files

Fixes ram output for linux

  • Loading branch information...
1 parent f6d9e36 commit f02766411c0ba81b7fe093f4367741c25ecad65d @mothur-westcott mothur-westcott committed Jul 12, 2016
Showing with 10 additions and 20 deletions.
  1. +10 −19 source/mothurout.cpp
  2. +0 −1 source/mothurout.h
View
@@ -570,11 +570,16 @@ unsigned long long MothurOut::getTotalRAM() {
try {
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
- long pages = get_phys_pages();
- long page_size = sysconf(_SC_PAGE_SIZE);
- if ((page_size == -1) || (pages == -1))
+ #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE
+ /* This works on linux-gnu, solaris2 and cygwin. */
+ double pages = sysconf (_SC_PHYS_PAGES);
+ double pagesize = sysconf (_SC_PAGESIZE);
+ if (0 <= pages && 0 <= pagesize)
+ return pages * pagesize;
+ #else
mothurOut("[WARNING]: Cannot determine amount of RAM");
- return pages * page_size;
+ #endif
+
#elif defined (_WIN32)
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
@@ -587,28 +592,14 @@ unsigned long long MothurOut::getTotalRAM() {
return si.totalram * si.mem_unit;
#endif
+ return 0;
}
catch(exception& e) {
errorOut(e, "MothurOut", "getTotalRAM");
exit(1);
}
}
/***********************************************************************/
-unsigned long MothurOut::get_phys_pages () {
- unsigned long phys_pages = 0;
-#if (_SC_PAGE_SIZE)
- uint64_t mem;
- size_t len = sizeof(mem);
- sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
- phys_pages = mem/sysconf(_SC_PAGE_SIZE);
-#elif (_SC_PHYS_PAGES)
- phys_pages = sysconf(_SC_PHYS_PAGES);
-#else
- mothurOut("[WARNING]: Cannot determine number of physical pages\n");
-#endif
- return phys_pages;
-}
-/***********************************************************************/
int MothurOut::openOutputFileAppend(string fileName, ofstream& fileHandle){
try {
fileName = getFullPathName(fileName);
View
@@ -172,7 +172,6 @@ class MothurOut {
string mothurGetpid(int);
unsigned long long getRAMUsed();
unsigned long long getTotalRAM();
- unsigned long get_phys_pages();
string getStringFromVector(vector<string>&, string); //creates string like "v[0], v[1], ... v[n]" where ', ' is string.
string getStringFromVector(vector<int>&, string); //creates string like "v[0], v[1], ... v[n]" where ', ' is string.
string getStringFromVector(vector<double>&, string); //creates string like "v[0], v[1], ... v[n]" where ', ' is string.

0 comments on commit f027664

Please sign in to comment.