]>
Commit | Line | Data |
---|---|---|
6efecea1 | 1 | /* |
2 | Origin: marian.ivanov@cern.ch | |
3 | Make sys watch default plots (see $ALICE_ROOT/STEER/AliSysInfo.cxx): | |
4 | Input - syswatch.log - text log file created by process to be monitored | |
5 | Output - syswatch.root - root files with default histograms | |
6 | Number of top violators - only top consumer displayed | |
6efecea1 | 7 | Default histogram: |
ab557934 | 8 | TOP violators - CPU and Virtual memory usage |
6efecea1 | 9 | Detector reports - CPU and Virtual memory usage per detector |
ab557934 | 10 | // |
11 | ||
12 | Example usage: | |
13 | // 1. Initialize | |
6efecea1 | 14 | gROOT->LoadMacro("$ALICE_ROOT/macros/PlotSys.C+"); |
ab557934 | 15 | PInit("syswatch.log","syswatch.root","syswatch.sum"); |
16 | // 2. Make ascii report. | |
17 | SumDetector() | |
18 | // 3. Make histos of top violators | |
19 | MakePlots(20); | |
20 | // 4. Browse the results | |
6efecea1 | 21 | TFile f("syswatch.root"); |
22 | TBrowser b; | |
ab557934 | 23 | */ |
6efecea1 | 24 | |
ab557934 | 25 | #include <stdio.h> |
26 | #include "AliReconstruction.h" | |
6efecea1 | 27 | #include "TMath.h" |
28 | #include "TH1F.h" | |
29 | #include "TH2F.h" | |
30 | #include "TTree.h" | |
31 | #include "TFile.h" | |
32 | #include "TCut.h" | |
33 | #include "TStyle.h" | |
34 | #include "AliSysInfo.h" | |
35 | ||
ab557934 | 36 | const Int_t kNDetectors=AliReconstruction::kNDetectors; |
37 | const char* fgkDetectorName[kNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"}; | |
38 | ||
39 | ||
40 | ||
6efecea1 | 41 | TObject * htemp; |
42 | TTree *tree=0; | |
43 | TFile *fout=0; | |
ab557934 | 44 | TString sumFile; |
6efecea1 | 45 | TCut cutVM("cutVM","deltaVM>10"); |
46 | TCut cutDT("cutDT","deltaT>2"); | |
ab557934 | 47 | Int_t ctop=20; |
6efecea1 | 48 | |
49 | ||
50 | Float_t TopUsage(TTree* tree, const char *exp, const char*cut, Int_t order); | |
ab557934 | 51 | Double_t SumUsage(TTree* tree, const char *exp, const char*cut); |
6efecea1 | 52 | void TopVM(); |
53 | void TopCPU(); | |
54 | void TopVMDetector(); | |
55 | void TopCPUDetector(); | |
ab557934 | 56 | void SumDetector(); |
6efecea1 | 57 | |
ab557934 | 58 | void PInit(const char *log="syswatch.log", const char *out="syswatch.root", const char * sumName="syswatch.sum"){ |
6efecea1 | 59 | // |
60 | // Set Input output | |
61 | // | |
62 | tree = AliSysInfo::MakeTree(log); | |
63 | fout = new TFile(out,"recreate"); | |
ab557934 | 64 | sumFile=sumName; |
6efecea1 | 65 | } |
66 | ||
67 | ||
68 | ||
ab557934 | 69 | void MakePlots(Int_t top=20){ |
6efecea1 | 70 | // |
71 | // | |
72 | // | |
73 | ctop=top; | |
6efecea1 | 74 | gStyle->SetOptStat(0); |
75 | // | |
76 | // Top users | |
77 | // | |
78 | TopVM(); | |
79 | TopCPU(); | |
80 | // | |
81 | // Reports per detector | |
82 | // | |
6efecea1 | 83 | fout->cd(); |
ab557934 | 84 | for (Int_t idet=0; idet<kNDetectors;idet++){ |
85 | fout->cd(); | |
86 | fout->mkdir(fgkDetectorName[idet]); | |
87 | } | |
88 | TopVMDetector(); | |
6efecea1 | 89 | TopCPUDetector(); |
6efecea1 | 90 | // |
91 | fout->Close(); | |
92 | ctop=top; | |
93 | delete fout; | |
94 | } | |
95 | ||
96 | void TopVM(){ | |
97 | // | |
98 | // select top user of virtual Memory | |
99 | // MakeReport - ASCII and histogram | |
100 | // | |
101 | TH1 * his=0; | |
102 | TH2 * his2=0; | |
103 | Float_t thVM = TopUsage(tree,"deltaVM","",ctop); | |
104 | cutVM = TCut("cutDT",Form("deltaVM>%f",thVM)); | |
105 | // | |
106 | // | |
107 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n\n"); | |
108 | printf("TOP Virtual memory user\n"); | |
ab557934 | 109 | //tree->Scan("deltaVM:sname",cutVM,"colsize=20"); |
6efecea1 | 110 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n\n"); |
111 | // | |
112 | tree->Draw("deltaVM:sname>>hhh","1"+cutVM,"*"); | |
113 | his2 = (TH2F*)(tree->GetHistogram())->Clone("dvmsname"); | |
114 | delete tree->GetHistogram(); | |
115 | his2->SetYTitle("Delta Virtual Memory (MBy)"); | |
116 | his2->SetMarkerStyle(22); | |
117 | his2->SetMarkerSize(1); | |
118 | his2->Draw("l*"); | |
119 | his2->Write("DVMvsName"); | |
120 | delete his2; | |
121 | // | |
122 | tree->Draw("VM:sname>>hhh","id2<3"+cutVM,"*"); | |
123 | his2 = (TH2F*)(tree->GetHistogram())->Clone("vmsname"); | |
124 | delete tree->GetHistogram(); | |
125 | his2->SetYTitle("Delta Virtual Memory (MBy)"); | |
126 | his2->SetMarkerStyle(22); | |
127 | his2->SetMarkerSize(1); | |
128 | his2->Draw("l*"); | |
129 | his2->Write("VMvsName"); | |
130 | delete his2; | |
131 | // | |
132 | // | |
133 | tree->Draw("VM:T>>hhh","deltaVM>1","line*"); | |
134 | his = (TH1*)tree->GetHistogram()->Clone("vmt"); | |
135 | delete tree->GetHistogram(); | |
136 | his->SetXTitle("Time (sec)"); | |
137 | his->SetYTitle("Virtual Memory (MBy)"); | |
138 | his->GetYaxis()->SetTitleOffset(1.2); | |
139 | his->SetMarkerStyle(22); | |
140 | his->SetMarkerSize(1); | |
141 | his->Draw(); | |
142 | his->Write("VMvsTime"); | |
143 | delete his; | |
144 | } | |
145 | ||
146 | void TopCPU(){ | |
147 | // | |
148 | // select top user of CPU | |
149 | // MakeReport - ASCII and histogram | |
150 | // | |
151 | TH2 * his2=0; | |
152 | Float_t thDT = TopUsage(tree,"deltaT","id2<3",ctop); | |
153 | cutDT = TCut("cutDT",Form("deltaT>%f",thDT)); | |
154 | // | |
155 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); | |
156 | printf("/n/n/nTOP CPU user\n"); | |
ab557934 | 157 | //tree->Scan("deltaT:sname",cutDT,"colsize=20"); |
6efecea1 | 158 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); |
159 | // | |
160 | tree->Draw("deltaT:sname>>hhh","id2<3"+cutDT,"*"); | |
161 | his2 = (TH2F*)(tree->GetHistogram())->Clone("tsname"); | |
162 | delete tree->GetHistogram(); | |
163 | his2->SetName("VMsanme"); | |
164 | his2->SetYTitle("Delta CPU time(sec)"); | |
165 | his2->SetMarkerStyle(22); | |
166 | his2->SetMarkerSize(1); | |
167 | his2->GetXaxis()->SetLabelSize(0.03); | |
168 | his2->Draw("l*"); | |
169 | his2->Write("CPUvsName"); | |
170 | delete his2; | |
171 | } | |
172 | ||
173 | ||
174 | void TopVMDetector(){ | |
175 | // | |
176 | // Draw usage of VM | |
177 | // | |
178 | TH2 * his2=0; | |
179 | // | |
180 | // | |
181 | //detector part | |
182 | // | |
ab557934 | 183 | for (Int_t idet=0; idet<kNDetectors; idet++){ |
184 | fout->cd(); | |
185 | fout->cd(fgkDetectorName[idet]); | |
6efecea1 | 186 | char cdet[100]; |
187 | char cdvm[100]; | |
188 | sprintf(cdet,"id0==%d",idet); | |
189 | char expr[100]; | |
190 | sprintf(expr,"deltaVM:sname>>hhh"); | |
191 | // | |
192 | Float_t thDVM = TopUsage(tree,"deltaVM",cdet,ctop); | |
ab557934 | 193 | sprintf(cdvm,"%s&&deltaVM>%f",cdet, thDVM); |
6efecea1 | 194 | // |
ab557934 | 195 | tree->Draw(expr,cdvm,"GOFF"); |
6efecea1 | 196 | his2 = (TH2F*)(tree->GetHistogram())->Clone("xxx"); |
197 | delete tree->GetHistogram(); | |
198 | his2->SetYTitle("Delta Virtual Memory (MBy)"); | |
199 | his2->SetMarkerStyle(22); | |
200 | his2->SetMarkerSize(1); | |
ab557934 | 201 | //his2->Draw("l*"); |
6efecea1 | 202 | his2->Write(Form("DVMvsName_%d",idet)); |
203 | delete his2; | |
204 | // | |
205 | // | |
206 | sprintf(expr,"VM:sname>>hhh"); | |
ab557934 | 207 | tree->Draw(expr,cdvm,"goff"); |
6efecea1 | 208 | his2 = (TH2F*)(tree->GetHistogram())->Clone("yyy"); |
209 | delete tree->GetHistogram(); | |
210 | his2->SetYTitle("Delta Virtual Memory (MBy)"); | |
211 | his2->SetMarkerStyle(22); | |
212 | his2->SetMarkerSize(1); | |
ab557934 | 213 | //his2->Draw("l*"); |
6efecea1 | 214 | his2->Write(Form("VMvsName_%d",idet)); |
215 | delete his2; | |
216 | } | |
ab557934 | 217 | fout->cd(); |
6efecea1 | 218 | } |
219 | ||
220 | ||
221 | ||
222 | void TopCPUDetector(){ | |
223 | // | |
224 | // Draw usage of CPU | |
225 | // | |
226 | TH2 * his2=0; | |
227 | // | |
228 | // | |
229 | // CPU | |
230 | // | |
ab557934 | 231 | for (Int_t idet=0; idet<kNDetectors; idet++){ |
232 | fout->cd(); | |
233 | fout->cd(fgkDetectorName[idet]); | |
6efecea1 | 234 | char cdet[100]; |
235 | char cdtime[100]; | |
236 | sprintf(cdet,"id0==%d",idet); | |
237 | char expr[100]; | |
238 | sprintf(expr,"deltaT:sname>>hhh"); | |
239 | // | |
240 | Float_t thDT = TopUsage(tree,"deltaT",cdet,ctop); | |
241 | sprintf(cdtime,"%s&&deltaT>%f",cdet, thDT); | |
242 | // | |
ab557934 | 243 | tree->Draw(expr,cdtime,"goff"); |
6efecea1 | 244 | his2 = (TH2F*)(tree->GetHistogram())->Clone("dtsname"); |
245 | delete tree->GetHistogram(); | |
246 | his2->SetYTitle("Delta CPU time(sec)"); | |
247 | his2->SetMarkerStyle(22); | |
248 | his2->SetMarkerSize(1); | |
249 | his2->GetXaxis()->SetLabelSize(0.03); | |
ab557934 | 250 | //his2->Draw("l*"); |
6efecea1 | 251 | his2->Write(Form("CPUvsName_%d",idet)); |
252 | delete his2; | |
253 | } | |
ab557934 | 254 | fout->cd(); |
255 | } | |
256 | ||
257 | void SumDetector(){ | |
258 | // | |
259 | // Sum - detector information | |
260 | // | |
261 | FILE * pFile; | |
262 | pFile = fopen (sumFile,"w"); | |
263 | char cdet[100]; | |
264 | char expr[100]; | |
265 | sprintf(cdet,"id0>=0&&id2>=0"); | |
266 | Double_t sumdTAll = SumUsage(tree,"deltaT",cdet); | |
267 | Double_t sumdVMAll = SumUsage(tree,"deltaVM",cdet); | |
268 | printf("%s%s%s%s%s\n","Det/C:","sumDt/F:","sumDvm/F:","fracDt/F:","fracDvm/F"); | |
269 | printf("%s\t%f\t%f\t%f\t%f\t\n","all", sumdTAll,sumdVMAll,100.,100.); | |
270 | fprintf(pFile,"%s%s%s%s%s\n","Det/C:","sumDt/F:","sumDvm/F:","fracDt/F:","fracDvm/F"); | |
271 | fprintf(pFile,"%s\t%f\t%f\t%f\t%f\t\n","all", sumdTAll,sumdVMAll,100.,100.); | |
272 | for (Int_t idet=0; idet<kNDetectors; idet++){ | |
273 | sprintf(cdet,"id0==%d&&id2>=0",idet); | |
274 | sprintf(expr,"deltaT:sname>>hhh"); | |
275 | Double_t sumdT = SumUsage(tree,"deltaT",cdet); | |
276 | Double_t sumdVM = SumUsage(tree,"deltaVM",cdet); | |
277 | printf("%s\t%f\t%f\t%f\t%f\t\n",fgkDetectorName[idet], sumdT,sumdVM,100.*sumdT/sumdTAll, 100.*sumdVM/sumdVMAll); | |
278 | fprintf(pFile,"%s\t%f\t%f\t%f\t%f\t\n",fgkDetectorName[idet], sumdT,sumdVM,100.*sumdT/sumdTAll, 100.*sumdVM/sumdVMAll); | |
279 | } | |
280 | fclose (pFile); | |
6efecea1 | 281 | } |
282 | ||
ab557934 | 283 | |
6efecea1 | 284 | |
285 | ||
286 | ||
287 | ||
288 | Float_t TopUsage(TTree* tree, const char *exp, const char*cut, Int_t order){ | |
289 | // | |
290 | // | |
291 | // Find value for given order | |
292 | // Used to select top violator | |
293 | // | |
294 | Int_t entries = tree->Draw(Form("%s>>hhh1",exp),cut,"goff"); | |
295 | if (entries<=1) { | |
296 | if (tree->GetHistogram()) delete tree->GetHistogram(); | |
297 | printf("%s\t No entries\n",cut); | |
298 | return -10000; | |
299 | } | |
300 | if (!tree->GetV1()) { | |
301 | printf("%s\t No entries\n",cut); | |
302 | return -10000; | |
303 | } | |
304 | Int_t *index = new Int_t[entries]; | |
305 | TMath::Sort(entries, tree->GetV1(), index); | |
306 | Int_t oindex = TMath::Min(order, entries); | |
307 | Float_t val = tree->GetV1()[index[oindex-1]]; | |
308 | if (tree->GetHistogram()) delete tree->GetHistogram(); | |
309 | delete [] index; | |
310 | return val; | |
311 | } | |
ab557934 | 312 | |
313 | ||
314 | Double_t SumUsage(TTree* tree, const char *exp, const char*cut){ | |
315 | // | |
316 | // return sum of usage | |
317 | // | |
318 | Int_t entries = tree->Draw(Form("%s",exp),cut,"goff"); | |
319 | if (entries==0) return 0; | |
320 | Double_t mean = TMath::Mean(entries, tree->GetV1()); | |
321 | return entries*mean; | |
322 | } |