1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 // Origin: marian.ivanov@cern.ch
20 // Make a log file for the CPU and Memory usage
23 // Make a set of stamps in the code in the place of interest
26 // AliSysInfo::AddStamp("Start");
28 // loader->UnloadRecPoints();
29 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
32 // The log file can be transformed to the tree - to make a visualization
33 // See $ALICE_ROOT/macros/PlotSysInfo.C as an example
36 #include <Riostream.h>
38 #include "TStopwatch.h"
42 #include "TTimeStamp.h"
43 #include "AliSysInfo.h"
45 //#include "TMemStatManager.h" //USE IFDEF
50 AliSysInfo* AliSysInfo::fInstance=0;
52 AliSysInfo::AliSysInfo():
60 fTimer = new TStopwatch;
61 fSysWatch = new fstream("syswatch.log", ios_base::out|ios_base::trunc);
63 //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
66 (*fSysWatch) <<"hname"<<"/C:" // hname - hostname
67 <<"sname"<<"/C:" // stamp name
68 <<"id0"<<"/I:" // 0 id
69 <<"id1"<<"/I:" // 1 id
70 <<"id2"<<"/I:" // 1 id
71 <<"first"<<"/I:" // first stamp
73 <<"stampSec"<<"/I:" // time - time stamp in seconds
74 <<"mi.fMemUsed"<<"/F:" // system info
75 <<"mi.fSwapUsed"<<"/F:" //
76 <<"cI.fUser"<<"/F:" //
79 <<"pI.fMemResident"<<"/F:" // process info
80 <<"pI.fMemVirtual"<<"/F:" //
81 <<"pI.fCpuUser"<<"/F:" //
82 <<"pI.fCpuSys"<<"/F:" //
84 <<"stampOldSec"<<"/I:" // time - time stamp in seconds
85 <<"miOld.fMemUsed"<<"/F:" // system info - previous
86 <<"miOld.fSwapUsed"<<"/F:" //
87 <<"cIOld.fUser"<<"/F:" //
88 <<"cIOld.fSys"<<"/F:" //
90 <<"pIOld.fMemResident"<<"/F:" // process info -previous
91 <<"pIOld.fMemVirtual"<<"/F:" //
92 <<"pIOld.fCpuUser"<<"/F:" //
93 <<"pIOld.fCpuSys"<<"/F" //
101 AliSysInfo * AliSysInfo::Instance(){
106 fInstance = new AliSysInfo;
112 void AliSysInfo::AddStamp(const char *sname, Int_t id0, Int_t id1, Int_t id2){
121 gSystem->GetCpuInfo(&cpuInfo, 10);
122 gSystem->GetMemInfo(&memInfo);
123 gSystem->GetProcInfo(&procInfo);
124 procInfo.fMemVirtual/=1024; //size in MBy
125 procInfo.fMemResident/=1024; //size in MBy
127 const char * hname = gSystem->HostName();
129 static Int_t entry=0;
130 static Int_t first=stamp.GetSec();
132 static TTimeStamp stampOld;
133 static CpuInfo_t cpuInfoOld;
134 static MemInfo_t memInfoOld;
135 static ProcInfo_t procInfoOld;
138 (*(Instance()->fSysWatch)) << hname <<"\t" // hname - hostname
139 << sname <<"\t" // stamp name
143 << first <<"\t" // first stamp
145 << stamp.GetSec()<<"\t" // time - time stamp in seconds
146 << memInfo.fMemUsed<<"\t" // system info
147 << memInfo.fSwapUsed<<"\t" //
148 << cpuInfo.fUser <<"\t" //
149 << cpuInfo.fSys <<"\t" //
151 << procInfo.fMemResident<<"\t" // process info
152 << procInfo.fMemVirtual<<"\t" //
153 << procInfo.fCpuUser<<"\t" //
154 << procInfo.fCpuSys<<"\t" //
156 << stampOld.GetSec()<<"\t" // time - time stamp in seconds
157 << memInfoOld.fMemUsed<<"\t" // system info - previous
158 << memInfoOld.fSwapUsed<<"\t" //
159 << cpuInfoOld.fUser <<"\t" //
160 << cpuInfoOld.fSys <<"\t" //
162 << procInfoOld.fMemResident<<"\t" // process info -previous
163 << procInfoOld.fMemVirtual<<"\t" //
164 << procInfoOld.fCpuUser<<"\t" //
165 << procInfoOld.fCpuSys<<"\t" //
168 cpuInfoOld = cpuInfo;
169 memInfoOld = memInfo;
170 procInfoOld= procInfo;
172 // if (fInstance->fMemStat) fInstance->fMemStat->AddStamps(sname);
173 for (Int_t icallback=0; icallback<Instance()->fNCallBack; icallback++){
174 Instance()->fCallBackFunc[icallback](sname);
180 TTree * AliSysInfo::MakeTree(const char *lname){
181 // char * lname = "syswatch.log"
182 TTree * tree = new TTree;
183 tree->ReadFile(lname);
184 tree->SetAlias("deltaT","stampSec-stampOldSec");
185 tree->SetAlias("T","stampSec-first");
186 tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)");
187 tree->SetAlias("VM","pI.fMemVirtual");
192 Bool_t AliSysInfo::Contain(const char * str1, const char * str2){
197 return str.Contains(str2);
202 void AliSysInfo::OpenMemStat(){
206 //USE IFDEF if MEMSTAT ENABLED
207 // Instance()->fMemStat = TMemStatManager::GetInstance();
208 // Instance()->fMemStat->SetAutoStamp(10000000, 10000000,1000000);
209 // Instance()->fMemStat->Enable();
212 void AliSysInfo::CloseMemStat(){
216 //USE IFDEF if MEMSTAT ENABLED
217 //if (Instance()->fMemStat == TMemStatManager::GetInstance()) Instance()->fMemStat->Close();
218 //Instance()->fMemStat=0;
223 void AliSysInfo::AddCallBack(StampCallback_t callback){
225 // add cal back function
227 AliSysInfo *info = Instance();
228 if (!info->fCallBackFunc)
229 info->fCallBackFunc = new StampCallback_t[100];
230 info->fCallBackFunc[info->fNCallBack]=callback;