00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <functional>
00028 #include <stdexcept>
00029 #include <algorithm>
00030
00031 #include "TGTextView.h"
00032 #include "TGLabel.h"
00033 #include "TGTab.h"
00034 #include "TGButton.h"
00035 #include "TGNumberEntry.h"
00036 #include "TGSplitter.h"
00037 #include "TGButtonGroup.h"
00038 #include "TGComboBox.h"
00039 #include "TObjArray.h"
00040
00041 #include "TMemStat.h"
00042 #include "TMemStatViewerGUI.h"
00043 #include "TMemStatResource.h"
00044 #include "TMemStatDrawDlg.h"
00045
00046 ClassImp(TMemStatViewerGUI)
00047
00048 using namespace std;
00049
00050
00051
00052 struct SStringToListBox_t : public binary_function<string, TGComboBox*, bool> {
00053 bool operator()(string str, TGComboBox* box) const {
00054 if (!box)
00055 return false;
00056
00057 box->AddEntry(str.c_str(), box->GetNumberOfEntries());
00058 return true;
00059 }
00060 };
00061
00062
00063 struct SFillListBox_t : public binary_function<TObject*, TGComboBox*, bool> {
00064 bool operator()(TObject *aObj, TGComboBox* box) const {
00065 if (!aObj || !box)
00066 return false;
00067
00068 if ((aObj->IsA() == TObjString::Class())) {
00069 TObjString *str(dynamic_cast<TObjString*>(aObj));
00070 if (!str)
00071 return false;
00072
00073 SStringToListBox_t()(str->String().Data(), box);
00074 }
00075
00076 return true;
00077 }
00078 };
00079
00080
00081 TMemStatViewerGUI::TMemStatViewerGUI(const TGWindow *p, UInt_t w, UInt_t h, Option_t* option):
00082 TGCompositeFrame(p, w, h),
00083 fViewer(NULL),
00084 fText(NULL),
00085 fNmbStackDeep(NULL),
00086 fNmbSortDeep(NULL)
00087 {
00088
00089
00090 SetCleanup(kDeepCleanup);
00091
00092
00093
00094
00095 TGCompositeFrame *contMain = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
00096 AddFrame(contMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00097
00098
00099 TGCompositeFrame *contLCR = new TGCompositeFrame(contMain, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
00100 contMain->AddFrame(contLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00101
00102
00103
00104 TGCompositeFrame *contLeft = new TGCompositeFrame(contLCR, 160, 200, kVerticalFrame | kFixedWidth | kFitHeight);
00105 contLCR->AddFrame(contLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
00106
00107
00108 TGVSplitter *splitLeft = new TGVSplitter(contLCR);
00109 splitLeft->SetFrame(contLeft, kTRUE);
00110 contLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
00111
00112
00113 TGCompositeFrame *contCenter = new TGCompositeFrame(contLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
00114 contLCR->AddFrame(contCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00115
00116 TGTab *tab = new TGTab(contCenter, 150, 200);
00117 contCenter->AddFrame(tab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00118 TGCompositeFrame *text = tab->AddTab("Text");
00119 TGCompositeFrame *graphics = tab->AddTab("Graphics");
00120
00121 fText = new TGTextView(text);
00122 text->AddFrame(fText, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00123
00124
00125 Initialize(option);
00126
00127
00128
00129 new TMemStatDrawDlg(graphics, fViewer);
00130
00131 MakeStampList(contLeft);
00132 MakeSelection(contLeft);
00133 MakeContSortStat(contLeft);
00134 MakeContSortStamp(contLeft);
00135 MakeContDeep(contLeft);
00136
00137 MapSubwindows();
00138 Resize(GetDefaultSize());
00139 MapWindow();
00140
00141
00142 fViewer->SetSortStat( TMemStat::kTotalAllocCount );
00143 fViewer->SetSortStamp( TMemStat::kCurrent );
00144 MakePrint();
00145 }
00146
00147
00148 TMemStatViewerGUI::~TMemStatViewerGUI()
00149 {
00150
00151
00152 Cleanup();
00153 if (fViewer)
00154 fViewer->Delete();
00155 }
00156
00157
00158 void TMemStatViewerGUI::Initialize(Option_t* option)
00159 {
00160
00161
00162 delete fViewer;
00163 fViewer = new TMemStat(option);
00164 fViewer->Report();
00165 }
00166
00167
00168 void TMemStatViewerGUI::MakeContSortStat(TGCompositeFrame *frame)
00169 {
00170
00171
00172
00173 TGVButtonGroup *sortStatGroup = new TGVButtonGroup(frame, "Statistic type");
00174 frame->AddFrame(sortStatGroup, new TGLayoutHints(kLHintsExpandX));
00175 new TGRadioButton(sortStatGroup, "Total Alloc Count", rbtnTotalAllocCount);
00176 new TGRadioButton(sortStatGroup, "Total Alloc Size", rbtnTotalAllocSize);
00177 new TGRadioButton(sortStatGroup, "Alloc Count", rbtnAllocCount);
00178 new TGRadioButton(sortStatGroup, "Alloc Size", rbtnAllocSize);
00179 sortStatGroup->SetButton(rbtnTotalAllocCount);
00180 sortStatGroup->Connect("Pressed(Int_t)", "TMemStatViewerGUI", this, "HandleButtonsSortStat(Int_t)");
00181 }
00182
00183
00184 void TMemStatViewerGUI::MakeContSortStamp(TGCompositeFrame *frame)
00185 {
00186
00187
00188
00189 TGVButtonGroup *sortStampGroup = new TGVButtonGroup(frame, "Sorting stamp");
00190 frame->AddFrame(sortStampGroup, new TGLayoutHints(kLHintsExpandX));
00191 new TGRadioButton(sortStampGroup, "Current", rbtnCurrent);
00192 new TGRadioButton(sortStampGroup, "Max Size", rbtnMaxSize);
00193 new TGRadioButton(sortStampGroup, "Max Count", rbtnMaxCount);
00194 sortStampGroup->SetButton(rbtnCurrent);
00195 sortStampGroup->Connect("Pressed(Int_t)", "TMemStatViewerGUI", this, "HandleButtonsSortStamp(Int_t)");
00196 }
00197
00198
00199 void TMemStatViewerGUI::MakeStampList(TGCompositeFrame *frame)
00200 {
00201
00202
00203 if (!fViewer)
00204 return;
00205
00206 const TObjArray *stampList = fViewer->GetStampList();
00207 if (!stampList)
00208 return;
00209
00210 TGHorizontalFrame *horz = new TGHorizontalFrame(frame);
00211 frame->AddFrame(horz, new TGLayoutHints(kLHintsExpandX, 2, 2, 10, 2));
00212
00213 TGLabel *lblName = new TGLabel(horz, "Stamp name:");
00214 horz->AddFrame(lblName,
00215 new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
00216
00217
00218 TGComboBox *stampListBox = new TGComboBox(horz, lstStamps);
00219 stampListBox->Resize(100, 20);
00220 horz->AddFrame(stampListBox, new TGLayoutHints(kLHintsExpandX));
00221 stampListBox->Connect("Selected(const char*)", "TMemStatViewerGUI", this, "HandleStampSelect(const char*)");
00222
00223
00224 TIter iter(stampList);
00225 for_each(iter.Begin(), TIter::End(),
00226 bind2nd(SFillListBox_t(), stampListBox));
00227
00228 const Int_t count(stampListBox->GetNumberOfEntries());
00229 if (count <= 0)
00230 return;
00231
00232 stampListBox->Select(count - 1);
00233
00234 TObjString *str(dynamic_cast<TObjString*>(stampList->At(stampListBox->GetSelected())));
00235 if (!str)
00236 return;
00237
00238 fViewer->SetCurrentStamp(*str);
00239 }
00240
00241
00242 void TMemStatViewerGUI::HandleStampSelect(const char* value)
00243 {
00244
00245
00246 fViewer->SetCurrentStamp(value);
00247 MakePrint();
00248 }
00249
00250
00251 void TMemStatViewerGUI::MakeContDeep(TGCompositeFrame *frame)
00252 {
00253
00254
00255 TGGroupFrame *contDeep = new TGGroupFrame(frame, "Deepnes");
00256 contDeep->SetLayoutManager(new TGMatrixLayout(contDeep, 0, 2, 5));
00257 frame->AddFrame(contDeep, new TGLayoutHints(kLHintsExpandX));
00258
00259
00260
00261 TGLabel *lblStackDeep = new TGLabel(contDeep, "Stack Deep:");
00262 contDeep->AddFrame(lblStackDeep, 0);
00263
00264 fNmbStackDeep = new TGNumberEntry(contDeep, fViewer->GetStackDeep(), 1, -1, TGNumberFormat::kNESInteger,
00265 TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
00266 contDeep->AddFrame(fNmbStackDeep, 0);
00267 fNmbStackDeep->Connect("ValueSet(Long_t)", "TMemStatViewerGUI", this, "HandleDeep(Long_t)");
00268 fNmbStackDeep->Resize(60, 20);
00269
00270
00271
00272 TGLabel *lSortDeep = new TGLabel(contDeep, "Sort Deep:");
00273 contDeep->AddFrame(lSortDeep, 0);
00274
00275 fNmbSortDeep = new TGNumberEntry(contDeep, fViewer->GetSortDeep(), 1, -1, TGNumberFormat::kNESInteger,
00276 TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
00277 contDeep->AddFrame(fNmbSortDeep, 0);
00278 fNmbSortDeep->Connect("ValueSet(Long_t)", "TMemStatViewerGUI", this, "HandleDeep(Long_t)");
00279 fNmbSortDeep->Resize(60, 20);
00280 }
00281
00282
00283 void TMemStatViewerGUI::HandleButtonsSortStat(Int_t id)
00284 {
00285
00286 TMemStat::StatType val;
00287 HandleRButtons(id, rbtnTotalAllocCount, &val);
00288 fViewer->SetSortStat(val);
00289 MakePrint();
00290 }
00291
00292
00293 void TMemStatViewerGUI::HandleButtonsSortStamp(Int_t id)
00294 {
00295
00296 TMemStat::StampType val;
00297 HandleRButtons(id, rbtnCurrent, &val);
00298 fViewer->SetSortStamp(val);
00299 MakePrint();
00300 }
00301
00302
00303 void TMemStatViewerGUI::HandleDeep(Long_t )
00304 {
00305
00306
00307 fViewer->SetStackDeep( fNmbStackDeep->GetIntNumber() );
00308 fViewer->SetSortDeep( fNmbSortDeep->GetIntNumber() );
00309 MakePrint();
00310 }
00311
00312
00313 void TMemStatViewerGUI::ShowGUI()
00314 {
00315
00316
00317 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 950, 600);
00318 frmMain->SetWindowName("TMemStat analysis console");
00319 frmMain->SetCleanup(kDeepCleanup);
00320
00321 TMemStatViewerGUI* calibViewer1 = new TMemStatViewerGUI(frmMain, 950, 600, "read");
00322 frmMain->AddFrame(calibViewer1, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00323
00324
00325
00326 frmMain->MapSubwindows();
00327 frmMain->Resize();
00328 frmMain->MapWindow();
00329 }
00330
00331
00332 void TMemStatViewerGUI::MakePrint()
00333 {
00334
00335 fViewer->MakeReport( fCurLib.c_str(), fCurFunc.c_str(), 0, "/tmp/memstatprint.txt");
00336 fText->LoadFile("/tmp/memstatprint.txt");
00337 }
00338
00339
00340 void TMemStatViewerGUI::MakeSelection(TGCompositeFrame *frame)
00341 {
00342
00343 if (!fViewer)
00344 return;
00345
00346 TGGroupFrame *grp = new TGGroupFrame(frame, "Selections");
00347 frame->AddFrame(grp, new TGLayoutHints(kLHintsExpandX));
00348
00349
00350
00351 TGLabel *lblFun = new TGLabel(grp, "Function");
00352 grp->AddFrame(lblFun, new TGLayoutHints(kLHintsExpandX ));
00353
00354 TGComboBox *lboxFunctions = new TGComboBox(grp);
00355 lboxFunctions->Resize(100, 20);
00356 grp->AddFrame(lboxFunctions, new TGLayoutHints(kLHintsExpandX ));
00357 lboxFunctions->Connect("Selected(const char*)", "TMemStatViewerGUI", this, "HandleFuncSelect(const char*)");
00358
00359
00360 lboxFunctions->AddEntry("*", 0);
00361
00362 TMemStat::Selection_t container;
00363 fViewer->GetFillSelection( &container, TMemStat::kFunction );
00364 for_each(container.begin(), container.end(),
00365 bind2nd(SStringToListBox_t(), lboxFunctions));
00366 lboxFunctions->Select(0);
00367
00368
00369
00370 TGLabel *lblLib = new TGLabel(grp, "Libraries");
00371 grp->AddFrame(lblLib, new TGLayoutHints(kLHintsExpandX));
00372
00373 TGComboBox *lboxLibraries = new TGComboBox(grp);
00374 lboxLibraries->Resize(100, 20);
00375 grp->AddFrame(lboxLibraries, new TGLayoutHints(kLHintsExpandX ));
00376 lboxLibraries->Connect("Selected(const char*)", "TMemStatViewerGUI", this, "HandleLibSelect(const char*)");
00377
00378
00379 lboxLibraries->AddEntry("*", 0);
00380
00381 container.clear();
00382 fViewer->GetFillSelection( &container, TMemStat::kLibrary );
00383 for_each(container.begin(), container.end(),
00384 bind2nd(SStringToListBox_t(), lboxLibraries));
00385 lboxLibraries->Select(0);
00386 }
00387
00388
00389 void TMemStatViewerGUI::HandleFuncSelect(const char* _val)
00390 {
00391
00392 fCurFunc = _val;
00393
00394 if ( fCurFunc.find("*") != string::npos )
00395 fCurFunc.clear();
00396
00397 MakePrint();
00398 }
00399
00400
00401 void TMemStatViewerGUI::HandleLibSelect(const char* _val)
00402 {
00403
00404 fCurLib = _val;
00405
00406 if ( fCurLib.find("*") != string::npos )
00407 fCurLib.clear();
00408
00409 MakePrint();
00410 }