X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=STEER%2FAliMemoryWatcher.cxx;h=63bb6e8cf6a53bda893dc2030b11f2794099769b;hb=105ab4d7ada955427d116260b1fda82ef5e4495b;hp=a4980ad270bbdae8e422c33167176ffc4d9de798;hpb=7406fd3c53bbfbfeb513d66f482b1700d5e44dd5;p=u%2Fmrichter%2FAliRoot.git diff --git a/STEER/AliMemoryWatcher.cxx b/STEER/AliMemoryWatcher.cxx index a4980ad270b..63bb6e8cf6a 100644 --- a/STEER/AliMemoryWatcher.cxx +++ b/STEER/AliMemoryWatcher.cxx @@ -13,6 +13,7 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ /* $Id$ */ + //_________________________________________________________________________ //Basic Memory Leak utility. // You can use this tiny class to *see* if your program is leaking. @@ -22,11 +23,11 @@ // 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 : @@ -42,52 +43,56 @@ // But by fitting the VSIZE by a pol1 under ROOT, you'll see right away // by how much your program is leaking. //*-- Author: Laurent Aphecetche(SUBATECH) + // --- std system --- -class assert ; -#include +#include +#ifdef NEVER +#include +#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(), + 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; - fUseMallinfo = true; - 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), + 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 ; - fUseMallinfo = mw.fUseMallinfo; - 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() { @@ -101,43 +106,48 @@ AliMemoryWatcher::~AliMemoryWatcher() //_____________________________________________________________________________ void AliMemoryWatcher::Watch(Int_t x) { + static ProcInfo_t meminfo; +#ifdef NEVER + static Char_t cmd[1024]=""; +#endif // Sets the point where CPU parameters have to be monitored if ( !fDisabled && fSize < fMAXSIZE ) { if ( fSize==0 ) { - assert(fTimer==0); fTimer = new TStopwatch; fTimer->Start(true); fTimer->Stop(); +#ifdef NEVER + if(!cmd[0]) + sprintf(cmd,"ps -h -p %d -o vsz,rss | grep -v VSZ",gSystem->GetPid()); +#endif } - if ( fUseMallinfo ) { - static struct mallinfo meminfo; - meminfo = mallinfo(); + gSystem->GetProcInfo(&meminfo); + fX[fSize] = x ; + fVSIZE[fSize] = meminfo.fMemVirtual / 1024; + fRSSIZE[fSize] = meminfo.fMemResident / 1024; + fTIME[fSize] = fTimer->CpuTime(); + fSize++; +#ifdef NEVER + Int_t vsize, rssize; + FILE* pipe = 0; + pipe = popen(cmd,"r"); + if ( pipe ) { + + fscanf(pipe,"%d %d",&vsize,&rssize); + fX[fSize] = x ; - fVSIZE[fSize] = (meminfo.hblkhd + meminfo.uordblks) / 1024; - fRSSIZE[fSize] = meminfo.uordblks / 1024; + fVSIZE[fSize] = vsize ; + fRSSIZE[fSize] = rssize ; 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); } + Int_t iclose=pclose(pipe); + assert(iclose!=-1); +#endif fTimer->Start(true); - } - else { + } else { fDisabled=true; - Error("watch", "I'm full !" ) ; + AliError("I'm full !" ) ; } } //_____________________________________________________________________________ @@ -211,7 +221,7 @@ AliMemoryWatcher::Frame(void) const } //_____________________________________________________________________________ Int_t -AliMemoryWatcher::Write(const char *, Int_t, Int_t) +AliMemoryWatcher::WriteToFile() { // Stores the graphs in a file if ( GraphVSIZE() ) GraphVSIZE()->Write("VSIZE",TObject::kOverwrite);