]> Creatis software - clitk.git/commitdiff
Debug libstatgrab
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 14 Mar 2017 16:31:16 +0000 (17:31 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 14 Mar 2017 16:31:16 +0000 (17:31 +0100)
With previous commits, we have to use libstatgrab version >=0.90 now

cmake/build_opt.cmake
common/clitkMemoryUsage.cxx

index 1ed1fa52cae3a3d77079b1a0e7d76695d7fba700..54a35317f71a5373d213f1f3d52b152ae0869f59 100644 (file)
@@ -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)
index a8be21ae478db0c76f3ff33c42d525d60c9592d1..9cc75d0acce73059b2aba6a083059624e9af66d4 100644 (file)
@@ -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;