27 const UInt_t kLogElemFilled = BIT(17);
28 const UInt_t kDefaultActive = BIT(18);
40 ClassImp(TProofProgressLog);
45 TProofProgressLog::TProofProgressLog(TProofProgressDialog *d, Int_t w, Int_t h) :
46 TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), w, h)
49 if (fDialog) fSessionUrl = fDialog->fSessionUrl;
58 TProofProgressLog::TProofProgressLog(
const char *url, Int_t idx, Int_t w, Int_t h) :
59 TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), w, h)
63 fSessionIdx = (idx > 0) ? -idx : idx;
71 void TProofProgressLog::Init(Int_t w, Int_t h)
77 SetCleanup(kDeepCleanup);
80 TGHorizontalFrame *htotal =
new TGHorizontalFrame(
this, w, h);
81 TGVerticalFrame *vtextbox =
new TGVerticalFrame(htotal, w, h);
83 fText =
new TGTextView(vtextbox, w, h);
84 vtextbox->AddFrame(fText,
new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3));
87 fVworkers =
new TGVerticalFrame(htotal);
89 TGLabel *laburl =
new TGLabel(fVworkers,
"Enter cluster URL:");
90 fVworkers->AddFrame(laburl,
new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 2, 2, 2));
91 fUrlText =
new TGTextEntry(fVworkers);
92 fUrlText->SetText(fSessionUrl.Data());
93 fVworkers->AddFrame(fUrlText,
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 0, 0, 0));
95 TGHorizontalFrame *hfurlbox =
new TGHorizontalFrame(fVworkers, 20, 20);
96 TGLabel *labsess =
new TGLabel(hfurlbox,
"Enter session:");
97 hfurlbox->AddFrame(labsess,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 2, 2, 2));
98 fSessNum =
new TGNumberEntry(hfurlbox, 0, 5, -1, TGNumberFormat::kNESInteger);
99 fSessNum->SetLimits(TGNumberFormat::kNELLimitMax, 0., 0.);
100 fSessNum->SetIntNumber(0);
101 fSessNum->GetNumberEntry()->SetToolTipText(
"Use 0 for the last known one,"
102 " negative numbers for the previous ones, e.g. -1 for the last-but-one");
103 hfurlbox->AddFrame(fSessNum,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 0, 0, 0));
104 fUrlButton =
new TGTextButton(hfurlbox,
"Get logs info");
105 fUrlButton->Connect(
"Clicked()",
"TProofProgressLog",
this,
"Rebuild()");
106 hfurlbox->AddFrame(fUrlButton,
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 4, 0, 0, 0));
107 fVworkers->AddFrame(hfurlbox,
new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
109 TGNumberEntry *nent =
new TGNumberEntry(hfurlbox);
110 fVworkers->AddFrame(nent,
new TGLayoutHints(kLHintsTop | kLHintsLeft, 4, 0, 0, 0));
115 fLogList->Resize(102,52);
116 fLogList->SetMultipleSelections(kTRUE);
119 TGHorizontalFrame *hfselbox =
new TGHorizontalFrame(fVworkers, 20, 20);
120 TGLabel *label1 =
new TGLabel(hfselbox,
"Choose workers:");
121 hfselbox->AddFrame(label1,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 0, 0, 0, 0));
122 TGTextButton *selall =
new TGTextButton(hfselbox,
" &All ");
123 selall->Connect(
"Clicked()",
"TProofProgressLog",
this,
"Select(=0)");
124 hfselbox->AddFrame(selall,
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 10, 0, 0, 0));
125 TGTextButton *clearall =
new TGTextButton(hfselbox,
" &Clear ");
126 clearall->Connect(
"Clicked()",
"TProofProgressLog",
this,
"Select(=1)");
127 hfselbox->AddFrame(clearall,
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 10, 0, 0, 0));
133 fLogNew =
new TGTextButton(fVworkers,
"&Display");
134 fLogNew->Connect(
"Clicked()",
"TProofProgressLog",
this,
"DoLog(=kFALSE)");
137 fLogNew->SetTextColor(0xffffff, kFALSE);
138 fLogNew->SetBackgroundColor(0x000044);
139 fVworkers->AddFrame(hfselbox,
new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 2, 2, 2));
140 fVworkers->AddFrame(fLogList,
new TGLayoutHints(kLHintsExpandX | kLHintsTop | kLHintsExpandY, 2, 2, 5, 2));
141 fVworkers->AddFrame(fLogNew,
new TGLayoutHints(kLHintsExpandX | kLHintsTop , 2, 2, 1, 5));
143 htotal->AddFrame(fVworkers,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft | kLHintsExpandY, 2, 2, 2, 2));
146 TGHorizontalFrame *hflogbox =
new TGHorizontalFrame(vtextbox, 550, 20);
147 fClose =
new TGTextButton(hflogbox,
" &Close ");
148 fClose->Connect(
"Clicked()",
"TProofProgressLog",
this,
"CloseWindow()");
149 hflogbox->AddFrame(fClose,
new TGLayoutHints(kLHintsCenterY |
150 kLHintsRight, 10, 2, 2, 2));
153 fSave =
new TGTextButton(hflogbox,
"&Save");
154 fSave->Connect(
"Clicked()",
"TProofProgressLog",
this,
"SaveToFile()");
155 hflogbox->AddFrame(fSave,
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 4, 0, 0, 0));
156 fFileName =
new TGTextEntry(hflogbox);
157 fFileName->SetText(
"<session-tag>.log");
158 hflogbox->AddFrame(fFileName,
new TGLayoutHints(kLHintsCenterY | kLHintsRight | kLHintsExpandX));
159 TGLabel *label10 =
new TGLabel(hflogbox,
"Save to a file:");
160 hflogbox->AddFrame(label10,
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 50, 2, 2, 2));
163 TGVerticalFrame *vlines =
new TGVerticalFrame(hflogbox);
164 TGHorizontalFrame *vlines_buttons =
new TGHorizontalFrame(vlines);
165 TGLabel *label2 =
new TGLabel(vlines_buttons,
"Lines:");
166 vlines_buttons->AddFrame(label2,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
168 fAllLines =
new TGCheckButton(vlines_buttons,
"all");
169 fAllLines->SetToolTipText(
"Retrieve all lines (service messages excluded)");
170 fAllLines->SetState(kButtonUp);
171 fAllLines->Connect(
"Clicked()",
"TProofProgressLog",
this,
"NoLineEntry()");
172 vlines_buttons->AddFrame(fAllLines,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
174 fRawLines =
new TGCheckButton(vlines_buttons,
"svcmsg");
175 fRawLines->SetToolTipText(
"Retrieve all type of lines, service messages included");
176 fRawLines->SetState(kButtonUp);
177 vlines_buttons->AddFrame(fRawLines,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
179 TGLabel *label11 =
new TGLabel(vlines_buttons,
"From");
180 vlines_buttons->AddFrame(label11,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
182 fLinesFrom =
new TGNumberEntry(vlines_buttons, 0, 5, -1, TGNumberFormat::kNESInteger);
184 fLinesFrom->SetIntNumber(-100);
185 fLinesFrom->GetNumberEntry()->SetToolTipText(
"Negative values indicate \"tail\" action");
188 vlines_buttons->AddFrame(fLinesFrom,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
190 TGLabel *label3 =
new TGLabel(vlines_buttons,
"to");
191 vlines_buttons->AddFrame(label3,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
192 fLinesTo =
new TGNumberEntry(vlines_buttons, 0, 5, -1, TGNumberFormat::kNESInteger);
193 vlines_buttons->AddFrame(fLinesTo,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
194 vlines->AddFrame(vlines_buttons,
new TGLayoutHints(kLHintsCenterY));
195 hflogbox->AddFrame(vlines,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
201 TGHorizontalFrame *hfgrepbox =
new TGHorizontalFrame(vtextbox, 550, 20);
204 fGrepLabel =
new TGLabel(hfgrepbox,
"");
205 hfgrepbox->AddFrame(fGrepLabel,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
206 fGrepText =
new TGTextEntry(hfgrepbox);
208 TGDimension dim = fGrepText->GetDefaultSize();
209 fGrepText->SetDefaultSize(400, dim.fHeight);
211 hfgrepbox->AddFrame(fGrepText,
new TGLayoutHints( kLHintsCenterY | kLHintsLeft | kLHintsExpandX));
212 fGrepButton =
new TGTextButton(hfgrepbox,
"Filter");
213 fGrepButton->Connect(
"Clicked()",
"TProofProgressLog",
this,
"DoLog(=kTRUE)");
214 hfgrepbox->AddFrame(fGrepButton,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4, 10, 0, 0));
217 fGrepCheckInv =
new TGCheckButton(hfgrepbox,
"invert match");
218 fGrepCheckInv->Connect(
"Clicked()",
"TProofProgressLog",
this,
"SetGrepView()");
219 hfgrepbox->AddFrame(fGrepCheckInv,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
221 fGrepCheckCmd =
new TGCheckButton(hfgrepbox,
"is a pipe command");
222 fGrepCheckCmd->Connect(
"Clicked()",
"TProofProgressLog",
this,
"SetGrepView()");
223 hfgrepbox->AddFrame(fGrepCheckCmd,
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
233 vtextbox->AddFrame(hflogbox,
new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
234 vtextbox->AddFrame(hfgrepbox,
new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
235 htotal->AddFrame(vtextbox,
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY | kLHintsRight, 3, 3, 3, 3));
236 AddFrame(htotal,
new TGLayoutHints(kLHintsExpandX |
237 kLHintsExpandY, 3, 3, 3, 3));
248 TProofProgressLog::~TProofProgressLog()
251 SafeDelete(fProofLog);
255 fDialog->fLogWindow = 0;
256 fDialog->fProof->Disconnect(
"LogMessage(const char*,Bool_t)",
this,
257 "LogMessage(const char*,Bool_t)");
264 void TProofProgressLog::Popup()
272 void TProofProgressLog::Clear(Option_t *)
281 void TProofProgressLog::LoadBuffer(
const char *buffer)
284 fText->LoadBuffer(buffer);
290 void TProofProgressLog::LoadFile(
const char *file)
293 fText->LoadFile(file);
299 void TProofProgressLog::AddBuffer(
const char *buffer)
303 txt.LoadBuffer(buffer);
304 fText->AddText(&txt);
311 void TProofProgressLog::CloseWindow()
320 void TProofProgressLog::BuildLogList(Bool_t create)
324 title.Form(
"PROOF - Processing logs for session 'undefined'");
325 SetWindowName(title.Data());
326 SetIconName(title.Data());
330 if (fLogList)
delete fLogList;
331 fLogList =
new TGListBox(fVworkers);
334 Int_t nent = fLogList->GetNumberOfEntries();
335 fLogList->RemoveEntries(0,nent);
339 if (fSessionUrl.IsNull()) {
341 Info(
"BuildLogList",
"sesssion URL undefined - do nothing");
344 TProofMgr *mgr = TProof::Mgr(fSessionUrl.Data());
345 if (!mgr || !mgr->IsValid()) {
346 Warning(
"BuildLogList",
"unable open a manager connection to %s",
350 if (!(fProofLog = mgr->GetSessionLogs(fSessionIdx,
"NR"))) {
351 Warning(
"BuildLogList",
"unable to get logs from %s",
356 title.Form(
"PROOF - Processing logs for session '%s', started on %s at %s",
357 fProofLog->GetName(), fProofLog->StartTime().AsString(),
358 fProofLog->GetTitle());
359 SetWindowName(title.Data());
360 SetIconName(title.Data());
362 TList *elem = fProofLog->GetListOfLogs();
364 TProofLogElem *pe = 0;
369 while ((pe=(TProofLogElem*)next())){
370 TUrl url(pe->GetTitle());
371 buf.Form(
"%s %s", pe->GetName(), url.GetHost());
372 fLogList->AddEntry(buf.Data(), is);
373 if ((ent = fLogList->FindEntry(buf.Data()))) {
374 ent->ResetBit(kLogElemFilled);
375 ent->ResetBit(kDefaultActive);
376 if (!(pe->IsWorker())) ent->SetBit(kDefaultActive);
389 void TProofProgressLog::DoLog(Bool_t grep)
394 Warning(
"DoLog",
"no text: do nothing!");
398 TString greptext = fGrepText->GetText();
399 greptext.Remove(TString::kBoth,
' ');
400 if (greptext.IsNull()) {
403 else if (!fGrepCheckCmd->IsOn()) {
405 TPMERegexp san(
"(^|[^\\\\])([^a-zA-Z0-9_=\\\\/.-])");
406 while ( san.Substitute(greptext,
"$1\\$2") > 0 );
410 if (fAllLines->IsOn()){
414 from = fLinesFrom->GetIntNumber();
415 to = fLinesTo->GetIntNumber();
421 if ((mgr = TProof::Mgr(fSessionUrl.Data()))) {
422 if (!(fProofLog = mgr->GetSessionLogs(fSessionIdx,
"NR"))) {
423 Warning(
"DoLog",
"unable to instantiate TProofLog for %s",
427 Warning(
"DoLog",
"unable to instantiate a TProofMgr for %s",
436 if (!fRawLines->IsOn()) {
437 pipeCommand =
"grep -v \"| SvcMsg\"";
441 Bool_t retrieve = kFALSE;
445 ((fTextType != kRaw && fRawLines->IsOn()) ||
446 (fTextType != kStd && !fRawLines->IsOn())) ||
447 (fDialog && fDialog->fStatus==TProofProgressDialog::kRunning)) {
449 if (fRawLines->IsOn()) {
454 if (fDialog && fDialog->fStatus != TProofProgressDialog::kRunning)
461 if (!pipeCommand.IsNull())
462 pipeCommand.Append(
'|');
464 if (fGrepCheckCmd->IsOn()) {
465 pipeCommand.Append(greptext);
468 pipeCommand.Append(
"grep ");
469 if (fGrepCheckInv->IsOn())
470 pipeCommand.Append(
"-v ");
471 pipeCommand.Append(
"-- ");
472 pipeCommand.Append(greptext);
475 if (fDialog && fDialog->fStatus != TProofProgressDialog::kRunning)
481 TList *selected =
new TList;
482 fLogList->GetSelectedEntries(selected);
483 TIter next(selected);
484 TGTextLBEntry *selentry;
485 Bool_t logonly = fProofLog->LogToBox();
486 fProofLog->SetLogToBox(kTRUE);
488 fProofLog->Connect(
"Prt(const char*)",
"TProofProgressLog",
489 this,
"LogMessage(const char*, Bool_t)");
490 while ((selentry=(TGTextLBEntry*)next())){
491 TString ord = selentry->GetText()->GetString();
492 Int_t is = ord.Index(
" ");
493 if (is != kNPOS) ord.Remove(is);
494 if (retrieve || !selentry->TestBit(kLogElemFilled)) {
495 pipeCommand.Prepend(
'|');
496 if (fTextType == kRaw) {
498 Info(
"DoLog",
"Retrieving unfiltered log for %s", ord.Data());
499 fProofLog->Retrieve(ord.Data(), TProofLog::kTrailing, 0, 0);
503 Info(
"DoLog",
"Retrieving log for %s filtered with %s",
504 ord.Data(), pipeCommand.Data());
505 fProofLog->Retrieve(ord.Data(), TProofLog::kGrep, 0, pipeCommand.Data());
507 selentry->SetBit(kLogElemFilled);
509 fProofLog->Display(ord.Data(), from, to);
511 fProofLog->SetLogToBox(logonly);
512 fProofLog->Disconnect(
"Prt(const char*)",
this,
"LogMessage(const char*, Bool_t)");
520 void TProofProgressLog::LogMessage(
const char *msg, Bool_t all)
535 void TProofProgressLog::SaveToFile()
537 if (!fProofLog) DoLog();
540 TString filename = fFileName->GetText();
541 if (filename.IsNull() || filename ==
"<session-tag>.log") {
542 filename = (fDialog && fDialog->fProof) ?
543 TString::Format(
"%s.log", fDialog->fProof->GetName()) :
544 TString(
"proof.log");
547 TList *selected =
new TList;
548 fLogList->GetSelectedEntries(selected);
549 TIter next(selected);
550 TGTextLBEntry *selentry;
551 Bool_t writemode=kTRUE;
554 while ((selentry=(TGTextLBEntry*)next())){
555 ord = selentry->GetText()->GetString();
556 Int_t isp = ord.Index(
' ');
557 if (isp != kNPOS) ord.Remove(isp);
559 option = writemode ?
"w" :
"a";
560 fProofLog->Save(ord.Data(), filename.Data(), option);
564 Info(
"SaveToFile",
"logs saved to file %s", filename.Data());
571 void TProofProgressLog::SetGrepView()
573 if (fGrepCheckCmd->IsOn()) {
574 fGrepLabel->SetText(
"Pipe log through command:");
575 fGrepCheckInv->SetDisabledAndSelected(kFALSE);
578 fGrepLabel->SetText(
"Grep:");
579 Bool_t u = fGrepCheckInv->IsOn();
580 fGrepCheckInv->SetEnabled(kTRUE);
582 fGrepLabel->SetText(
"Show lines not matching:");
583 fGrepCheckInv->SetState(kButtonDown);
586 fGrepLabel->SetText(
"Show lines matching:");
587 fGrepCheckInv->SetState(kButtonUp);
592 TGFrame *frame =
dynamic_cast<TGFrame *
>(
const_cast<TGWindow *
>(fGrepLabel->GetParent()) );
593 if (frame) frame->Layout();
600 void TProofProgressLog::NoLineEntry()
602 if (fAllLines->IsOn()){
604 fLinesFrom->SetState(kFALSE);
605 fLinesTo->SetState(kFALSE);
607 fLinesFrom->SetState(kTRUE);
608 fLinesTo->SetState(kTRUE);
615 void TProofProgressLog::Select(Int_t
id, Bool_t all)
617 Int_t nen = fLogList->GetNumberOfEntries();
618 Bool_t sel =
id ? 0 : 1;
621 for (Int_t ie=0; ie<nen; ie++) {
623 fLogList->Select(ie, sel);
625 if ((ent = fLogList->GetEntry(ie))) {
626 if (ent->TestBit(kDefaultActive)) fLogList->Select(ie, sel);
636 void TProofProgressLog::Rebuild()
639 Bool_t sameurl = kFALSE;
640 TUrl url(fUrlText->GetText());
641 TUrl urlref(fSessionUrl.Data());
642 if (!strcmp(url.GetHostFQDN(), urlref.GetHostFQDN())) {
643 if (url.GetPort() == urlref.GetPort()) {
644 if (!strcmp(url.GetUser(), urlref.GetUser())) {
651 idx = fSessNum->GetIntNumber();
652 if (idx == fSessionIdx) {
653 Info(
"Rebuild",
"same paremeters {%s, %s}, {%d, %d}: no need to rebuild TProofLog",
654 url.GetUrl(), urlref.GetUrl(), idx, fSessionIdx);
659 if (fProofLog)
delete fProofLog;
662 fSessionUrl = fUrlText->GetText();
666 BuildLogList(kFALSE);