Callback function for additional information about the stamp (Marian)
[u/mrichter/AliRoot.git] / STEER / AliSysInfo.cxx
index 332e58320e6e64df7874b73169bd871872a2bf7b..fe746e4471e37891521ea61084472b265e5067c7 100644 (file)
  **************************************************************************/
 
 
+//
+// Origin:  marian.ivanov@cern.ch
+//
+//  Make   a log file for the CPU and Memory usage
+//  
+//  The typical usage:
+//  Make a set of stamps in the code in the place of interest
+//  e.g. 
+//
+//  AliSysInfo::AddStamp("Start");
+//
+//  loader->UnloadRecPoints();
+//    AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
+//
+
+// The log file can be transformed to the tree - to make a visualization
+// See $ALICE_ROOT/macros/PlotSysInfo.C as an example
+
+
 #include <Riostream.h>
 #include "AliLog.h"
 #include "TStopwatch.h"
@@ -23,6 +42,8 @@
 #include "TTimeStamp.h"
 #include "AliSysInfo.h"
 
+//#include "TMemStatManager.h"  //USE IFDEF
+
 
 ClassImp(AliSysInfo)
 
@@ -31,15 +52,22 @@ AliSysInfo* AliSysInfo::fInstance=0;
 AliSysInfo::AliSysInfo():
     TObject(),
     fSysWatch(0),
-    fTimer(0)    
+    fTimer(0),
+    fMemStat(0),
+    fCallBackFunc(0),
+    fNCallBack(0)
 {
   fTimer = new TStopwatch;
   fSysWatch  = new fstream("syswatch.log", ios_base::out|ios_base::trunc);
+
   //hname/C:sname/C:sec/I:mI.fMemUsed/F:mI.fSwapUsed/F:pI.fMemResident/F:pI.fMemVirtual/F:cI.fUser/F:cI.fSys/F:cI.fCpuUser/F:pI.fCpuSys/F
 
 
   (*fSysWatch) <<"hname"<<"/C:"               // hname - hostname  
                <<"sname"<<"/C:"              // stamp name
+               <<"id0"<<"/I:"                // 0 id
+               <<"id1"<<"/I:"                // 1 id
+               <<"id2"<<"/I:"                // 1 id
                <<"first"<<"/I:"              // first stamp
     //
               <<"stampSec"<<"/I:"         // time  - time stamp in seconds
@@ -81,20 +109,11 @@ AliSysInfo * AliSysInfo::Instance(){
 }
 
 
-void AliSysInfo::AddStamp(const char *stamp){
+void AliSysInfo::AddStamp(const char *sname, Int_t id0, Int_t id1, Int_t id2){
   //
   // 
   //
-  Instance()->Print(stamp);
-}
-
-
-void AliSysInfo::Print(Option_t* option ) const{
-  //
-  // 
   //
-  char sname[1000];
-  sprintf(sname,"n-%s",option);
   TTimeStamp stamp;
   CpuInfo_t  cpuInfo;
   MemInfo_t  memInfo;
@@ -102,6 +121,9 @@ void AliSysInfo::Print(Option_t* option ) const{
   gSystem->GetCpuInfo(&cpuInfo, 10);
   gSystem->GetMemInfo(&memInfo);
   gSystem->GetProcInfo(&procInfo);
+  procInfo.fMemVirtual*=0.001;  //size in MBy
+  procInfo.fMemResident*=0.001;  //size in MBy
+
   const char * hname = gSystem->HostName();
 
   static Int_t entry=0;
@@ -113,9 +135,12 @@ void AliSysInfo::Print(Option_t* option ) const{
   static ProcInfo_t procInfoOld;  
 
 
-  (*fSysWatch) << hname   <<"\t"               // hname - hostname  
+  (*(Instance()->fSysWatch)) << hname   <<"\t"               // hname - hostname  
                << sname    <<"\t"              // stamp name
-               << first    <<"\t"              // first stamp
+               << id0      <<"\t"
+               << id1      <<"\t"
+               << id2      <<"\t"
+               << first    <<"\t"              // first stamp               
                //
               << stamp.GetSec()<<"\t"         // time  - time stamp in seconds
               << memInfo.fMemUsed<<"\t"       // system info 
@@ -142,7 +167,12 @@ void AliSysInfo::Print(Option_t* option ) const{
   stampOld   = stamp;
   cpuInfoOld = cpuInfo;
   memInfoOld = memInfo;
-  procInfoOld= procInfo; 
+  procInfoOld= procInfo;
+
+  //  if (fInstance->fMemStat) fInstance->fMemStat->AddStamps(sname);
+  for (Int_t icallback=0; icallback<Instance()->fNCallBack; icallback++){
+    Instance()->fCallBackFunc[icallback](sname);
+  }
   entry++;
 }
 
@@ -152,7 +182,51 @@ TTree * AliSysInfo::MakeTree(const char *lname){
   TTree * tree = new TTree;
   tree->ReadFile(lname);
   tree->SetAlias("deltaT","stampSec-stampOldSec");
-  tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)*0.001");
+  tree->SetAlias("T","stampSec-first");
+  tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)");
+  tree->SetAlias("VM","pI.fMemVirtual");
   return tree;
 }
 
+
+Bool_t AliSysInfo::Contain(const char * str1, const char * str2){
+  //
+  //
+  //
+  TString str(str1);
+  return str.Contains(str2);
+}
+
+
+
+void AliSysInfo::OpenMemStat(){
+  //
+  //
+  //
+  //USE IFDEF if MEMSTAT ENABLED  
+  //  Instance()->fMemStat = TMemStatManager::GetInstance();
+  //   Instance()->fMemStat->SetAutoStamp(10000000, 10000000,1000000);
+  //   Instance()->fMemStat->Enable();  
+}
+
+void AliSysInfo::CloseMemStat(){
+  //
+  //
+  //
+  //USE IFDEF if MEMSTAT ENABLED
+  //if (Instance()->fMemStat  == TMemStatManager::GetInstance()) Instance()->fMemStat->Close();
+  //Instance()->fMemStat=0;
+}
+
+
+
+void AliSysInfo::AddCallBack(StampCallback_t callback){
+  //
+  // add cal back function
+  //
+  AliSysInfo *info =  Instance();
+  if (!info->fCallBackFunc)
+    info->fCallBackFunc = new StampCallback_t[100];
+  info->fCallBackFunc[info->fNCallBack]=callback;
+  info->fNCallBack++;
+}