//*-- Author: Laurent Aphecetche(SUBATECH)
// --- std system ---
class assert ;
+#include <malloc.h>
// --- AliRoot header files ---
#include "AliMemoryWatcher.h"
// --- ROOT system ---
{
//ctor
fMAXSIZE=maxsize;
+ fUseMallinfo = true;
fPID = gSystem->GetPid();
sprintf(fCmd,"ps -h -p %d -o vsize,rssize",fPID);
fX = new Int_t[fMAXSIZE];
{
//copy ctor
fMAXSIZE = mw.fMAXSIZE ;
+ fUseMallinfo = mw.fUseMallinfo;
fPID = mw.fPID ;
strcpy(fCmd, mw.fCmd) ;
fX = new Int_t[fMAXSIZE];
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 {
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; }
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