ROOT  6.06/09
Reference Guide
TPerfStats.cxx
Go to the documentation of this file.
1 // @(#)root/proofplayer:$Id$
2 // Author: Kristjan Gulbrandsen 11/05/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TPerfStats //
15 // //
16 // Provides the interface for the PROOF internal performance measurment //
17 // and event tracing. //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 
21 
22 #include "TPerfStats.h"
23 
24 #include "Riostream.h"
25 #include "TCollection.h"
26 #include "TEnv.h"
27 #include "TError.h"
28 #include "TFile.h"
29 #include "TH1.h"
30 #include "TH2.h"
31 #include "TDSet.h"
32 #include "TProofDebug.h"
33 #include "TProof.h"
34 #include "TProofServ.h"
35 #include "TSlave.h"
36 #include "TStatus.h"
37 #include "TTree.h"
38 #include "TSQLServer.h"
39 #include "TSQLResult.h"
40 #include "TParameter.h"
41 #include "TPluginManager.h"
42 #include "TROOT.h"
43 #include "TTimeStamp.h"
44 #include "TProofMonSender.h"
45 
48 
49 
50 //------------------------------------------------------------------------------
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Constructor
54 
56  : fEvtNode("-3"), fType(TVirtualPerfStats::kUnDefined), fSlave(),
57  fEventsProcessed(0), fBytesRead(0), fLen(0), fLatency(0.0), fProcTime(0.0), fCpuTime(0.0),
58  fIsStart(kFALSE), fIsOk(kFALSE)
59 {
60  if (gProofServ != 0) {
61  fEvtNode = gProofServ->GetOrdinal();
62  } else {
63  if (gProof && gProof->IsLite())
64  fEvtNode = "0";
65  else
66  fEvtNode = "-2"; // not on a PROOF server
67  }
68 
69  if (offset != 0) {
70  fTimeStamp = TTimeStamp(fTimeStamp.GetSec() - offset->GetSec(),
71  fTimeStamp.GetNanoSec() - offset->GetNanoSec());
72  }
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// Compare method. Must return -1 if this is smaller than obj,
77 /// 0 if objects are equal and 1 if this is larger than obj.
78 
80 {
81  const TPerfEvent *pe = dynamic_cast<const TPerfEvent*>(obj);
82 
83  if (!pe) {
84  Error("Compare", "input is not a TPerfEvent object");
85  return 0;
86  }
87 
88  if (fTimeStamp < pe->fTimeStamp) {
89  return -1;
90  } else if (fTimeStamp == pe->fTimeStamp) {
91  return 0;
92  } else {
93  return 1;
94  }
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Dump content of this instance
99 
101 {
102  TString where;
103  if (fEvtNode == -2) {
104  where = "TPerfEvent: StandAlone ";
105  } else if ( fEvtNode == -1 ) {
106  where = "TPerfEvent: Master ";
107  } else {
108  where.Form("TPerfEvent: Worker %s ", fEvtNode.Data());
109  }
110  Printf("%s %s %f", where.Data(),
112 }
113 
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Normal constructor.
119 
121  : fTrace(0), fPerfEvent(0), fPacketsHist(0), fProcPcktHist(0),
122  fEventsHist(0), fLatencyHist(0),
123  fProcTimeHist(0), fCpuTimeHist(0), fBytesRead(0),
124  fTotCpuTime(0.), fTotBytesRead(0), fTotEvents(0), fNumEvents(0),
125  fSlaves(0), fDoHist(kFALSE),
126  fDoTrace(kFALSE), fDoTraceRate(kFALSE), fDoSlaveTrace(kFALSE), fDoQuota(kFALSE),
127  fMonitorPerPacket(kFALSE), fMonSenders(3),
128  fDataSet("+++none+++"), fDataSetSize(-1), fOutput(output)
129 {
131 
132  // Master flag
133  Bool_t isMaster = ((proof && proof->TestBit(TProof::kIsMaster)) ||
135  Bool_t isEndMaster = ((gProofServ && gProofServ->IsEndMaster()) ||
136  (proof && proof->IsLite())) ? kTRUE : kFALSE;
137 
138  TList *l = 0;
139  Bool_t deletel = kFALSE;
140  TParameter<Int_t> *dyns = (TParameter<Int_t> *) input->FindObject("PROOF_DynamicStartup");
141  if (dyns) {
142  // When starring up dynamically the number of slots needs to be guessed from the
143  // maximum workers request. There is no way to change this later on.
144  Int_t nwrks = dyns->GetVal();
145  if (nwrks > 0) {
146  l = new TList;
147  for (Int_t i = 0; i < nwrks; i++) {
148  TSlaveInfo *wi = new TSlaveInfo(TString::Format("0.%d", i));
150  l->Add(wi);
151  }
152  l->SetOwner(kTRUE);
153  deletel = kTRUE;
154  }
155  }
156  if (!l) l = proof ? proof->GetListOfSlaveInfos() : 0 ;
157 
158  TIter nextslaveinfo(l);
159  while (TSlaveInfo *si = dynamic_cast<TSlaveInfo*>(nextslaveinfo()))
161 
162  PDB(kMonitoring,1) Info("TPerfStats", "Statistics for %d slave(s)", fSlaves);
163 
164  fDoHist = (input->FindObject("PROOF_StatsHist") != 0);
165  fDoTrace = (input->FindObject("PROOF_StatsTrace") != 0);
166  fDoTraceRate = (input->FindObject("PROOF_RateTrace") != 0);
167  fDoSlaveTrace = (input->FindObject("PROOF_SlaveStatsTrace") != 0);
168  PDB(kMonitoring,1)
169  Info("TPerfStats", "master:%d hist:%d,trace:%d,rate:%d,wrktrace:%d",
171 
172  // Check per packet monitoring
173  Int_t perpacket = -1;
174  if (TProof::GetParameter(input, "PROOF_MonitorPerPacket", perpacket) != 0) {
175  // Check if there is a global monitor-per-packet setting
176  perpacket = gEnv->GetValue("Proof.MonitorPerPacket", 0);
177  }
178  fMonitorPerPacket = (perpacket == 1) ? kTRUE : kFALSE;
179  if (fMonitorPerPacket)
180  Info("TPerfStats", "sending full information after each packet");
181 
182  // Extract the name of the dataset
183  TObject *o = 0;
184  TIter nxi(input);
185  while ((o = nxi()))
186  if (!strncmp(o->ClassName(), "TDSet", strlen("TDSet"))) break;
187  if (o) {
188  fDSet = (TDSet *) o;
190  if (fDataSetSize > 0) {
191  fDataSet = "";
192  TString grus = (gProofServ) ? TString::Format("/%s/%s/", gProofServ->GetGroup(),
193  gProofServ->GetUser()) : TString("");
194  TString dss = fDSet->GetName(), ds;
195  Ssiz_t fd = 0, nq = kNPOS;
196  while (dss.Tokenize(ds, fd, "[,| ]")) {
197  if ((nq = ds.Index("?")) != kNPOS) ds.Remove(nq);
198  ds.ReplaceAll(grus, "");
199  if (!fDataSet.IsNull()) fDataSet += ",";
200  fDataSet += ds;
201  }
202  }
203  }
204 
205  // Dataset string limited in length: get the authorized size
206  fDataSetLen = gEnv->GetValue("Proof.Monitor.DataSetLen", 512);
207  if (fDataSetLen != 512)
208  Info("TPerfStats", "dataset string length truncated to %d chars", fDataSetLen);
210  //
211  PDB(kMonitoring,1)
212  Info("TPerfStats", "dataset: '%s', # files: %d", fDataSet.Data(), fDataSetSize);
213 
214  if ((isMaster && (fDoTrace || fDoTraceRate)) || (!isMaster && fDoSlaveTrace)) {
215  // Construct tree
216  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_PerfStats"));
217  fTrace = new TTree("PROOF_PerfStats", "PROOF Statistics");
218  fTrace->SetDirectory(0);
219  fTrace->Bronch("PerfEvents", "TPerfEvent", &fPerfEvent, 64000, 0);
220  output->Add(fTrace);
221  PDB(kMonitoring,1)
222  Info("TPerfStats", "tree '%s' added to the output list", fTrace->GetName());
223  }
224 
225  if (fDoHist && isEndMaster) {
226  // Make Histograms
227  Double_t time_per_bin = 1e-3; // 10ms
228  Double_t min_time = 0;
229  Int_t ntime_bins = 1000;
230 
231  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_PacketsHist"));
232  fPacketsHist = new TH1D("PROOF_PacketsHist", "Packets processed per Worker",
233  fSlaves, 0, fSlaves);
237  output->Add(fPacketsHist);
238  PDB(kMonitoring,1)
239  Info("TPerfStats", "histo '%s' added to the output list", fPacketsHist->GetName());
240 
241  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_ProcPcktHist"));
242  fProcPcktHist = new TH1I("PROOF_ProcPcktHist", "Packets being processed per Worker",
243  fSlaves, 0, fSlaves);
247  output->Add(fProcPcktHist);
248  PDB(kMonitoring,1)
249  Info("TPerfStats", "histo '%s' added to the output list", fProcPcktHist->GetName());
250 
251  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_EventsHist"));
252  fEventsHist = new TH1D("PROOF_EventsHist", "Events processed per Worker",
253  fSlaves, 0, fSlaves);
257  output->Add(fEventsHist);
258  PDB(kMonitoring,1)
259  Info("TPerfStats", "histo '%s' added to the output list", fEventsHist->GetName());
260 
261  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_NodeHist"));
262  fNodeHist = new TH1D("PROOF_NodeHist", "Slaves per Fileserving Node",
263  fSlaves, 0, fSlaves);
265  fNodeHist->SetMinimum(0);
267  output->Add(fNodeHist);
268  PDB(kMonitoring,1)
269  Info("TPerfStats", "histo '%s' added to the output list", fNodeHist->GetName());
270 
271  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_LatencyHist"));
272  fLatencyHist = new TH2D("PROOF_LatencyHist", "GetPacket Latency per Worker",
273  fSlaves, 0, fSlaves,
274  ntime_bins, min_time, time_per_bin);
278  output->Add(fLatencyHist);
279  PDB(kMonitoring,1)
280  Info("TPerfStats", "histo '%s' added to the output list", fLatencyHist->GetName());
281 
282  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_ProcTimeHist"));
283  fProcTimeHist = new TH2D("PROOF_ProcTimeHist", "Packet Processing Time per Worker",
284  fSlaves, 0, fSlaves,
285  ntime_bins, min_time, time_per_bin);
289  output->Add(fProcTimeHist);
290  PDB(kMonitoring,1)
291  Info("TPerfStats", "histo '%s' added to the output list", fProcTimeHist->GetName());
292 
293  gDirectory->RecursiveRemove(gDirectory->FindObject("PROOF_CpuTimeHist"));
294  fCpuTimeHist = new TH2D("PROOF_CpuTimeHist", "Packet CPU Time per Worker",
295  fSlaves, 0, fSlaves,
296  ntime_bins, min_time, time_per_bin);
300  output->Add(fCpuTimeHist);
301  PDB(kMonitoring,1)
302  Info("TPerfStats", "histo '%s' added to the output list", fCpuTimeHist->GetName());
303 
304  nextslaveinfo.Reset();
305  Int_t slavebin=1;
306  while (TSlaveInfo *si = dynamic_cast<TSlaveInfo*>(nextslaveinfo())) {
307  if (si->fStatus == TSlaveInfo::kActive) {
308  fPacketsHist->GetXaxis()->SetBinLabel(slavebin, si->GetOrdinal());
309  fProcPcktHist->GetXaxis()->SetBinLabel(slavebin, si->GetOrdinal());
310  fEventsHist->GetXaxis()->SetBinLabel(slavebin, si->GetOrdinal());
311  fNodeHist->GetXaxis()->SetBinLabel(slavebin, si->GetOrdinal());
312  fLatencyHist->GetXaxis()->SetBinLabel(slavebin, si->GetOrdinal());
313  fProcTimeHist->GetXaxis()->SetBinLabel(slavebin, si->GetOrdinal());
314  fCpuTimeHist->GetXaxis()->SetBinLabel(slavebin, si->GetOrdinal());
315  slavebin++;
316  }
317  }
318  }
319  // Cleanup
320  if (deletel) delete(l);
321 
322  if (isMaster) {
323 
324  // Monitoring for query performances using monitoring system (e.g. Monalisa, SQL, ...)
325  //
326  // We support multiple specifications separated by ',' or '|' or '\' (the latter need
327  // top be escaped three times in the regular experession), e.g.
328  // ProofServ.Monitoring: Monalisa bla bla bla,
329  // +ProofServ.Monitoring: SQL blu blu blu
330 
331  TString mons = gEnv->GetValue("ProofServ.Monitoring", ""), mon;
332  Ssiz_t fmon = 0;
333  TProofMonSender *monSender = 0;
334  while (mons.Tokenize(mon, fmon, "[,|\\\\]")) {
335  if (mon != "") {
336  // Extract arguments (up to 9 'const char *')
337  TString a[10];
338  Int_t from = 0;
339  TString tok, sendopts;
340  Int_t na = 0;
341  while (mon.Tokenize(tok, from, " ")) {
342  if (tok.BeginsWith("sendopts:")) {
343  tok.ReplaceAll("sendopts:", "");
344  sendopts = tok;
345  } else {
346  a[na++] = tok;
347  }
348  }
349  na--;
350  // Get monitor object from the plugin manager
351  TPluginHandler *h = 0;
352  if ((h = gROOT->GetPluginManager()->FindHandler("TProofMonSender", a[0]))) {
353  if (h->LoadPlugin() != -1) {
354  monSender =
355  (TProofMonSender *) h->ExecPlugin(na, a[1].Data(), a[2].Data(), a[3].Data(),
356  a[4].Data(), a[5].Data(), a[6].Data(),
357  a[7].Data(), a[8].Data(), a[9].Data());
358  if (monSender && monSender->TestBit(TObject::kInvalidObject)) SafeDelete(monSender);
359  if (monSender && monSender->SetSendOptions(sendopts) != 0) SafeDelete(monSender);
360  }
361  }
362  }
363 
364  if (monSender) {
365  fMonSenders.Add(monSender);
366  PDB(kMonitoring,1)
367  Info("TPerfStats", "created monitoring object: %s - # of active monitors: %d",
368  mon.Data(), fMonSenders.GetEntries());
369  fDoQuota = kTRUE;
370  }
371  monSender = 0;
372  }
373  }
374 }
375 
376 ////////////////////////////////////////////////////////////////////////////////
377 /// Destructor
378 
380 {
381  // Shutdown the monitor writers, if any
384 }
385 
386 ////////////////////////////////////////////////////////////////////////////////
387 /// Simple event.
388 
390 {
391  if (type == kStop && fPacketsHist != 0) {
393  fPacketsHist->LabelsOption("auv","X");
394  }
395 
396  if (type == kStop && fDoQuota)
397  WriteQueryLog();
398 
399  if (fTrace == 0) return;
400 
401  TPerfEvent pe(&fTzero);
402  pe.fType = type;
403 
404  fPerfEvent = &pe;
405  fTrace->SetBranchAddress("PerfEvents",&fPerfEvent);
406  fTrace->Fill();
407  fPerfEvent = 0;
408 }
409 
410 ////////////////////////////////////////////////////////////////////////////////
411 /// Packet event.
412 /// See WriteQueryLog for the descripition of the structure sent for monitoring
413 /// when fMonitorPerPacket is kTRUE.
414 
415 void TPerfStats::PacketEvent(const char *slave, const char* slavename, const char* filename,
416  Long64_t eventsprocessed, Double_t latency, Double_t proctime,
417  Double_t cputime, Long64_t bytesRead)
418 {
419  if (fDoTrace && fTrace != 0) {
420  TPerfEvent pe(&fTzero);
421 
422  pe.fType = kPacket;
423  pe.fSlaveName = slavename;
424  pe.fFileName = filename;
425  pe.fSlave = slave;
426  pe.fEventsProcessed = eventsprocessed;
427  pe.fBytesRead = bytesRead;
428  pe.fLatency = latency;
429  pe.fProcTime = proctime;
430  pe.fCpuTime = cputime;
431 
432  fPerfEvent = &pe;
433  fTrace->SetBranchAddress("PerfEvents",&fPerfEvent);
434  fTrace->Fill();
435  fPerfEvent = 0;
436  }
437 
438  PDB(kMonitoring,1)
439  Info("PacketEvent","%s: fDoHist: %d, fPacketsHist: %p, eventsprocessed: %lld",
440  slave, fDoHist, fPacketsHist, eventsprocessed);
441 
442  if (fDoHist && fPacketsHist != 0) {
443  fPacketsHist->Fill(slave, 1);
444  fEventsHist->Fill(slave, eventsprocessed);
445  fLatencyHist->Fill(slave, latency, 1);
446  fProcTimeHist->Fill(slave, proctime, 1);
447  fCpuTimeHist->Fill(slave, cputime, 1);
448  }
449 
450  if (fDoQuota) {
451  fTotCpuTime += cputime;
452  fTotBytesRead += bytesRead;
453  fTotEvents += eventsprocessed;
454  }
455 
456  // Write to monitoring system, if requested
460  if (!gProofServ || !gProofServ->GetSessionTag() || !gProofServ->GetProof() || !qr) {
461  Error("PacketEvent", "some required object are undefined (%p %p %p %p)",
463  (gProofServ ? gProofServ->GetProof() : 0),
464  ((gProofServ && gProofServ->GetProof()) ? qr : 0));
465  return;
466  }
467 
468  TTimeStamp stop;
469  TString identifier;
470  identifier.Form("%s-q%d", gProofServ->GetSessionTag(), qr->GetSeqNum());
471 
472  TList values;
473  values.SetOwner();
474  values.Add(new TParameter<int>("id", 0));
475  values.Add(new TNamed("user", gProofServ->GetUser()));
476  values.Add(new TNamed("proofgroup", gProofServ->GetGroup()));
477  values.Add(new TNamed("begin", fTzero.AsString("s")));
478  values.Add(new TNamed("end", stop.AsString("s")));
479  values.Add(new TParameter<int>("walltime", stop.GetSec()-fTzero.GetSec()));
480  values.Add(new TParameter<Long64_t>("bytesread", fTotBytesRead));
481  values.Add(new TParameter<Long64_t>("events", fTotEvents));
482  values.Add(new TParameter<Long64_t>("totevents", fNumEvents));
483  values.Add(new TParameter<int>("workers", fSlaves));
484  values.Add(new TNamed("querytag", identifier.Data()));
485 
486  // Memory usage on workers
487  TStatus *pst = (fOutput) ? (TStatus *) fOutput->FindObject("PROOF_Status") : 0;
488  // This most likely will be always NULL when sending from GetNextPacket ...
489  Long64_t vmxw = (pst) ? (Long64_t) pst->GetVirtMemMax() : -1;
490  Long64_t rmxw = (pst) ? (Long64_t) pst->GetResMemMax() : -1;
491  values.Add(new TParameter<Long64_t>("vmemmxw", vmxw));
492  values.Add(new TParameter<Long64_t>("rmemmxw", rmxw));
493  // Memory usage on master
494  values.Add(new TParameter<Long64_t>("vmemmxm", (Long64_t) fgVirtMemMax));
495  values.Add(new TParameter<Long64_t>("rmemmxm", (Long64_t) fgResMemMax));
496  // Dataset information
497  values.Add(new TNamed("dataset", fDataSet.Data()));
498  values.Add(new TParameter<int>("numfiles", fDataSetSize));
499  // Missing files
500  TList *mfls = (fOutput) ? (TList *) fOutput->FindObject("MissingFiles") : 0;
501  Int_t nmiss = (mfls && mfls->GetSize() > 0) ? mfls->GetSize() : 0;
502  values.Add(new TParameter<int>("missfiles", nmiss));
503  // Query status
504  Int_t est = (pst) ? pst->GetExitStatus() : -1;
505  values.Add(new TParameter<int>("status", est));
506  // Root version
507  TString rver = TString::Format("%s|%s", gROOT->GetVersion(), gROOT->GetGitCommit());
508  values.Add(new TNamed("rootver", rver.Data()));
509 
510  for (Int_t i = 0; i < fMonSenders.GetEntries(); i++) {
512  if (m) {
513  // Send query summary
514  if (m->SendSummary(&values, identifier) != 0)
515  Error("PacketEvent", "sending of summary info failed (%s)", m->GetName());
516  } else {
517  Warning("PacketEvent", "undefined entry found in monitors array for id: %d", i);
518  }
519  }
520  }
521 }
522 
523 ////////////////////////////////////////////////////////////////////////////////
524 /// File event.
525 
526 void TPerfStats::FileEvent(const char *slave, const char *slavename, const char *nodename,
527  const char *filename, Bool_t isStart)
528 {
529  if (fDoTrace && fTrace != 0) {
530  TPerfEvent pe(&fTzero);
531 
532  pe.fType = kFile;
533  pe.fSlaveName = slavename;
534  pe.fNodeName = nodename;
535  pe.fFileName = filename;
536  pe.fSlave = slave;
537  pe.fIsStart = isStart;
538 
539  fPerfEvent = &pe;
540  fTrace->SetBranchAddress("PerfEvents",&fPerfEvent);
541  fTrace->Fill();
542  fPerfEvent = 0;
543  }
544 
545  if (fDoHist && fPacketsHist != 0) {
546  fNodeHist->Fill(nodename, isStart ? 1 : -1);
547  }
548 }
549 
550 ////////////////////////////////////////////////////////////////////////////////
551 /// Open file event.
552 
553 void TPerfStats::FileOpenEvent(TFile *file, const char *filename, Double_t start)
554 {
555  if (fDoTrace && fTrace != 0) {
556  TPerfEvent pe(&fTzero);
557 
558  pe.fType = kFileOpen;
559  pe.fFileName = filename;
560  pe.fFileClass = file != 0 ? file->ClassName() : "none";
561  pe.fProcTime = double(TTimeStamp())-start;
562  pe.fIsOk = (file != 0);
563 
564  fPerfEvent = &pe;
565  fTrace->SetBranchAddress("PerfEvents",&fPerfEvent);
566  fTrace->Fill();
567  fPerfEvent = 0;
568  }
569 }
570 
571 ////////////////////////////////////////////////////////////////////////////////
572 /// Read file event.
573 
575 {
576  if (fDoTrace && fTrace != 0) {
577  TPerfEvent pe(&fTzero);
578 
579  pe.fType = kFileRead;
580  pe.fFileName = file->GetName();
581  pe.fFileClass = file->ClassName();
582  pe.fLen = len;
583  pe.fProcTime = double(TTimeStamp())-start;
584 
585  fPerfEvent = &pe;
586  fTrace->SetBranchAddress("PerfEvents",&fPerfEvent);
587  fTrace->Fill();
588  fPerfEvent = 0;
589  }
590 }
591 
592 ////////////////////////////////////////////////////////////////////////////////
593 /// Record TTree file unzip event.
594 /// start is the TimeStamp before unzip
595 /// pos is where in the file the compressed buffer came from
596 /// complen is the length of the compressed buffer
597 /// objlen is the length of the de-compressed buffer
598 
599 void TPerfStats::UnzipEvent(TObject * /* tree */, Long64_t /* pos */,
600  Double_t /* start */, Int_t /* complen */,
601  Int_t /* objlen */)
602 {
603  // Do nothing for now.
604 }
605 
606 ////////////////////////////////////////////////////////////////////////////////
607 /// Rate event.
608 
609 void TPerfStats::RateEvent(Double_t proctime, Double_t deltatime,
610  Long64_t eventsprocessed, Long64_t bytesRead)
611 {
612  if ((fDoTrace || fDoTraceRate) && fTrace != 0) {
613  TPerfEvent pe(&fTzero);
614 
615  pe.fType = kRate;
616  pe.fEventsProcessed = eventsprocessed;
617  pe.fBytesRead = bytesRead;
618  pe.fProcTime = proctime;
619  pe.fLatency = deltatime;
620 
621  fPerfEvent = &pe;
622  fTrace->SetBranchAddress("PerfEvents",&fPerfEvent);
623  fTrace->Fill();
624  fPerfEvent = 0;
625  }
626 }
627 
628 ////////////////////////////////////////////////////////////////////////////////
629 /// Set number of bytes read.
630 
632 {
633  fBytesRead = num;
634 }
635 
636 ////////////////////////////////////////////////////////////////////////////////
637 /// Get number of bytes read.
638 
640 {
641  return fBytesRead;
642 }
643 
644 ////////////////////////////////////////////////////////////////////////////////
645 /// Send to the connected monitoring servers information related to this query.
646 /// The information is of three types: 'summary', 'dataset' and 'files'.
647 /// Actual 'table' formatting is done by the relevant sender, implementation of
648 /// TProofMonSender, where the details are given.
649 
651 {
652  TTimeStamp stop;
653 
654  // Write to monitoring system
655  if (!fMonSenders.IsEmpty()) {
658  if (!gProofServ || !gProofServ->GetSessionTag() || !gProofServ->GetProof() || !qr) {
659  Error("WriteQueryLog", "some required object are undefined (%p %p %p %p)",
661  (gProofServ ? gProofServ->GetProof() : 0),
662  ((gProofServ && gProofServ->GetProof()) ? qr : 0));
663  return;
664  }
665 
666  TString identifier;
667  identifier.Form("%s-q%d", gProofServ->GetSessionTag(), qr->GetSeqNum());
668 
669  TList values;
670  values.SetOwner();
671  values.Add(new TParameter<int>("id", 0));
672  values.Add(new TNamed("user", gProofServ->GetUser()));
673  values.Add(new TNamed("proofgroup", gProofServ->GetGroup()));
674  values.Add(new TNamed("begin", fTzero.AsString("s")));
675  values.Add(new TNamed("end", stop.AsString("s")));
676  values.Add(new TParameter<int>("walltime", stop.GetSec()-fTzero.GetSec()));
677  values.Add(new TParameter<float>("cputime", fTotCpuTime));
678  values.Add(new TParameter<Long64_t>("bytesread", fTotBytesRead));
679  values.Add(new TParameter<Long64_t>("events", fTotEvents));
680  values.Add(new TParameter<Long64_t>("totevents", fTotEvents));
681  values.Add(new TParameter<int>("workers", fSlaves));
682  values.Add(new TNamed("querytag", identifier.Data()));
683 
684  TList *mfls = (fOutput) ? (TList *) fOutput->FindObject("MissingFiles") : 0;
685  // Memory usage on workers
686  TStatus *pst = (fOutput) ? (TStatus *) fOutput->FindObject("PROOF_Status") : 0;
687  Long64_t vmxw = (pst) ? (Long64_t) pst->GetVirtMemMax() : -1;
688  Long64_t rmxw = (pst) ? (Long64_t) pst->GetResMemMax() : -1;
689  values.Add(new TParameter<Long64_t>("vmemmxw", vmxw));
690  values.Add(new TParameter<Long64_t>("rmemmxw", rmxw));
691  // Memory usage on master
692  values.Add(new TParameter<Long64_t>("vmemmxm", (Long64_t) fgVirtMemMax));
693  values.Add(new TParameter<Long64_t>("rmemmxm", (Long64_t) fgResMemMax));
694  // Dataset information
695  values.Add(new TNamed("dataset", fDataSet.Data()));
696  values.Add(new TParameter<int>("numfiles", fDataSetSize));
697  // Missing files
698  Int_t nmiss = (mfls && mfls->GetSize() > 0) ? mfls->GetSize() : 0;
699  values.Add(new TParameter<int>("missfiles", nmiss));
700  // Query status
701  Int_t est = (pst) ? pst->GetExitStatus() : -1;
702  values.Add(new TParameter<int>("status", est));
703  // Root version
704  TString rver = TString::Format("%s|%s", gROOT->GetVersion(), gROOT->GetGitCommit());
705  values.Add(new TNamed("rootver", rver.Data()));
706 
707  for (Int_t i = 0; i < fMonSenders.GetEntries(); i++) {
709  if (m) {
710  // Send query summary
711  if (m->SendSummary(&values, identifier) != 0)
712  Error("WriteQueryLog", "sending of summary info failed (%s)", m->GetName());
713  // Send dataset information
714  if (m->SendDataSetInfo(fDSet, mfls, fTzero.AsString("s"), identifier) != 0)
715  Error("WriteQueryLog", "sending of dataset info failed (%s)", m->GetName());
716  // Send file information
717  if (m->SendFileInfo(fDSet, mfls, fTzero.AsString("s"), identifier) != 0)
718  Error("WriteQueryLog", "sending of files info failed (%s)", m->GetName());
719  } else {
720  Warning("WriteQueryLog", "undefined entry found in monitors array for id: %d", i);
721  }
722  }
723  }
724 }
725 
726 ////////////////////////////////////////////////////////////////////////////////
727 /// Setup the PROOF input list with requested statistics and tracing options.
728 
730 {
731  const Int_t ntags=3;
732  const char *tags[ntags] = {"StatsHist", "StatsTrace", "SlaveStatsTrace"};
733 
734  TString varname, parname;
735  for (Int_t i=0; i<ntags; i++) {
736  varname.Form("Proof.%s", tags[i]);
737  parname.Form("PROOF_%s", tags[i]);
738  if (!input->FindObject(parname))
739  if (gEnv->GetValue(varname, 0)) input->Add(new TNamed(parname.Data(),""));
740  }
741 }
742 
743 ////////////////////////////////////////////////////////////////////////////////
744 /// Initialize PROOF statistics run.
745 
747 {
748  if (gPerfStats)
749  delete gPerfStats;
750  fgVirtMemMax = -1;
751  fgResMemMax = -1;
753 
754  gPerfStats = new TPerfStats(input, output);
755  if (gPerfStats && !gPerfStats->TestBit(TObject::kInvalidObject)) {
756  // This measures the time taken by the constructor: not negligeable ...
758  } else {
760  }
761 }
762 
763 ////////////////////////////////////////////////////////////////////////////////
764 /// Terminate the PROOF statistics run.
765 
767 {
768  if (!gPerfStats) return;
769 
771  gPerfStats->SimpleEvent(TVirtualPerfStats::kStop);
772 
773  delete gPerfStats;
774  gPerfStats = 0;
775 }
776 
777 ////////////////////////////////////////////////////////////////////////////////
778 /// Record memory usage
779 
781 {
782  ProcInfo_t pi;
783  if (!gSystem->GetProcInfo(&pi)){
786  }
787 }
788 
789 ////////////////////////////////////////////////////////////////////////////////
790 /// Get memory usage
791 
793 {
794  vmax = fgVirtMemMax;
795  rmax = fgResMemMax;
796 }
Bool_t fIsOk
Definition: TPerfStats.h:67
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
TVirtualPerfStats::EEventType fType
Definition: TPerfStats.h:54
Int_t GetSeqNum() const
Definition: TQueryResult.h:123
THist< 2, double > TH2D
Definition: THist.h:320
long long Long64_t
Definition: RtypesCore.h:69
virtual void LabelsOption(Option_t *option="h", Option_t *axis="X")
Set option(s) to draw axis with labels.
Definition: TH1.cxx:4901
const char * AsString(const Option_t *option="") const
Return the date & time as a string.
Definition: TTimeStamp.cxx:269
Bool_t fDoHist
number of active slaves
Definition: TPerfStats.h:102
TH1D * fEventsHist
histogram of packets being processed per slave
Definition: TPerfStats.h:90
Ssiz_t Length() const
Definition: TString.h:390
const double pi
TList * fOutput
Saved pointer to the TDSet object.
Definition: TPerfStats.h:116
Bool_t IsEmpty() const
Definition: TObjArray.h:72
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8266
Provides the interface for the PROOF internal performance measurement and event tracing.
const char Option_t
Definition: RtypesCore.h:62
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:328
Definition: Rtypes.h:61
Int_t SetSendOptions(const char *)
Parse send options from string 'sendopts'.
Long_t GetVirtMemMax(Bool_t master=kFALSE) const
Definition: TStatus.h:71
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
#define gDirectory
Definition: TDirectory.h:218
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4328
Definition: TDSet.h:153
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
static const char * EventType(EEventType type)
Return the name of the event type.
TH1 * h
Definition: legend2.C:5
TDSet * fDSet
of files in the dataset
Definition: TPerfStats.h:115
Int_t GetNumOfFiles()
Return the number of files in the dataset.
Definition: TDSet.cxx:1979
const char * GetSessionTag() const
Definition: TProofServ.h:257
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
PyObject * fTrace
static const char * filename()
Bool_t fIsStart
Definition: TPerfStats.h:66
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
#define gROOT
Definition: TROOT.h:340
TPerfStats(TList *input, TList *output)
Max resident memory used by this process.
Definition: TPerfStats.cxx:120
Int_t GetExitStatus() const
Definition: TStatus.h:69
THist< 1, int > TH1I
Definition: THist.h:317
Int_t LoadPlugin()
Load the plugin library for this handler.
TString fSlaveName
Definition: TPerfStats.h:55
const char * GetOrdinal() const
Definition: TProof.h:255
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:496
TTimeStamp fTzero
TTree with trace events.
Definition: TPerfStats.h:86
TString fNodeName
Definition: TPerfStats.h:56
Definition: Rtypes.h:61
Long64_t fNumEvents
total number of events processed
Definition: TPerfStats.h:99
Double_t fCpuTime
Definition: TPerfStats.h:65
static Long_t fgVirtMemMax
Saved pointer to the output list.
Definition: TPerfStats.h:118
const char * GetGroup() const
Definition: TProofServ.h:254
Long_t ExecPlugin(int nargs, const T &...params)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
Long64_t GetBytesRead() const
Get number of bytes read.
Definition: TPerfStats.cxx:639
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2443
THist< 1, double > TH1D
Definition: THist.h:314
void Reset()
Definition: TCollection.h:161
void WriteQueryLog()
Send to the connected monitoring servers information related to this query.
Definition: TPerfStats.cxx:650
const char * Data() const
Definition: TString.h:349
void PacketEvent(const char *slave, const char *slavename, const char *filename, Long64_t eventsprocessed, Double_t latency, Double_t proctime, Double_t cputime, Long64_t bytesRead)
Packet event.
Definition: TPerfStats.cxx:415
#define SafeDelete(p)
Definition: RConfig.h:436
TH1D * fNodeHist
histogram of events processed per slave
Definition: TPerfStats.h:91
void RateEvent(Double_t proctime, Double_t deltatime, Long64_t eventsprocessed, Long64_t bytesRead)
Rate event.
Definition: TPerfStats.cxx:609
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
#define PDB(mask, level)
Definition: TProofDebug.h:58
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition: TTree.cxx:7529
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual Int_t SendSummary(TList *, const char *)=0
TH2D * fLatencyHist
histogram of slaves per file serving node
Definition: TPerfStats.h:92
TH1D * fPacketsHist
TPerfEvent used to fill tree.
Definition: TPerfStats.h:88
void SimpleEvent(EEventType type)
Simple event.
Definition: TPerfStats.cxx:389
Bool_t fDoQuota
Full tracing in workers.
Definition: TPerfStats.h:106
TString fEvtNode
Definition: TPerfStats.h:52
TObjArray fMonSenders
Whether to send the full entry per each packet.
Definition: TPerfStats.h:110
ESlaveStatus fStatus
Definition: TProof.h:245
TQueryResult * GetQueryResult(const char *ref=0)
Return pointer to the full TQueryResult instance owned by the player and referenced by 'ref'...
Definition: TProof.cxx:2143
void SetBytesRead(Long64_t num)
Set number of bytes read.
Definition: TPerfStats.cxx:631
static void GetMemValues(Long_t &vmax, Long_t &rmax)
Get memory usage.
Definition: TPerfStats.cxx:792
Long_t GetResMemMax(Bool_t master=kFALSE) const
Definition: TStatus.h:70
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Double_t fTotCpuTime
track bytes read of main file
Definition: TPerfStats.h:96
Bool_t fDoSlaveTrace
Trace processing rate in master.
Definition: TPerfStats.h:105
A container class for query results.
Definition: TQueryResult.h:44
TList * GetListOfSlaveInfos()
Returns list of TSlaveInfo's. In case of error return 0.
Definition: TProof.cxx:2316
static void Start(TList *input, TList *output)
Initialize PROOF statistics run.
Definition: TPerfStats.cxx:746
Bool_t IsLite() const
Definition: TProof.h:966
TObject * GetParameter(const char *par) const
Get specified parameter.
Definition: TProof.cxx:10485
A doubly linked list.
Definition: TList.h:47
TH1I * fProcPcktHist
histogram of packets processed per slave
Definition: TPerfStats.h:89
void UnzipEvent(TObject *tree, Long64_t pos, Double_t start, Int_t complen, Int_t objlen)
Record TTree file unzip event.
Definition: TPerfStats.cxx:599
TString fDataSet
Monitoring engines.
Definition: TPerfStats.h:112
static void Setup(TList *input)
Setup the PROOF input list with requested statistics and tracing options.
Definition: TPerfStats.cxx:729
Named parameter, streamable and storable.
Definition: TParameter.h:49
Long64_t fTotEvents
total bytes read on all slaves
Definition: TPerfStats.h:98
time_t GetSec() const
Definition: TTimeStamp.h:140
Bool_t fMonitorPerPacket
Save stats on SQL server for quota management.
Definition: TPerfStats.h:108
virtual Int_t SendDataSetInfo(TDSet *, TList *, const char *, const char *)=0
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
TPerfEvent * fPerfEvent
start time of this run
Definition: TPerfStats.h:87
Long64_t fEventsProcessed
Definition: TPerfStats.h:60
Double_t fProcTime
Definition: TPerfStats.h:64
Int_t fSlaves
total number of events to be processed
Definition: TPerfStats.h:100
TProof * GetProof() const
Definition: TProofServ.h:249
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
Long_t fMemVirtual
Definition: TSystem.h:207
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2321
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual void LabelsDeflate(Option_t *axis="X")
Reduce the number of bins for the axis passed in the option to the number of bins having a label...
Definition: TH1.cxx:4776
TMarker * m
Definition: textangle.C:8
TString fFileName
Definition: TPerfStats.h:57
Long64_t fBytesRead
histogram of cpu time spent processing packets
Definition: TPerfStats.h:95
TLine * l
Definition: textangle.C:4
Bool_t IsEndMaster() const
Definition: TProofServ.h:304
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
Int_t fDataSetSize
Maximum size of the dataset string fDataSet.
Definition: TPerfStats.h:114
void SetStatus(ESlaveStatus stat)
Definition: TProof.h:257
Bool_t IsNull() const
Definition: TString.h:387
static Long_t fgResMemMax
Max virtual memory used by this process.
Definition: TPerfStats.h:119
virtual TBranch * Bronch(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99)
Create a new TTree BranchElement.
Definition: TTree.cxx:2187
const char * GetUser() const
Definition: TProofServ.h:253
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2240
#define Printf
Definition: TGeoToOCC.h:18
#define gPerfStats
PyObject * fType
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
R__EXTERN TProof * gProof
Definition: TProof.h:1110
TTimeStamp fTimeStamp
Definition: TPerfStats.h:53
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
Definition: TTree.cxx:8095
TString fSlave
Definition: TPerfStats.h:59
double Double_t
Definition: RtypesCore.h:55
Bool_t IsMaster() const
Definition: TProofServ.h:305
void Print(Option_t *option="") const
Dump content of this instance.
Definition: TPerfStats.cxx:100
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
const char * GetOrdinal() const
Definition: TProofServ.h:265
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:76
Definition: TProof.h:339
TString fFileClass
Definition: TPerfStats.h:58
virtual Int_t SendFileInfo(TDSet *, TList *, const char *, const char *)=0
Int_t fDataSetLen
Dataset string.
Definition: TPerfStats.h:113
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:793
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:493
Long64_t fLen
Definition: TPerfStats.h:62
Bool_t fDoTrace
Fill histos.
Definition: TPerfStats.h:103
Definition: Rtypes.h:61
void FileOpenEvent(TFile *file, const char *filename, Double_t start)
Open file event.
Definition: TPerfStats.cxx:553
virtual UInt_t SetCanExtend(UInt_t extendBitMask)
make the histogram axes extendable / not extendable according to the bit mask returns the previous bi...
Definition: TH1.cxx:6211
Mother of all ROOT objects.
Definition: TObject.h:58
const char Int_t const char TProof * proof
Definition: TXSlave.cxx:46
Long64_t fBytesRead
Definition: TPerfStats.h:61
ClassImp(TPerfEvent) ClassImp(TPerfStats) TPerfEvent
Constructor.
Definition: TPerfStats.cxx:46
TTree * fTrace
Definition: TPerfStats.h:85
R__EXTERN TProofServ * gProofServ
Definition: TProofServ.h:359
virtual ~TPerfStats()
Destructor.
Definition: TPerfStats.cxx:379
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
Long64_t fTotBytesRead
total cpu time of all slaves
Definition: TPerfStats.h:97
Bool_t fDoTraceRate
Trace details in master.
Definition: TPerfStats.h:104
Double_t fLatency
Definition: TPerfStats.h:63
ClassImp(TSlaveInfo) Int_t TSlaveInfo const TSlaveInfo * si
Used to sort slaveinfos by ordinal.
Definition: TProof.cxx:167
void FileEvent(const char *slave, const char *slavename, const char *nodename, const char *filename, Bool_t isStart)
File event.
Definition: TPerfStats.cxx:526
static void Stop()
Terminate the PROOF statistics run.
Definition: TPerfStats.cxx:766
void Add(TObject *obj)
Definition: TObjArray.h:75
A TTree object has a header with a name and a title.
Definition: TTree.h:94
TH2D * fCpuTimeHist
histogram of real time spent processing packets
Definition: TPerfStats.h:94
const AParamType & GetVal() const
Definition: TParameter.h:77
static void output(int code)
Definition: gifencode.c:226
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:285
TObject * obj
TH2D * fProcTimeHist
histogram of latency due to packet requests
Definition: TPerfStats.h:93
static void SetMemValues()
Record memory usage.
Definition: TPerfStats.cxx:780
void FileReadEvent(TFile *file, Int_t len, Double_t start)
Read file event.
Definition: TPerfStats.cxx:574
Int_t Compare(const TObject *obj) const
Compare method.
Definition: TPerfStats.cxx:79
Long_t fMemResident
Definition: TSystem.h:206
TAxis * GetXaxis()
Definition: TH1.h:319
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1058
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904