31 TProofLog::TProofLog(
const char *stag,
const char *url, TProofMgr *mgr)
40 fStartTime.Set((UInt_t)0);
43 Int_t idx = st.Index(
'-');
50 fStartTime.Set(st.Atoi());
59 TProofLog::~TProofLog()
67 TProofLogElem *TProofLog::Add(
const char *ord,
const char *url)
69 TProofLogElem *ple =
new TProofLogElem(ord, url,
this);
87 Int_t TProofLog::Retrieve(
const char *ord, TProofLog::ERetrieveOpt opt,
88 const char *fname,
const char *pattern)
91 if (opt == TProofLog::kGrep && (!pattern || strlen(pattern) <= 0)) {
92 Error(
"Retrieve",
"option 'Grep' requires a pattern");
96 Int_t nel = (ord[0] ==
'*') ? fElem->GetSize() : 1;
99 TProofLogElem *ple = 0;
100 Int_t nd = 0, nb = 0;
102 while ((ple = (TProofLogElem *) nxe())) {
103 if (ord[0] ==
'*' || !strcmp(ord, ple->GetName())) {
104 if (ple->Retrieve(opt, pattern) != 0) {
109 Float_t frac = ((Float_t)nd + (Float_t)nb) * 100. / (Float_t)nel;
110 msg.Form(
"Retrieving logs: %d ok, %d not ok (%.0f%% processed)\r", nd, nb, frac);
111 Prt(msg.Data(), kFALSE);
131 void TProofLog::Display(
const char *ord, Int_t from, Int_t to)
135 Int_t nel = (fElem) ? fElem->GetSize() : 0;
137 msg.Form(
"\n// --------- Displaying PROOF Session logs --------\n"
138 "// Server: %s \n// Session: %s \n// # of elements: %d \n"
139 "// ------------------------------------------------\n\n",
140 GetTitle(), GetName(), nel);
145 TProofLogElem *ple = 0;
146 while ((ple = (TProofLogElem *) nxe())) {
147 if (ord[0] ==
'*' || !strcmp(ord, ple->GetName()))
148 ple->Display(from, to);
152 Prt(
"// --------- End of PROOF Session logs ---------\n");
158 void TProofLog::Print(Option_t *opt)
const
160 Int_t nel = (fElem) ? fElem->GetSize() : 0;
162 fprintf(stderr,
"// --------- PROOF Session logs object --------\n");
163 fprintf(stderr,
"// Server: %s \n", GetTitle());
164 fprintf(stderr,
"// Session: %s \n", GetName());
165 fprintf(stderr,
"// # of elements: %d \n", nel);
166 fprintf(stderr,
"// --------------------------------------------\n");
170 TProofLogElem *ple = 0;
171 while ((ple = (TProofLogElem *) nxe()))
175 fprintf(stderr,
"// --------------------------------------------\n");
181 void TProofLog::Prt(
const char *what, Bool_t newline)
186 EmitVA(
"Prt(const char*)", 2, what, kFALSE);
188 FILE *where = (fFILE) ? (FILE *)fFILE : stderr;
190 if (newline) fputc(
'\n', where);
201 Int_t TProofLog::Save(
const char *ord,
const char *fname, Option_t *opt)
205 Warning(
"Save",
"filename undefined - do nothing");
211 TString option = opt;
214 if (option.Contains(
"a")){
215 fout = fopen(fname,
"a");
217 fout = fopen(fname,
"w");
220 Warning(
"Save",
"file could not be opened - do nothing");
223 fFILE = (
void *) fout;
227 Int_t nel = (fElem) ? fElem->GetSize() : 0;
229 msg.Form(
"\n// --------- Displaying PROOF Session logs --------\n"
230 "// Server: %s \n// Session: %s \n// # of elements: %d \n"
231 "// ------------------------------------------------\n\n",
232 GetTitle(), GetName(), nel);
238 TProofLogElem *ple = 0;
239 while ((ple = (TProofLogElem *) nxe())) {
240 if (ord[0] ==
'*' || !strcmp(ord, ple->GetName()))
246 Prt(
"// --------- End of PROOF Session logs ---------\n");
261 Int_t TProofLog::Grep(
const char *txt, Int_t from)
263 if (!txt || strlen(txt) <= 0) {
264 Warning(
"Grep",
"text to be searched for is undefined - do nothing");
268 Int_t nel = (fElem) ? fElem->GetSize() : 0;
271 msg.Form(
"\n// --------- Search in PROOF Session logs --------\n"
272 "// Server: %s \n// Session: %s \n// # of elements: %d \n"
273 "// Text searched for: \"%s\"", GetTitle(), GetName(), nel, txt);
276 msg.Form(
"// starting from line %d \n", from);
281 Prt(
"// ------------------------------------------------\n");
285 TProofLogElem *ple = 0;
286 while ((ple = (TProofLogElem *) nxe())) {
288 Int_t nf = ple->Grep(txt, res, from);
290 msg.Form(
"// Ord: %s - line(s): %s\n", ple->GetName(), res.Data());
295 Prt(
"// ------------------------------------------------\n");
304 void TProofLog::SetMaxTransferSize(Long64_t maxsz)
306 TProofLogElem::SetMaxTransferSize(maxsz);
313 Long64_t TProofLogElem::fgMaxTransferSize = 100000;
318 TProofLogElem::TProofLogElem(
const char *ord,
const char *url,
329 if (strstr(GetTitle(),
"worker-")) {
332 if (strchr(GetName(),
'.')) {
343 TProofLogElem::~TProofLogElem()
351 Long64_t TProofLogElem::GetMaxTransferSize()
353 return fgMaxTransferSize;
359 void TProofLogElem::SetMaxTransferSize(Long64_t maxsz)
361 fgMaxTransferSize = maxsz;
374 Int_t TProofLogElem::Retrieve(TProofLog::ERetrieveOpt opt,
const char *pattern)
377 if (!fLogger->fMgr || !fLogger->fMgr->IsValid()) {
378 Warning(
"Retrieve",
"No reference manager: corruption?");
384 Info(
"Retrieve",
"Retrieving from ordinal %s file %s with pattern %s",
385 GetName(), GetTitle(), (pattern ? pattern :
"(no pattern)"));
389 if (opt == TProofLog::kAll) {
394 Info(
"Retrieve",
"Retrieving the whole file");
395 }
else if (opt == TProofLog::kLeading) {
398 fTo = fgMaxTransferSize;
400 Info(
"Retrieve",
"Retrieving the leading %lld lines of file", fTo);
401 }
else if (opt == TProofLog::kGrep) {
403 if (!pattern || strlen(pattern) <= 0) {
404 Error(
"Retrieve",
"option 'Grep' requires a pattern");
408 Info(
"Retrieve",
"Retrieving only lines filtered with %s", pattern);
411 fFrom = -fgMaxTransferSize;
414 Info(
"Retrieve",
"Retrieving the last %lld lines of file", -fFrom);
422 Long64_t len = (fTo > fFrom) ? fTo - fFrom : -1;
427 TString fileName = GetTitle();
428 if (fileName.Contains(
"__igprof.pp__")) {
431 Info(
"Retrieve",
"Retrieving analyzed IgProf performance profile");
432 TString analyzeAndFilter = \
433 "|( T=`mktemp` && cat > \"$T\" ; igprof-analyse -d -g \"$T\" ; rm -f \"$T\" )";
434 if (pattern && (*pattern ==
'|'))
435 analyzeAndFilter.Append(pattern);
436 os = fLogger->fMgr->ReadBuffer(fileName.Data(), analyzeAndFilter.Data());
438 else if (opt == TProofLog::kGrep)
439 os = fLogger->fMgr->ReadBuffer(fileName.Data(), pattern);
441 os = fLogger->fMgr->ReadBuffer(fileName.Data(), fFrom, len);
447 while (os->String().Tokenize(ln, from,
"\n"))
448 fMacro->AddLine(ln.Data());
467 void TProofLogElem::Display(Int_t from, Int_t to)
469 Int_t nls = (fMacro->GetListOfLines()) ?
470 fMacro->GetListOfLines()->GetSize() : 0;
474 Int_t ie = (to > -1 && to < nls) ? to : nls;
478 }
else if (from < 0) {
486 Prt(
"// --------- Start of element log -----------------\n");
487 msg.Form(
"// Ordinal: %s (role: %s)\n", GetName(), fRole.Data());
490 TString path(GetTitle());
491 Int_t ic = path.Index(
",");
494 path.Remove(0, ic+1);
496 msg.Form(
"// Submaster: %s \n", subm.Data());
499 msg.Form(
"// Path: %s \n// # of retrieved lines: %d ", path.Data(), nls);
501 if (i > 0 || ie < nls) {
502 msg.Form(
"(displaying lines: %d -> %d)\n", i+1, ie);
507 Prt(
"// ------------------------------------------------\n");
510 if (fMacro->GetListOfLines()) {
511 TIter nxl(fMacro->GetListOfLines());
514 while ((os = (TObjString *) nxl())) {
517 if (msg.Length() < 100000) {
518 if (msg.Length() > 0) msg +=
"\n";
519 msg += os->GetName();
528 if (msg.Length() > 0) Prt(msg.Data());
530 Prt(
"// --------- End of element log -------------------\n\n");
536 void TProofLogElem::Print(Option_t *)
const
538 Int_t nls = (fMacro->GetListOfLines()) ?
539 fMacro->GetListOfLines()->GetSize() : 0;
540 const char *role = (strstr(GetTitle(),
"worker-")) ?
"worker" :
"master";
542 fprintf(stderr,
"Ord: %s Host: Role: %s lines: %d\n", GetName(), role, nls);
548 void TProofLogElem::Prt(
const char *what)
559 Int_t TProofLogElem::Grep(
const char *txt, TString &res, Int_t from)
561 Int_t nls = (fMacro->GetListOfLines()) ?
562 fMacro->GetListOfLines()->GetSize() : 0;
565 Int_t i = (from > 0) ? (from - 1) : 0;
566 for( ; i < nls; i++) {
567 TObjString *os = (TObjString *) fMacro->GetListOfLines()->At(i);
569 if (strstr(os->GetName(), txt)) {
570 if (res.Length() > 0)