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