]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Possibility to use mallinfo (T.Kuhr)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 15 Jul 2004 16:02:11 +0000 (16:02 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 15 Jul 2004 16:02:11 +0000 (16:02 +0000)
STEER/AliMemoryWatcher.cxx
STEER/AliMemoryWatcher.h

index 40f4528ed670e9d86cfedfb0d6f3380b6644e39e..a4980ad270bbdae8e422c33167176ffc4d9de798 100644 (file)
@@ -44,6 +44,7 @@
 //*-- Author: Laurent Aphecetche(SUBATECH)
 // --- std system ---
 class assert ; 
+#include <malloc.h>
 // --- AliRoot header files ---
 #include "AliMemoryWatcher.h"
 // --- ROOT system ---
@@ -59,6 +60,7 @@ AliMemoryWatcher::AliMemoryWatcher(UInt_t maxsize)
 {
   //ctor
   fMAXSIZE=maxsize;
+  fUseMallinfo = true;
   fPID = gSystem->GetPid();
   sprintf(fCmd,"ps -h -p %d -o vsize,rssize",fPID);
   fX = new Int_t[fMAXSIZE];
@@ -75,6 +77,7 @@ AliMemoryWatcher::AliMemoryWatcher(const AliMemoryWatcher& mw):
 {
   //copy ctor
   fMAXSIZE = mw.fMAXSIZE ;
+  fUseMallinfo = mw.fUseMallinfo;
   fPID = mw.fPID ; 
   strcpy(fCmd, mw.fCmd) ; 
   fX = new Int_t[fMAXSIZE];
@@ -106,20 +109,30 @@ void AliMemoryWatcher::Watch(Int_t x)
       fTimer->Start(true);
       fTimer->Stop();
     }
-    static Int_t vsize, rssize;
-    static FILE* pipe = 0;
-    pipe = popen(fCmd,"r");
-    if ( pipe ) {
-    
-      fscanf(pipe,"%d %d",&vsize,&rssize);
-      
+    if ( fUseMallinfo ) {
+      static struct mallinfo meminfo;
+      meminfo = mallinfo();
       fX[fSize] = x ;
-      fVSIZE[fSize] = vsize ;
-      fRSSIZE[fSize] = rssize ;
+      fVSIZE[fSize] = (meminfo.hblkhd + meminfo.uordblks) / 1024;
+      fRSSIZE[fSize] =  meminfo.uordblks / 1024;
       fTIME[fSize] = fTimer->CpuTime();
       fSize++;
+    } else {
+      static Int_t vsize, rssize;
+      static FILE* pipe = 0;
+      pipe = popen(fCmd,"r");
+      if ( pipe ) {
+    
+       fscanf(pipe,"%d %d",&vsize,&rssize);
+      
+       fX[fSize] = x ;
+       fVSIZE[fSize] = vsize ;
+       fRSSIZE[fSize] = rssize ;
+       fTIME[fSize] = fTimer->CpuTime();
+       fSize++;
+      }
+      assert(pclose(pipe)!=-1);
     }
-    assert(pclose(pipe)!=-1);
     fTimer->Start(true);
   }
   else {
index 6b529f75d0f0a96397fc1b6916bf41cb600e4f52..ab7ef3e408372e4b99da457574e0296c2a0ba566 100644 (file)
@@ -50,6 +50,7 @@ public:
   AliMemoryWatcher(UInt_t maxsize=10000);
   AliMemoryWatcher(const AliMemoryWatcher& mw);
   ~AliMemoryWatcher() ;
+  void SetUseMallinfo(Bool_t use) { fUseMallinfo = use; }
   void Watch(Int_t x);
   
   UInt_t Size(void) const { return fSize; }
@@ -64,6 +65,7 @@ public:
   Int_t       Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
   AliMemoryWatcher & operator = (const AliMemoryWatcher &) { return *this; } 
 private:
+  Bool_t fUseMallinfo; // use mallinfo function instead of ps command
   Int_t fPID;          // PID of the process to watch
   char fCmd[1024];     // the command sent to the system to retrieve things ("ps .....")
   UInt_t fMAXSIZE;     // maximum size of arrays where the informationis stored