From: tbaudier Date: Tue, 14 Mar 2017 16:31:16 +0000 (+0100) Subject: Debug libstatgrab X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=34637c8712feac5cf12c8920b6d0c1690918dd47;p=clitk.git Debug libstatgrab With previous commits, we have to use libstatgrab version >=0.90 now --- diff --git a/cmake/build_opt.cmake b/cmake/build_opt.cmake index 1ed1fa5..54a3531 100644 --- a/cmake/build_opt.cmake +++ b/cmake/build_opt.cmake @@ -20,7 +20,7 @@ endif(BUILD_DOXYGEN) # Compilation options option(CLITK_EXPERIMENTAL "Enable experimental software and features" OFF) mark_as_advanced(CLITK_EXPERIMENTAL) -option(CLITK_MEMORY_INFO "Enable memory info (need libstatgrab)" OFF) +option(CLITK_MEMORY_INFO "Enable memory info (need libstatgrab >= v.0.90)" OFF) mark_as_advanced(CLITK_MEMORY_INFO) option(CLITK_BUILD_TOOLS "Build command-line tools" OFF) option(CLITK_BUILD_SEGMENTATION "Build command-line segmentation tools" OFF) diff --git a/common/clitkMemoryUsage.cxx b/common/clitkMemoryUsage.cxx index a8be21a..9cc75d0 100644 --- a/common/clitkMemoryUsage.cxx +++ b/common/clitkMemoryUsage.cxx @@ -42,14 +42,24 @@ double clitk::GetMemoryUsageInMb() { #if CLITK_MEMORY_INFO == 1 //sleep(1); // wait to refresh memory ? need to let the system refresh the mem - size_t * entries = new size_t; - sg_process_stats * stat = new sg_process_stats; + size_t entries; + sg_process_stats *stat; int i=0; - stat = sg_get_process_stats(entries); + sg_init(1); + + stat = sg_get_process_stats(&entries); + if(stat == NULL) + return 0.0; + // Search the current pid in the list of processes - while (stat[i].pid != getpid()) i++; + while (stat->pid != getpid() && i < entries) + { + ++i; + ++stat; + } + // Display total memory size - double mem = stat[i].proc_resident/1000/1000; // in MB + double mem = stat->proc_resident/1000/1000; // in MB return mem; #else return 0.0;