From 88aebfd189cdbe2b329b62dbec4ff56d136e1664 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Thu, 3 Mar 2011 10:10:53 +0000 Subject: [PATCH] add getMemoryUsage --- common/clitkMemoryUsage.cxx | 40 ++++++++++++++++++++++--------------- common/clitkMemoryUsage.h | 1 + 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/common/clitkMemoryUsage.cxx b/common/clitkMemoryUsage.cxx index 295ac29..b588c41 100644 --- a/common/clitkMemoryUsage.cxx +++ b/common/clitkMemoryUsage.cxx @@ -24,22 +24,30 @@ void clitk::PrintMemory(bool verbose, std::string s) { #if CLITK_MEMORY_INFO == 1 if (verbose) { - //sleep(1); // wait to refresh memory ? need to let the system refresh the mem - int * entries = new int; - sg_process_stats * stat = new sg_process_stats; - int i=0; - stat = sg_get_process_stats(entries); - // Search the current pid in the list of processes - while (stat[i].pid != getpid()) i++; - // Display total memory size - if (s != "") std::cout << "==> " << s << ": "; - static int previous=0; - int mem = stat[i].proc_size/1000/1000; // in Mb - std::cout << mem << "Mb (" << mem-previous << "Mb)" << std::endl; - previous = mem; - //DD(stat[i].proc_resident/1000/1000); - //DD(stat[i].pid); - } + static double previous=0; + double mem = GetMemoryUsageInMb(); + if (s != "") std::cout << "==> " << s << ": "; + std::cout << mem << "Mb (" << mem-previous << "Mb)" << std::endl; + previous = mem; + //DD(stat[i].proc_resident/1000/1000); + //DD(stat[i].pid); + } +#endif + } + +double clitk::GetMemoryUsageInMb() +{ +#if CLITK_MEMORY_INFO == 1 + //sleep(1); // wait to refresh memory ? need to let the system refresh the mem + int * entries = new int; + sg_process_stats * stat = new sg_process_stats; + int i=0; + stat = sg_get_process_stats(entries); + // Search the current pid in the list of processes + while (stat[i].pid != getpid()) i++; + // Display total memory size + double mem = stat[i].proc_size/1000/1000; // in Mb + return mem; #endif } diff --git a/common/clitkMemoryUsage.h b/common/clitkMemoryUsage.h index d514aff..38a982e 100644 --- a/common/clitkMemoryUsage.h +++ b/common/clitkMemoryUsage.h @@ -31,6 +31,7 @@ namespace clitk { void PrintMemory(bool verbose=true, std::string s="") ; + double GetMemoryUsageInMb() ; } // end namespace //-------------------------------------------------------------------- -- 2.47.1