forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TProofPerfAnalysis.cxx
1863 lines (1678 loc) · 63.3 KB
/
TProofPerfAnalysis.cxx
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/proofx:$Id$
// Author: G.Ganis Nov 2011
/*************************************************************************
* Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/** \class TProofPerfAnalysis
\ingroup proofbench
Set of tools to analyse the performance tree
*/
#include <errno.h>
#include "TProofPerfAnalysis.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TGraph.h"
#include "TH1F.h"
#include "TH2F.h"
#include "THashList.h"
#include "TKey.h"
#include "TList.h"
#include "TSortedList.h"
#include "TPerfStats.h"
#include "TRegexp.h"
#include "TStyle.h"
#include "TSystem.h"
#include "TTree.h"
#include "TMath.h"
//
// Auxilliary internal classes
////////////////////////////////////////////////////////////////////////////////
class TProofPerfAnalysis::TWrkInfo : public TNamed {
public:
TWrkInfo(const char *ord, const char *name) :
TNamed(ord, name), fPackets(0), fRemotePackets(0), fEventsProcessed(0),
fBytesRead(0), fLatency(0), fProcTime(0), fCpuTime(0), fStart(0), fStop(-1),
fRateT(0), fRateRemoteT(0), fMBRateT(0), fMBRateRemoteT(0), fLatencyT(0) { }
virtual ~TWrkInfo() { SafeDelete(fRateT); SafeDelete(fRateRemoteT);
SafeDelete(fMBRateT); SafeDelete(fMBRateRemoteT);
SafeDelete(fLatencyT); }
Int_t fPackets; // Number of packets processed
Int_t fRemotePackets; // Number of processed packet from non-local files
Long64_t fEventsProcessed; // Tot events processed
Long64_t fBytesRead; // Tot bytes read
Double_t fLatency; // Tot latency
Double_t fProcTime; // Tot proc time
Double_t fCpuTime; // Tot CPU time
Float_t fStart; // Start time
Float_t fStop; // Stop time
TGraph *fRateT; // Event processing rate vs time
TGraph *fRateRemoteT; // Event processing rate of remote packets vs time
TGraph *fMBRateT; // Byte processing rate vs time
TGraph *fMBRateRemoteT; // Byte processing rate of remote packets vs time
TGraph *fLatencyT; // Packet latency vs time
Double_t AvgRate() { if (fProcTime > 0) return (fEventsProcessed/fProcTime); return -1.; }
Double_t AvgIO() { if (fProcTime > 0) return (fBytesRead/fProcTime); return -1.; }
void Print(Option_t * = "") const {
Printf(" +++ TWrkInfo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
Printf(" +++ Worker: %s, %s", GetName(), GetTitle());
Printf(" +++ Activity interval: %f -> %f", fStart, fStop);
Printf(" +++ Amounts processed: %d packets (%d remote), %lld evts, %lld bytes",
fPackets, fRemotePackets, fEventsProcessed, fBytesRead);
if (fProcTime) {
Printf(" +++ Processing time: %f s (CPU: %f s)", fProcTime, fCpuTime);
Printf(" +++ Averages: %f evts/s, %f MB/s", (Double_t)fEventsProcessed / fProcTime, (Double_t)fBytesRead /1024./1024./fProcTime);
}
Printf(" +++ Total latency: %f", fLatency);
Printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
}
Int_t Compare(const TObject *o) const { TWrkInfo *wi = (TWrkInfo *)o;
if (wi) {
if (fStop < wi->fStop) {
return -1;
} else if (fStop == wi->fStop) {
return 0;
}
}
return 1; }
};
class TProofPerfAnalysis::TPackInfo : public TNamed {
public:
TPackInfo(const char *ord, const char *host) : TNamed(ord, host), fStart(0), fStop(-1), fSize(0), fMBRate(0.) { }
TPackInfo(const char *ord, const char *host, Float_t start, Float_t stop, Long64_t sz, Double_t mbr)
: TNamed(ord, host), fStart(start), fStop(stop), fSize(sz), fMBRate(mbr) { }
Float_t fStart; // When the packet has been assigned
Float_t fStop; // When the packet has been finished
Long64_t fSize; // Packet size
Double_t fMBRate; // Processing rate MB/s
void Print(Option_t *opt= "") const {
if (!strcmp(opt, "S")) {
Printf(" \t%10lld evts, \t%12.2f MB/s, \t%12.3f -> %12.3f s", fSize, fMBRate, fStart, fStop);
} else {
Printf(" %s:\t%s \t%10lld evts, \t%12.2f MB/s, \t%12.3f -> %12.3f s", GetTitle(), GetName(), fSize, fMBRate, fStart, fStop);
}
}
};
class TProofPerfAnalysis::TWrkInfoFile : public TNamed {
public:
TWrkInfoFile(const char *ord, const char *name) : TNamed(ord, name) { }
~TWrkInfoFile() {fPackets.SetOwner(kFALSE); fPackets.Clear("nodelete");}
TList fPackets; // Packest from this file processed by this worker
void Print(Option_t *opt= "") const {
if (!strcmp(opt, "R")) {
Printf(" Worker: %s,\tpacket(s): %d", GetName(), fPackets.GetSize());
} else {
Printf(" Worker: %s,\t%d packet(s) from file: %s", GetName(), fPackets.GetSize(), GetTitle());
}
TIter nxp(&fPackets);
TObject *o = 0;
while ((o = nxp())) { o->Print("S"); }
}
};
class TProofPerfAnalysis::TWrkEntry : public TObject {
public:
TWrkEntry(Double_t xx, Double_t er, Double_t mbr, Double_t pt) : fXx(xx), fEvtRate(er), fMBRate(mbr), fProcTime(pt) { }
Double_t fXx; // Bin center
Double_t fEvtRate; // Event processing rate from this worker for this packet
Double_t fMBRate; // I/O processing rate from this worker for this packet
Double_t fProcTime; // Processing time
void Print(Option_t * = "") const { Printf("%.4f \t%.3f evt/s \t%.3f MB/s \t%.3f s ", fXx, fEvtRate, fMBRate, fProcTime); }
};
////////////////////////////////////////////////////////////////////////////////
class TProofPerfAnalysis::TFileInfo : public TNamed {
public:
TFileInfo(const char *name, const char *srv) :
TNamed(name, srv), fPackets(0), fRPackets(0), fStart(0), fStop(-1),
fSizeAvg(0), fSizeMax(-1.), fSizeMin(-1.),
fMBRateAvg(0), fMBRateMax(-1.), fMBRateMin(-1.), fSizeP(0),
fRateP(0), fRatePRemote(0), fMBRateP(0), fMBRatePRemote(0) { }
virtual ~TFileInfo() {SafeDelete(fSizeP);
SafeDelete(fRateP); SafeDelete(fRatePRemote);
SafeDelete(fMBRateP); SafeDelete(fMBRatePRemote);
fPackList.SetOwner(kTRUE); fPackList.Clear();
fWrkList.SetOwner(kTRUE); fWrkList.Clear();
fRWrkList.SetOwner(kTRUE); fRWrkList.Clear();}
Int_t fPackets; // Number of packets from this file
Int_t fRPackets; // Number of different remote workers processing this file
TList fPackList; // List of packet info
TList fWrkList; // List of worker names processing this packet
TList fRWrkList; // List of remote worker names processing this packet
Float_t fStart; // When the first packet has been assigned
Float_t fStop; // When the last packet has been finished
Long64_t fSizeAvg; // Average Packet size
Long64_t fSizeMax; // Max packet size
Long64_t fSizeMin; // Min packet size
Double_t fMBRateAvg; // Average MB rate
Double_t fMBRateMax; // Max MB rate
Double_t fMBRateMin; // Min MB rate
TGraph *fSizeP; // Packet size vs packet (all)
TGraph *fRateP; // Event processing rate vs packet (all)
TGraph *fRatePRemote; // Event processing rate vs packet (remote workers)
TGraph *fMBRateP; // Byte processing rate vs packet (all)
TGraph *fMBRatePRemote; // Byte processing rate vs packet (remote workers)
void Print(Option_t *opt = "") const {
Printf(" +++ TFileInfo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
Printf(" +++ Server: %s", GetTitle());
Printf(" +++ File: %s", GetName());
Printf(" +++ Processing interval: %f -> %f", fStart, fStop);
Printf(" +++ Packets: %d (%d remote)", fPackets, fRPackets);
Printf(" +++ Processing wrks: %d (%d remote)", fWrkList.GetSize(), fRWrkList.GetSize());
if (!strcmp(opt, "P")) fPackList.Print();
if (!strcmp(opt, "WP")) fWrkList.Print("R");
if (fPackets > 0) {
Printf(" +++ MB rates: %f MB/s (avg), %f MB/s (min), %f MB/s (max)",
fMBRateAvg / fPackets, fMBRateMin, fMBRateMax);
Printf(" +++ Sizes: %lld (avg), %lld (min), %lld (max)",
fSizeAvg / fPackets, fSizeMin, fSizeMax);
}
Printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
}
Int_t Compare(const TObject *o) const { TFileInfo *wi = (TFileInfo *)o;
if (wi) {
if (fStop < wi->fStop) {
return -1;
} else if (fStop == wi->fStop) {
return 0;
}
}
return 1; }
};
Bool_t TProofPerfAnalysis::fgDebug = kTRUE;
////////////////////////////////////////////////////////////////////////////////
/// Constructor: open the file and attach to the tree
TProofPerfAnalysis::TProofPerfAnalysis(const char *perffile,
const char *title, const char *treename)
: TNamed(perffile, title), fFile(0), fTreeName(treename), fTree(0),
fInitTime(-1.), fMergeTime(-1.), fMaxTime(-1.),
fEvents(0), fPackets(0),
fEvtRateMax(-1.), fMBRateMax(-1.), fLatencyMax(-1.),
fEvtRate(0), fEvtRateRun(0), fMBRate(0), fMBRateRun(0),
fEvtRateAvgMax(-1.), fMBRateAvgMax(-1.),
fEvtRateAvg(-1.), fMBRateAvg(0),
fFileResult(""), fSaveResult(kFALSE),
fDebug(0)
{
// Use default title, if not specified
if (!title) SetTitle("PROOF Performance Analysis");
fTree = 0;
fFile = TFile::Open(perffile);
if (!fFile || (fFile && fFile->IsZombie())) {
SafeDelete(fFile);
Error("TProofPerfAnalysis", "problems opening file '%s'",
perffile ? perffile : "<undef>");
SetBit(TObject::kInvalidObject);
return;
}
// Set the subdirectory name, if any
if (fTreeName.Contains("/")) {
fDirName = gSystem->DirName(fTreeName);
fTreeName = gSystem->BaseName(fTreeName);
}
// Adjust the name, if requested
if (fTreeName.BeginsWith("+"))
fTreeName.Replace(0, 1, "PROOF_PerfStats");
// Point to the right TDirectory
TDirectory *dir = fFile;
if (!fDirName.IsNull()) {
if (!(dir = dynamic_cast<TDirectory *>(fFile->Get(fDirName)))) {
Error("TProofPerfAnalysis", "directory '%s' not found or not loadable", fDirName.Data());
fFile->Close();
SafeDelete(fFile);
SetBit(TObject::kInvalidObject);
return;
}
}
// Load the performance tree
LoadTree(dir);
if (!fTree) {
Error("TProofPerfAnalysis", "tree '%s' not found or not loadable", fTreeName.Data());
fFile->Close();
SafeDelete(fFile);
SetBit(TObject::kInvalidObject);
return;
}
if (fgDebug)
Printf(" +++ TTree '%s' has %lld entries", fTreeName.Data(), fTree->GetEntries());
// Init worker information
FillWrkInfo();
// Init file information
FillFileInfo();
// Done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor: open the file and attach to the tree
TProofPerfAnalysis::TProofPerfAnalysis(TTree *tree, const char *title)
: TNamed("", title), fFile(0), fTree(0),
fInitTime(-1.), fMergeTime(-1.), fMaxTime(-1.),
fEvents(0), fPackets(0),
fEvtRateMax(-1.), fMBRateMax(-1.), fLatencyMax(-1.),
fEvtRate(0), fEvtRateRun(0), fMBRate(0), fMBRateRun(0),
fEvtRateAvgMax(-1.), fMBRateAvgMax(-1.),
fEvtRateAvg(-1.), fMBRateAvg(0),
fDebug(0)
{
// The tree must be defined
if (!tree) {
SetBit(TObject::kInvalidObject);
return;
}
// Use default title, if not specified
if (!title) SetTitle("PROOF Performance Analysis");
fTree = tree;
fTreeName = fTree->GetName();
SetName(TString::Format("heap_%s", fTreeName.Data()));
// Adjust the name, if requested
if (fTreeName.BeginsWith("+"))
fTreeName.Replace(0, 1, "PROOF_PerfStats");
if (fgDebug)
Printf(" +++ TTree '%s' has %lld entries", fTreeName.Data(), fTree->GetEntries());
// Init worker information
FillWrkInfo();
// Init file information
FillFileInfo();
// Done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor: detach the tree and close the file
TProofPerfAnalysis::~TProofPerfAnalysis()
{
SafeDelete(fEvents);
SafeDelete(fPackets);
if (fFile) fFile->Close();
SafeDelete(fFile);
}
////////////////////////////////////////////////////////////////////////////////
/// If defined, add '- <this title>' to the canvas title 't'
TString TProofPerfAnalysis::GetCanvasTitle(const char *t)
{
if (fTitle.IsNull()) return TString(t);
TString newt;
if (t && strlen(t) > 0) {
newt.Form("%s - %s", t, GetTitle());
} else {
newt = GetTitle();
}
// Done
return newt;
}
////////////////////////////////////////////////////////////////////////////////
/// Load tree fTreeName from directory 'dir'. If not found, look for the
/// first TTree in the directory (and sub-directories) with the name containing
/// fTreeName.
/// The tree pointer is saved in fTree.
void TProofPerfAnalysis::LoadTree(TDirectory *dir)
{
fTree = 0;
if (!dir) return;
// Try first the full name in the top directory
if ((fTree = dynamic_cast<TTree *>(dir->Get(fTreeName)))) return;
TRegexp re(fTreeName);
// Now look inside: iter on the list of keys first
TIter nxk(dir->GetListOfKeys());
TKey *k = 0;
while ((k = (TKey *) nxk())) {
if (!strcmp(k->GetClassName(), "TDirectoryFile")) {
TDirectory *kdir = (TDirectory *) dir->Get(k->GetName());
LoadTree(kdir);
if (fTree) return;
} else if (!strcmp(k->GetClassName(), "TTree")) {
TString tn(k->GetName());
if (tn.Index(re) != kNPOS) {
if ((fTree = dynamic_cast<TTree *>(dir->Get(tn)))) {
fTreeName = tn;
if (fgDebug) Printf(" +++ Found and loaded TTree '%s'", tn.Data());
return;
}
}
}
}
// Nothing found
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Analyse the file distribution. If writedet, underling details are
/// written out to a text file.
void TProofPerfAnalysis::FileDist(Bool_t writedet)
{
if (!IsValid()) {
Error("FileDist","not a valid instance - do nothing");
return;
}
// Fill file info
TList *wrkList = new TList;
TList *srvList = new TList;
GetWrkFileList(wrkList, srvList);
Info("FileDist", "%d workers were active during this query", wrkList->GetSize());
Info("FileDist", "%d servers were active during this query", srvList->GetSize());
// Fill the worker-data server mapping
TIter nxs(srvList);
TIter nxw(wrkList);
TNamed *sn = 0, *wn = 0;
while ((sn = (TNamed *)nxs())) {
nxw.Reset();
while ((wn = (TNamed *) nxw())) {
if (!strcmp(TUrl(sn->GetName()).GetHostFQDN(), wn->GetTitle())) {
sn->SetTitle(wn->GetName());
}
}
}
// Reorder the lists following the title
TList *nwl = new TList;
TList *nsl = new TList;
nxw.Reset();
while ((wn = (TNamed *) nxw())) {
TIter nnxw(nwl);
TNamed *nwn = 0;
while ((nwn = (TNamed *) nnxw())) {
if (CompareOrd(wn->GetName(), nwn->GetName()) < 0) {
nwl->AddBefore(nwn, wn);
break;
}
}
if (!nwn) nwl->Add(wn);
// Find the server name, if any
nxs.Reset();
while ((sn = (TNamed *)nxs())) {
if (!strcmp(sn->GetTitle(), wn->GetName())) {
TIter nnxs(nsl);
TNamed *nsn = 0;
while ((nsn = (TNamed *) nnxs())) {
if (CompareOrd(sn->GetTitle(), nsn->GetTitle()) < 0) {
nsl->AddBefore(nsn, sn);
break;
}
}
if (!nsn) nsl->Add(sn);
break;
}
}
if (sn) srvList->Remove(sn);
}
// Add remaining servers at the end
nxs.Reset();
while ((sn = (TNamed *)nxs())) {
nsl->Add(sn);
}
// Clean the orginal lists
wrkList->SetOwner(kFALSE);
srvList->SetOwner(kFALSE);
delete wrkList;
delete srvList;
wrkList = nwl;
srvList = nsl;
// Notify
wrkList->ls();
srvList->ls();
// Separate out the case with only one file server
if (srvList->GetSize() == 1) {
Printf("\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
Printf(" + Only one data server found: full analysis meaningful + ");
Printf(" + only when there are more file servers + ");
Printf(" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
// Create a 1D histo for cross packets
TH1F *hxpak = new TH1F("hxpak", "MBytes / Worker",
wrkList->GetSize(), 0., (Double_t)wrkList->GetSize());
hxpak->SetDirectory(0);
hxpak->SetMinimum(0.);
hxpak->GetXaxis()->SetTitle("Worker");
// Set the labels
Int_t j = 1;
TIter nxsw(wrkList);
while ((wn = (TNamed *)nxsw())) {
hxpak->GetXaxis()->SetBinLabel(j++, wn->GetName());
}
// Fill the histograms
FillFileDistOneSrv(hxpak, writedet);
// Display histos
gStyle->SetOptStat(0);
TCanvas *c2 = new TCanvas("cv-hxpak", GetCanvasTitle(hxpak->GetTitle()), 800,350,700,700);
c2->cd();
DoDraw(hxpak);
c2->Update();
} else {
// Create a 1D histo for file distribution
TH1F *hfdis = new TH1F("hfdis", "Packet dist",
srvList->GetSize(), 0., (Double_t)srvList->GetSize());
hfdis->SetDirectory(0);
hfdis->SetMinimum(0);
hfdis->GetXaxis()->SetTitle("Server");
TH1F *hbdis = new TH1F("hbdis", "MBytes dist",
srvList->GetSize(), 0., (Double_t)srvList->GetSize());
hbdis->SetDirectory(0);
hbdis->SetMinimum(0);
hbdis->GetXaxis()->SetTitle("Server");
// Create a 2D histo for cross packets
TH2F *hxpak = new TH2F("hxpak", "MBytes / {Worker,Server}",
srvList->GetSize(), 0., (Double_t)srvList->GetSize(),
wrkList->GetSize(), 0., (Double_t)wrkList->GetSize());
hxpak->SetDirectory(0);
hxpak->GetYaxis()->SetTitle("Worker");
hxpak->GetXaxis()->SetTitle("Server");
hxpak->GetXaxis()->SetTitleOffset(1.4);
hxpak->GetYaxis()->SetTitleOffset(1.7);
// Set the labels
Int_t j = 1;
TIter nxsw(wrkList);
while ((wn = (TNamed *)nxsw())) {
hxpak->GetYaxis()->SetBinLabel(j++, wn->GetName());
}
j = 1;
TIter nxss(srvList);
while ((sn = (TNamed *)nxss())) {
hfdis->GetXaxis()->SetBinLabel(j, sn->GetName());
hbdis->GetXaxis()->SetBinLabel(j, sn->GetName());
hxpak->GetXaxis()->SetBinLabel(j++, sn->GetName());
}
// Fill the histograms
FillFileDist(hfdis, hbdis, hxpak, writedet);
j = 1;
nxss.Reset();
while ((sn = (TNamed *)nxss())) {
TString lab(sn->GetName());
lab = TUrl(sn->GetName()).GetHost();
if (strcmp(sn->GetTitle(), "remote") && lab.Index(".") != kNPOS) lab.Remove(lab.Index("."));
hfdis->GetXaxis()->SetBinLabel(j, lab);
hbdis->GetXaxis()->SetBinLabel(j, lab);
hxpak->GetXaxis()->SetBinLabel(j++, lab);
}
// Display histos
gStyle->SetOptStat(0);
TCanvas *c1 = new TCanvas("cv-hfdis", GetCanvasTitle(hfdis->GetTitle()), 800,50,700,700);
c1->Divide(1,2);
TPad *pad1 = (TPad *) c1->GetPad(1);
TPad *pad2 = (TPad *) c1->GetPad(2);
pad1->cd();
DoDraw(hfdis);
pad2->cd();
DoDraw(hbdis);
c1->Update();
TCanvas *c2 = new TCanvas("cv-hxpak", GetCanvasTitle(hxpak->GetTitle()), 500,350,700,700);
c2->cd();
DoDraw(hxpak, "lego");
c2->Update();
}
// Done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Fill file info
void TProofPerfAnalysis::GetWrkFileList(TList *wl, TList *sl)
{
if (!wl || !sl) return;
// Extract information
TPerfEvent pe;
TPerfEvent* pep = &pe;
fTree->SetBranchAddress("PerfEvents", &pep);
Long64_t entries = fTree->GetEntries();
TNamed *wn = 0, *sn = 0;
for (Long64_t k=0; k<entries; k++) {
fTree->GetEntry(k);
// Analyse only packets
if (pe.fType != TVirtualPerfStats::kPacket) continue;
// Find out the worker instance
TString wrk(TUrl(pe.fSlaveName.Data()).GetHostFQDN());
wn = (TNamed *) wl->FindObject(pe.fSlave.Data());
if (!wn) {
wn = new TNamed(pe.fSlave.Data(), wrk.Data());
wl->Add(wn);
}
// Find out the file server instance
TUrl uf(pe.fFileName);
TString srv(uf.GetUrl());
Int_t ifn = srv.Index(uf.GetFile());
if (ifn != kNPOS) srv.Remove(ifn);
sn = (TNamed *) sl->FindObject(srv.Data());
if (!sn) {
sn = new TNamed(srv.Data(), "remote");
sl->Add(sn);
}
}
// Done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Return -1 if ord1 comes before ord2, 0 i they are equal,
/// 1 if ord1 comes after ord2
Int_t TProofPerfAnalysis::CompareOrd(const char *ord1, const char *ord2)
{
TString o1(ord1), o2(ord2), p1, p2;
Int_t o1d = 0, o2d = 0;
if ((o1d = o1.CountChar('.')) > (o2d = o2.CountChar('.'))) {
return 1;
} else if (o1d < o2d) {
return -1;
} else {
o1.ReplaceAll(".", " ");
o2.ReplaceAll(".", " ");
Bool_t b1 = o1.Tokenize(p1, o1d, " ");
Bool_t b2 = o2.Tokenize(p2, o2d, " ");
while (b1 && b2) {
if (p1.Atoi() > p2.Atoi()) {
return 1;
} else if (p1.Atoi() < p2.Atoi()) {
return -1;
} else {
b1 = o1.Tokenize(p1, o1d, " ");
b2 = o2.Tokenize(p2, o2d, " ");
}
}
if (b1 && !b2) {
return 1;
} else if (b2 && !b1) {
return -1;
} else {
return 0;
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Fill file info
void TProofPerfAnalysis::FillFileDist(TH1F *hf, TH1F *hb, TH2F *hx, Bool_t wdet)
{
if (!hf || !hb || !hx) return;
TString fnout;
FILE *fout = 0;
if (wdet) {
fnout.Form("%s-FileDist-Details.txt", GetName());
if (!(fout = fopen(fnout.Data(), "w"))) {
Warning("FillFileDist", "asked to save details in '%s' but file could"
" not be open (errno: %d)", fnout.Data(), (int)errno);
} else {
Info("FillFileDist", "saving details to '%s'", fnout.Data());
}
}
// Extract information
TPerfEvent pe;
TPerfEvent* pep = &pe;
fTree->SetBranchAddress("PerfEvents",&pep);
Long64_t entries = fTree->GetEntries();
for (Long64_t k=0; k<entries; k++) {
fTree->GetEntry(k);
// Analyse only packets
if (pe.fType != TVirtualPerfStats::kPacket) continue;
// Find out the labels ...
TString wrk(pe.fSlave.Data());
TUrl uf(pe.fFileName);
TString srv(uf.GetUrl());
Int_t ifn = srv.Index(uf.GetFile());
if (ifn != kNPOS) srv.Remove(ifn);
// ... and the bins
Double_t xhf = hf->GetXaxis()->GetBinCenter(hf->GetXaxis()->FindBin(srv.Data()));
Double_t xhx = hx->GetXaxis()->GetBinCenter(hx->GetXaxis()->FindBin(srv.Data()));
Double_t yhx = hx->GetYaxis()->GetBinCenter(hx->GetYaxis()->FindBin(wrk.Data()));
// Save details, if asked
if (fout)
fprintf(fout, "%s,%s -> %f,%f (%f)\n",
srv.Data(), wrk.Data(), xhx, yhx, pe.fBytesRead / 1024.);
// Fill now
hf->Fill(xhf);
hb->Fill(xhf, pe.fBytesRead / 1024. / 1024.);
hx->Fill(xhx, yhx, pe.fBytesRead / 1024. / 1024.);
}
if (fout) fclose(fout);
// Done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Fill file info when there is only one file server
void TProofPerfAnalysis::FillFileDistOneSrv(TH1F *hx, Bool_t wdet)
{
if (!hx) return;
TString fnout;
FILE *fout = 0;
if (wdet) {
fnout.Form("%s-FileDist-Details.txt", GetName());
if (!(fout = fopen(fnout.Data(), "w"))) {
Warning("FillFileDistOneSrv", "asked to save details in '%s' but file could"
" not be open (errno: %d)", fnout.Data(), (int)errno);
} else {
Info("FillFileDistOneSrv", "saving details to '%s'", fnout.Data());
}
}
// Extract information
TPerfEvent pe;
TPerfEvent* pep = &pe;
fTree->SetBranchAddress("PerfEvents",&pep);
Long64_t entries = fTree->GetEntries();
for (Long64_t k=0; k<entries; k++) {
fTree->GetEntry(k);
// Analyse only packets
if (pe.fType != TVirtualPerfStats::kPacket) continue;
// Find out the labels ...
TString wrk(pe.fSlave.Data());
TUrl uf(pe.fFileName);
TString srv(uf.GetUrl());
Int_t ifn = srv.Index(uf.GetFile());
if (ifn != kNPOS) srv.Remove(ifn);
// ... and the bins
Double_t xhx = hx->GetXaxis()->GetBinCenter(hx->GetXaxis()->FindBin(wrk.Data()));
// Save details, if asked
if (fout)
fprintf(fout, "%s,%s -> %f (%f)\n",
srv.Data(), wrk.Data(), xhx, pe.fBytesRead / 1024.);
// Fill now
hx->Fill(xhx, pe.fBytesRead / 1024. / 1024.);
}
if (fout) fclose(fout);
// Done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Measure the worker activity
void TProofPerfAnalysis::WorkerActivity()
{
if (!IsValid()) {
Error("WorkerActivity","not a valid instance - do nothing");
return;
}
// Fill basic worker info
if (!WrkInfoOK()) FillWrkInfo();
if (!WrkInfoOK()) {
Error("WorkerActivity", "workers information not available - do nothing");
return;
}
TObject *o = 0;
// Create the histograms with activity vs time
if ((o = gDirectory->FindObject("act10"))) delete o;
Float_t t0 = fMergeTime - 2.* (fMaxTime - fMergeTime);
Float_t t1 = 2.*fInitTime;
if (t1 > t0) t1 = t0;
TH1F *hact10 = new TH1F("act10", "Worker activity start (seconds)", 50, 0., t1);
hact10->GetXaxis()->SetTitle("Query Processing Time (s)");
if ((o = gDirectory->FindObject("act11"))) delete o;
TH1F *hact11 = new TH1F("act11", "Worker activity stop (seconds)", 50, t0, fMaxTime);
hact11->GetXaxis()->SetTitle("Query Processing Time (s)");
if ((o = gDirectory->FindObject("act2"))) delete o;
TH1F *hact2 = new TH1F("act2", "End of activity (seconds)", 50, t0, fMaxTime);
hact2->GetXaxis()->SetTitle("Query Processing Time (s)");
// Fine-tune stat printing
Int_t curoptstat = gStyle->GetOptStat();
gStyle->SetOptStat(1100);
// Create the sorted list
TIter nxw(&fWrksInfo);
TWrkInfo *wi = 0;
while ((wi = (TWrkInfo *)nxw())) {
Int_t j = 0;
for (j = 1; j < hact10->GetNbinsX()+1 ; j++) {
if (wi->fStart < hact10->GetBinLowEdge(j))
hact10->Fill(hact10->GetBinCenter(j));
}
for (j = 1; j < hact11->GetNbinsX()+1 ; j++) {
if (wi->fStop > hact11->GetBinLowEdge(j))
hact11->Fill(hact11->GetBinCenter(j));
}
hact2->Fill(wi->fStop);
}
// Display histos
TCanvas *c1 = new TCanvas("perf", GetCanvasTitle("Activity histos"), 800,10,700,780);
c1->Divide(1,2);
TPad *pad1 = (TPad *) c1->GetPad(1);
pad1->Divide(2,1);
TPad *pad10 = (TPad *) pad1->GetPad(1);
TPad *pad11 = (TPad *) pad1->GetPad(2);
pad10->cd();
DoDraw(hact10);
pad11->cd();
DoDraw(hact11);
TPad *pad2 = (TPad *) c1->GetPad(2);
pad2->cd();
DoDraw(hact2);
c1->cd();
c1->Update();
// Restore stat options
gStyle->SetOptStat(curoptstat);
// Done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Print information for all or the slowest showlast workers.
/// Use showlast < 0 to print all
void TProofPerfAnalysis::PrintWrkInfo(Int_t showlast)
{
// Create the sorted list
Int_t k = fWrksInfo.GetSize();
TIter nxw(&fWrksInfo);
TWrkInfo *wi = 0;
while ((wi = (TWrkInfo *)nxw())) {
// Print info about slowest workers
k--;
if (showlast < 0 || k < showlast) wi->Print();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Print information for worker 'wn' (ordinal) or on the machine whose
/// ordinal or fqdn matches 'wn'. Multiple specifications separated by ','
/// or ' ' are supported, as well as wildcards '*', e.g. '0.2*,lxb10* lxf2323.doma.in"
void TProofPerfAnalysis::PrintWrkInfo(const char *wn)
{
if (!wn || (wn && strlen(wn) <= 0)) {
Error("PrintWrkInfo", "worker name or host must be defined!");
return;
}
// Check exact name
TWrkInfo *wi = (TWrkInfo *) fWrksInfo.FindObject(wn);
if (wi) {
wi->Print();
} else {
// Check matching
TString ww(wn), w;
TIter nxw(&fWrksInfo);
while ((wi = (TWrkInfo *)nxw())) {
TString n(wi->GetName()), t(wi->GetTitle());
Ssiz_t from = 0;
while (ww.Tokenize(w, from, "[, ]")) {
TRegexp re(w, kTRUE);
if (n.Index(re) != kNPOS || t.Index(re) != kNPOS) wi->Print();
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Print information for all or the slowest showlast workers.
/// Use showlast < 0 to print all
void TProofPerfAnalysis::PrintFileInfo(Int_t showlast, const char *opt, const char *out)
{
RedirectHandle_t rh;
if (out && strlen(out) > 0) gSystem->RedirectOutput(out, "w", &rh);
// Create the sorted list
Int_t k = fFilesInfo.GetSize();
TIter nxf(&fFilesInfo);
TFileInfo *fi = 0;
while ((fi = (TFileInfo *)nxf())) {
// Print info about files processed last
k--;
if (showlast < 0 || k < showlast) fi->Print(opt);
}
if (out && strlen(out) > 0) gSystem->RedirectOutput(0, 0, &rh);
}
////////////////////////////////////////////////////////////////////////////////
/// Print information for file 'fn' (path including directory) or server 'fn'.
/// Multiple specifications separated by ','
/// or ' ' are supported, as well as wildcards '*', e.g. 'pippo.root, h4mu*,lxb10*"
void TProofPerfAnalysis::PrintFileInfo(const char *fn, const char *opt, const char *out)
{
if (!fn || (fn && strlen(fn) <= 0)) {
Error("PrintFileInfo", "file path must be defined!");
return;
}
RedirectHandle_t rh;
if (out && strlen(out) > 0) gSystem->RedirectOutput(out, "w", &rh);
// Check exact name
TFileInfo *fi = (TFileInfo *) fFilesInfo.FindObject(fn);
if (fi) {
fi->Print(opt);
} else {
// Check matching
TString fw(fn), f;
TIter nxf(&fFilesInfo);
while ((fi = (TFileInfo *)nxf())) {
TString n(fi->GetName()), s(fi->GetTitle());
Ssiz_t from = 0;
while (fw.Tokenize(f, from, "[, ]")) {
TRegexp re(f, kTRUE);
if (n.Index(re) != kNPOS || s.Index(re) != kNPOS) fi->Print(opt);
}
}
}
if (out && strlen(out) > 0) gSystem->RedirectOutput(0, 0, &rh);
}
////////////////////////////////////////////////////////////////////////////////
/// Fill basic worker info; if 'force' rescan the TTree even already done
void TProofPerfAnalysis::FillWrkInfo(Bool_t force)
{
// Nothing to do if already called
if (fWrksInfo.GetSize() > 0 && !force) return;
// Cleanup existing information
fWrksInfo.SetOwner(kTRUE);
fWrksInfo.Clear();
fInitTime = -1.;
fMergeTime = -1.;
fMaxTime = -1.;
fEvtRateMax = -1.;
fMBRateMax = -1.;
fLatencyMax = -1.;
TList *wl = new TList;
// Extract worker information
TPerfEvent pe;
TPerfEvent* pep = &pe;
fTree->SetBranchAddress("PerfEvents",&pep);
Long64_t entries = fTree->GetEntries();
// First determine binning for global rates
Int_t nraw = entries * 2, jj = 0, kk = 0;
Double_t *xraw = new Double_t[nraw];
for (Long64_t k=0; k<entries; k++) {
fTree->GetEntry(k);
// Analyse only packets
if (pe.fType == TVirtualPerfStats::kPacket) {
Float_t stop = pe.fTimeStamp.GetSec() + 1e-9*pe.fTimeStamp.GetNanoSec();
Float_t start = stop - pe.fProcTime;
// Bins
xraw[jj++] = start;
xraw[jj++] = stop;
}
}
Int_t nbins = jj;
Int_t *jidx = new Int_t[nbins];
memset(jidx, 0, nbins * sizeof(Int_t));
TMath::Sort(nbins, xraw, jidx, kFALSE);
Double_t *xbins = new Double_t[nbins];
jj = 0;
for (kk = 0; kk < nbins; kk++) {
Double_t xtmp = xraw[jidx[kk]];
if (jj == 0 || xtmp > xbins[jj - 1] + .5) {
xbins[jj] = xtmp;
jj++;
}
}
nbins = jj;
delete [] xraw;
delete [] jidx;
// Create the global histograms
Int_t nbin = nbins - 1;
TObject *o = 0;
if ((o = gDirectory->FindObject("gEvtRate"))) delete o;
fEvtRate = new TH1F("gEvtRate", "Total event processing rate (evt/s)", nbin, xbins);
fEvtRate->SetMinimum(0.);