Moved to mapping, as AliMpHVNamer (Laurent)
[u/mrichter/AliRoot.git] / STEER / AliSysInfo.cxx
CommitLineData
0e8bc704 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
6efecea1 17//
18// Origin: marian.ivanov@cern.ch
19//
20// Make a log file for the CPU and Memory usage
21//
22// The typical usage:
23// Make a set of stamps in the code in the place of interest
24// e.g.
25//
26// AliSysInfo::AddStamp("Start");
27//
28// loader->UnloadRecPoints();
29// AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
30//
31
32// The log file can be transformed to the tree - to make a visualization
33// See $ALICE_ROOT/macros/PlotSysInfo.C as an example
34
35
0e8bc704 36#include <Riostream.h>
37#include "AliLog.h"
38#include "TStopwatch.h"
39#include "TSystem.h"
40#include "TTree.h"
41
42#include "TTimeStamp.h"
43#include "AliSysInfo.h"
44
6efecea1 45//#include "TMemStatManager.h" //USE IFDEF
46
0e8bc704 47
48ClassImp(AliSysInfo)
49
50AliSysInfo* AliSysInfo::fInstance=0;
51
52AliSysInfo::AliSysInfo():
53 TObject(),
54 fSysWatch(0),
6efecea1 55 fTimer(0),
56 fMemStat(0)
0e8bc704 57{
58 fTimer = new TStopwatch;
59 fSysWatch = new fstream("syswatch.log", ios_base::out|ios_base::trunc);
6efecea1 60
0e8bc704 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
62
63
64 (*fSysWatch) <<"hname"<<"/C:" // hname - hostname
65 <<"sname"<<"/C:" // stamp name
6efecea1 66 <<"id0"<<"/I:" // 0 id
67 <<"id1"<<"/I:" // 1 id
68 <<"id2"<<"/I:" // 1 id
0e8bc704 69 <<"first"<<"/I:" // first stamp
70 //
71 <<"stampSec"<<"/I:" // time - time stamp in seconds
72 <<"mi.fMemUsed"<<"/F:" // system info
73 <<"mi.fSwapUsed"<<"/F:" //
74 <<"cI.fUser"<<"/F:" //
75 <<"cI.fSys"<<"/F:" //
76 //
77 <<"pI.fMemResident"<<"/F:" // process info
78 <<"pI.fMemVirtual"<<"/F:" //
79 <<"pI.fCpuUser"<<"/F:" //
80 <<"pI.fCpuSys"<<"/F:" //
81 //
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:" //
87 //
88 <<"pIOld.fMemResident"<<"/F:" // process info -previous
89 <<"pIOld.fMemVirtual"<<"/F:" //
90 <<"pIOld.fCpuUser"<<"/F:" //
91 <<"pIOld.fCpuSys"<<"/F" //
92 << endl;
93
94}
95
96
97
98
99AliSysInfo * AliSysInfo::Instance(){
100 //
101 //
102 //
103 if (!fInstance){
104 fInstance = new AliSysInfo;
105 }
106 return fInstance;
107}
108
109
6efecea1 110void AliSysInfo::AddStamp(const char *sname, Int_t id0, Int_t id1, Int_t id2){
0e8bc704 111 //
112 //
113 //
0e8bc704 114 //
0e8bc704 115 TTimeStamp stamp;
116 CpuInfo_t cpuInfo;
117 MemInfo_t memInfo;
118 ProcInfo_t procInfo;
119 gSystem->GetCpuInfo(&cpuInfo, 10);
120 gSystem->GetMemInfo(&memInfo);
121 gSystem->GetProcInfo(&procInfo);
122 const char * hname = gSystem->HostName();
123
124 static Int_t entry=0;
125 static Int_t first=stamp.GetSec();
126 //
127 static TTimeStamp stampOld;
128 static CpuInfo_t cpuInfoOld;
129 static MemInfo_t memInfoOld;
130 static ProcInfo_t procInfoOld;
131
132
6efecea1 133 (*(Instance()->fSysWatch)) << hname <<"\t" // hname - hostname
0e8bc704 134 << sname <<"\t" // stamp name
6efecea1 135 << id0 <<"\t"
136 << id1 <<"\t"
137 << id2 <<"\t"
138 << first <<"\t" // first stamp
0e8bc704 139 //
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" //
145 //
146 << procInfo.fMemResident<<"\t" // process info
147 << procInfo.fMemVirtual<<"\t" //
148 << procInfo.fCpuUser<<"\t" //
149 << procInfo.fCpuSys<<"\t" //
150 //
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" //
156 //
157 << procInfoOld.fMemResident<<"\t" // process info -previous
158 << procInfoOld.fMemVirtual<<"\t" //
159 << procInfoOld.fCpuUser<<"\t" //
160 << procInfoOld.fCpuSys<<"\t" //
161 << endl;
162 stampOld = stamp;
163 cpuInfoOld = cpuInfo;
164 memInfoOld = memInfo;
6efecea1 165 procInfoOld= procInfo;
166
167 // if (fInstance->fMemStat) fInstance->fMemStat->AddStamps(sname);
168
0e8bc704 169 entry++;
170}
171
172
173TTree * 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");
6efecea1 178 tree->SetAlias("T","stampSec-first");
0e8bc704 179 tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)*0.001");
6efecea1 180 tree->SetAlias("VM","pI.fMemVirtual*0.001");
0e8bc704 181 return tree;
182}
183
6efecea1 184
185Bool_t AliSysInfo::Contain(const char * str1, const char * str2){
186 //
187 //
188 //
189 TString str(str1);
190 return str.Contains(str2);
191}
192
193
194
195void AliSysInfo::OpenMemStat(){
196 //
197 //
198 //
199 //USE IFDEF if MEMSTAT ENABLED
200 // Instance()->fMemStat = TMemStatManager::GetInstance();
201 // Instance()->fMemStat->SetAutoStamp(10000000, 10000000,1000000);
202 // Instance()->fMemStat->Enable();
203}
204
205void AliSysInfo::CloseMemStat(){
206 //
207 //
208 //
209 //USE IFDEF if MEMSTAT ENABLED
210 //if (Instance()->fMemStat == TMemStatManager::GetInstance()) Instance()->fMemStat->Close();
211 //Instance()->fMemStat=0;
212}