// if ( nevents % x == 0 )
// {
// // take a sample every x events
-// memwatcher.watch(nevents);
+// memwatcher.Watch(nevents);
// }
// }
// TFile f("out.root","RECREATE");
-// memwatcher.write();
+// memwatcher.Write();
// f.Close();
// In the output root file you'll get 3 graphs representing
// the evolAliPHOSon, as a function of the number of events, of :
//*-- Author: Laurent Aphecetche(SUBATECH)
// --- std system ---
class assert ;
+#ifdef __APPLE__
+#include <stdlib.h>
+#else
+#include <malloc.h>
+#endif
// --- AliRoot header files ---
+#include "AliLog.h"
#include "AliMemoryWatcher.h"
// --- ROOT system ---
#include "TSystem.h"
#include "TGraph.h"
#include "TH2.h"
#include "TStopwatch.h"
+#include "TError.h"
ClassImp(AliMemoryWatcher)
//_____________________________________________________________________________
-AliMemoryWatcher::AliMemoryWatcher(UInt_t maxsize)
+AliMemoryWatcher::AliMemoryWatcher(UInt_t maxsize) :
+ TObject(),
+ fUseMallinfo(kTRUE),
+ fPID(gSystem->GetPid()),
+ fMAXSIZE(maxsize),
+ fSize(0),
+ fX(new Int_t[fMAXSIZE]),
+ fVSIZE(new Int_t[fMAXSIZE]),
+ fRSSIZE(new Int_t[fMAXSIZE]),
+ fTIME(new Double_t[fMAXSIZE]),
+ fTimer(0),
+ fDisabled(kFALSE)
{
+ //
//ctor
- fMAXSIZE=maxsize;
- fPID = gSystem->GetPid();
+ //
sprintf(fCmd,"ps -h -p %d -o vsize,rssize",fPID);
- fX = new Int_t[fMAXSIZE];
- fVSIZE = new Int_t[fMAXSIZE];
- fRSSIZE = new Int_t[fMAXSIZE];
- fTIME = new Double_t[fMAXSIZE];
- fSize=0;
- fDisabled=false;
- fTimer=0;
}
+
//_____________________________________________________________________________
AliMemoryWatcher::AliMemoryWatcher(const AliMemoryWatcher& mw):
- TObject(mw)
+ TObject(mw),
+ fUseMallinfo(mw.fUseMallinfo),
+ fPID(mw.fPID),
+ fMAXSIZE(mw.fMAXSIZE),
+ fSize(0),
+ fX(new Int_t[fMAXSIZE]),
+ fVSIZE(new Int_t[fMAXSIZE]),
+ fRSSIZE(new Int_t[fMAXSIZE]),
+ fTIME(new Double_t[fMAXSIZE]),
+ fTimer(0),
+ fDisabled(kFALSE)
{
//copy ctor
- fMAXSIZE = mw.fMAXSIZE ;
- fPID = mw.fPID ;
strcpy(fCmd, mw.fCmd) ;
- fX = new Int_t[fMAXSIZE];
- fVSIZE = new Int_t[fMAXSIZE];
- fRSSIZE = new Int_t[fMAXSIZE];
- fTIME = new Double_t[fMAXSIZE];
- fSize=0;
- fDisabled=false;
- fTimer=0;
}
+
//_____________________________________________________________________________
AliMemoryWatcher::~AliMemoryWatcher()
{
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 ) {
+#ifdef __linux
+ 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
+ AliFatal("Please SetUseMallinfo to kFALSE on this system");
+#endif
+ } 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 {
fDisabled=true;
- Error("watch", "I'm full !" ) ;
+ AliError("I'm full !" ) ;
}
}
//_____________________________________________________________________________
return h;
}
//_____________________________________________________________________________
-void
-AliMemoryWatcher::Write(void)
+Int_t
+AliMemoryWatcher::WriteToFile()
{
// Stores the graphs in a file
if ( GraphVSIZE() ) GraphVSIZE()->Write("VSIZE",TObject::kOverwrite);
if ( GraphRSSIZE() ) GraphRSSIZE() ->Write("RSSIZE",TObject::kOverwrite);
if ( GraphTIME() ) GraphTIME()->Write("TIME",TObject::kOverwrite);
+ return 0;
}