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():
58 fTimer = new TStopwatch;
59 fSysWatch = new fstream("syswatch.log", ios_base::out|ios_base::trunc);
61 //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
64 (*fSysWatch) <<"hname"<<"/C:" // hname - hostname
65 <<"sname"<<"/C:" // stamp name
66 <<"id0"<<"/I:" // 0 id
67 <<"id1"<<"/I:" // 1 id
68 <<"id2"<<"/I:" // 1 id
69 <<"first"<<"/I:" // first stamp
71 <<"stampSec"<<"/I:" // time - time stamp in seconds
72 <<"mi.fMemUsed"<<"/F:" // system info
73 <<"mi.fSwapUsed"<<"/F:" //
74 <<"cI.fUser"<<"/F:" //
77 <<"pI.fMemResident"<<"/F:" // process info
78 <<"pI.fMemVirtual"<<"/F:" //
79 <<"pI.fCpuUser"<<"/F:" //
80 <<"pI.fCpuSys"<<"/F:" //
82 <<"stampOldSec"<<"/I:" // time - time stamp in seconds
83 <<"miOld.fMemUsed"<<"/F:" // system info - previous
84 <<"miOld.fSwapUsed"<<"/F:" //
85 <<"cIOld.fUser"<<"/F:" //
86 <<"cIOld.fSys"<<"/F:" //
88 <<"pIOld.fMemResident"<<"/F:" // process info -previous
89 <<"pIOld.fMemVirtual"<<"/F:" //
90 <<"pIOld.fCpuUser"<<"/F:" //
91 <<"pIOld.fCpuSys"<<"/F" //
99 AliSysInfo * AliSysInfo::Instance(){
104 fInstance = new AliSysInfo;
110 void AliSysInfo::AddStamp(const char *sname, Int_t id0, Int_t id1, Int_t id2){
119 gSystem->GetCpuInfo(&cpuInfo, 10);
120 gSystem->GetMemInfo(&memInfo);
121 gSystem->GetProcInfo(&procInfo);
122 const char * hname = gSystem->HostName();
124 static Int_t entry=0;
125 static Int_t first=stamp.GetSec();
127 static TTimeStamp stampOld;
128 static CpuInfo_t cpuInfoOld;
129 static MemInfo_t memInfoOld;
130 static ProcInfo_t procInfoOld;
133 (*(Instance()->fSysWatch)) << hname <<"\t" // hname - hostname
134 << sname <<"\t" // stamp name
138 << first <<"\t" // first stamp
140 << stamp.GetSec()<<"\t" // time - time stamp in seconds
141 << memInfo.fMemUsed<<"\t" // system info
142 << memInfo.fSwapUsed<<"\t" //
143 << cpuInfo.fUser <<"\t" //
144 << cpuInfo.fSys <<"\t" //
146 << procInfo.fMemResident<<"\t" // process info
147 << procInfo.fMemVirtual<<"\t" //
148 << procInfo.fCpuUser<<"\t" //
149 << procInfo.fCpuSys<<"\t" //
151 << stampOld.GetSec()<<"\t" // time - time stamp in seconds
152 << memInfoOld.fMemUsed<<"\t" // system info - previous
153 << memInfoOld.fSwapUsed<<"\t" //
154 << cpuInfoOld.fUser <<"\t" //
155 << cpuInfoOld.fSys <<"\t" //
157 << procInfoOld.fMemResident<<"\t" // process info -previous
158 << procInfoOld.fMemVirtual<<"\t" //
159 << procInfoOld.fCpuUser<<"\t" //
160 << procInfoOld.fCpuSys<<"\t" //
163 cpuInfoOld = cpuInfo;
164 memInfoOld = memInfo;
165 procInfoOld= procInfo;
167 // if (fInstance->fMemStat) fInstance->fMemStat->AddStamps(sname);
173 TTree * AliSysInfo::MakeTree(const char *lname){
174 // char * lname = "syswatch.log"
175 TTree * tree = new TTree;
176 tree->ReadFile(lname);
177 tree->SetAlias("deltaT","stampSec-stampOldSec");
178 tree->SetAlias("T","stampSec-first");
179 tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)*0.001");
180 tree->SetAlias("VM","pI.fMemVirtual*0.001");
185 Bool_t AliSysInfo::Contain(const char * str1, const char * str2){
190 return str.Contains(str2);
195 void AliSysInfo::OpenMemStat(){
199 //USE IFDEF if MEMSTAT ENABLED
200 // Instance()->fMemStat = TMemStatManager::GetInstance();
201 // Instance()->fMemStat->SetAutoStamp(10000000, 10000000,1000000);
202 // Instance()->fMemStat->Enable();
205 void AliSysInfo::CloseMemStat(){
209 //USE IFDEF if MEMSTAT ENABLED
210 //if (Instance()->fMemStat == TMemStatManager::GetInstance()) Instance()->fMemStat->Close();
211 //Instance()->fMemStat=0;