#include <functional>
#include <stdexcept>
#include <algorithm>
#include "TGTextView.h"
#include "TGLabel.h"
#include "TGTab.h"
#include "TGButton.h"
#include "TGNumberEntry.h"
#include "TGSplitter.h"
#include "TGButtonGroup.h"
#include "TGComboBox.h"
#include "TObjArray.h"
#include "TMemStat.h"
#include "TMemStatViewerGUI.h"
#include "TMemStatResource.h"
#include "TMemStatDrawDlg.h"
ClassImp(TMemStatViewerGUI)
using namespace std;
struct SStringToListBox_t : public binary_function<string, TGComboBox*, bool> {
bool operator()(string str, TGComboBox* box) const {
if (!box)
return false;
box->AddEntry(str.c_str(), box->GetNumberOfEntries());
return true;
}
};
struct SFillListBox_t : public binary_function<TObject*, TGComboBox*, bool> {
bool operator()(TObject *aObj, TGComboBox* box) const {
if (!aObj || !box)
return false;
if ((aObj->IsA() == TObjString::Class())) {
TObjString *str(dynamic_cast<TObjString*>(aObj));
if (!str)
return false;
SStringToListBox_t()(str->String().Data(), box);
}
return true;
}
};
TMemStatViewerGUI::TMemStatViewerGUI(const TGWindow *p, UInt_t w, UInt_t h, Option_t* option):
TGCompositeFrame(p, w, h),
fViewer(NULL),
fText(NULL),
fNmbStackDeep(NULL),
fNmbSortDeep(NULL)
{
SetCleanup(kDeepCleanup);
TGCompositeFrame *contMain = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
AddFrame(contMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
TGCompositeFrame *contLCR = new TGCompositeFrame(contMain, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
contMain->AddFrame(contLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
TGCompositeFrame *contLeft = new TGCompositeFrame(contLCR, 160, 200, kVerticalFrame | kFixedWidth | kFitHeight);
contLCR->AddFrame(contLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
TGVSplitter *splitLeft = new TGVSplitter(contLCR);
splitLeft->SetFrame(contLeft, kTRUE);
contLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
TGCompositeFrame *contCenter = new TGCompositeFrame(contLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
contLCR->AddFrame(contCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
TGTab *tab = new TGTab(contCenter, 150, 200);
contCenter->AddFrame(tab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
TGCompositeFrame *text = tab->AddTab("Text");
TGCompositeFrame *graphics = tab->AddTab("Graphics");
fText = new TGTextView(text);
text->AddFrame(fText, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
Initialize(option);
new TMemStatDrawDlg(graphics, fViewer);
MakeStampList(contLeft);
MakeSelection(contLeft);
MakeContSortStat(contLeft);
MakeContSortStamp(contLeft);
MakeContDeep(contLeft);
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
fViewer->SetSortStat( TMemStat::kTotalAllocCount );
fViewer->SetSortStamp( TMemStat::kCurrent );
MakePrint();
}
TMemStatViewerGUI::~TMemStatViewerGUI()
{
Cleanup();
if (fViewer)
fViewer->Delete();
}
void TMemStatViewerGUI::Initialize(Option_t* option)
{
delete fViewer;
fViewer = new TMemStat(option);
fViewer->Report();
}
void TMemStatViewerGUI::MakeContSortStat(TGCompositeFrame *frame)
{
TGVButtonGroup *sortStatGroup = new TGVButtonGroup(frame, "Statistic type");
frame->AddFrame(sortStatGroup, new TGLayoutHints(kLHintsExpandX));
new TGRadioButton(sortStatGroup, "Total Alloc Count", rbtnTotalAllocCount);
new TGRadioButton(sortStatGroup, "Total Alloc Size", rbtnTotalAllocSize);
new TGRadioButton(sortStatGroup, "Alloc Count", rbtnAllocCount);
new TGRadioButton(sortStatGroup, "Alloc Size", rbtnAllocSize);
sortStatGroup->SetButton(rbtnTotalAllocCount);
sortStatGroup->Connect("Pressed(Int_t)", "TMemStatViewerGUI", this, "HandleButtonsSortStat(Int_t)");
}
void TMemStatViewerGUI::MakeContSortStamp(TGCompositeFrame *frame)
{
TGVButtonGroup *sortStampGroup = new TGVButtonGroup(frame, "Sorting stamp");
frame->AddFrame(sortStampGroup, new TGLayoutHints(kLHintsExpandX));
new TGRadioButton(sortStampGroup, "Current", rbtnCurrent);
new TGRadioButton(sortStampGroup, "Max Size", rbtnMaxSize);
new TGRadioButton(sortStampGroup, "Max Count", rbtnMaxCount);
sortStampGroup->SetButton(rbtnCurrent);
sortStampGroup->Connect("Pressed(Int_t)", "TMemStatViewerGUI", this, "HandleButtonsSortStamp(Int_t)");
}
void TMemStatViewerGUI::MakeStampList(TGCompositeFrame *frame)
{
if (!fViewer)
return;
const TObjArray *stampList = fViewer->GetStampList();
if (!stampList)
return;
TGHorizontalFrame *horz = new TGHorizontalFrame(frame);
frame->AddFrame(horz, new TGLayoutHints(kLHintsExpandX, 2, 2, 10, 2));
TGLabel *lblName = new TGLabel(horz, "Stamp name:");
horz->AddFrame(lblName,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
TGComboBox *stampListBox = new TGComboBox(horz, lstStamps);
stampListBox->Resize(100, 20);
horz->AddFrame(stampListBox, new TGLayoutHints(kLHintsExpandX));
stampListBox->Connect("Selected(const char*)", "TMemStatViewerGUI", this, "HandleStampSelect(const char*)");
TIter iter(stampList);
for_each(iter.Begin(), TIter::End(),
bind2nd(SFillListBox_t(), stampListBox));
const Int_t count(stampListBox->GetNumberOfEntries());
if (count <= 0)
return;
stampListBox->Select(count - 1);
TObjString *str(dynamic_cast<TObjString*>(stampList->At(stampListBox->GetSelected())));
if (!str)
return;
fViewer->SetCurrentStamp(*str);
}
void TMemStatViewerGUI::HandleStampSelect(const char* value)
{
fViewer->SetCurrentStamp(value);
MakePrint();
}
void TMemStatViewerGUI::MakeContDeep(TGCompositeFrame *frame)
{
TGGroupFrame *contDeep = new TGGroupFrame(frame, "Deepnes");
contDeep->SetLayoutManager(new TGMatrixLayout(contDeep, 0, 2, 5));
frame->AddFrame(contDeep, new TGLayoutHints(kLHintsExpandX));
TGLabel *lblStackDeep = new TGLabel(contDeep, "Stack Deep:");
contDeep->AddFrame(lblStackDeep, 0);
fNmbStackDeep = new TGNumberEntry(contDeep, fViewer->GetStackDeep(), 1, -1, TGNumberFormat::kNESInteger,
TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
contDeep->AddFrame(fNmbStackDeep, 0);
fNmbStackDeep->Connect("ValueSet(Long_t)", "TMemStatViewerGUI", this, "HandleDeep(Long_t)");
fNmbStackDeep->Resize(60, 20);
TGLabel *lSortDeep = new TGLabel(contDeep, "Sort Deep:");
contDeep->AddFrame(lSortDeep, 0);
fNmbSortDeep = new TGNumberEntry(contDeep, fViewer->GetSortDeep(), 1, -1, TGNumberFormat::kNESInteger,
TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
contDeep->AddFrame(fNmbSortDeep, 0);
fNmbSortDeep->Connect("ValueSet(Long_t)", "TMemStatViewerGUI", this, "HandleDeep(Long_t)");
fNmbSortDeep->Resize(60, 20);
}
void TMemStatViewerGUI::HandleButtonsSortStat(Int_t id)
{
TMemStat::StatType val;
HandleRButtons(id, rbtnTotalAllocCount, &val);
fViewer->SetSortStat(val);
MakePrint();
}
void TMemStatViewerGUI::HandleButtonsSortStamp(Int_t id)
{
TMemStat::StampType val;
HandleRButtons(id, rbtnCurrent, &val);
fViewer->SetSortStamp(val);
MakePrint();
}
void TMemStatViewerGUI::HandleDeep(Long_t )
{
fViewer->SetStackDeep( fNmbStackDeep->GetIntNumber() );
fViewer->SetSortDeep( fNmbSortDeep->GetIntNumber() );
MakePrint();
}
void TMemStatViewerGUI::ShowGUI()
{
TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 950, 600);
frmMain->SetWindowName("TMemStat analysis console");
frmMain->SetCleanup(kDeepCleanup);
TMemStatViewerGUI* calibViewer1 = new TMemStatViewerGUI(frmMain, 950, 600, "read");
frmMain->AddFrame(calibViewer1, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
frmMain->MapSubwindows();
frmMain->Resize();
frmMain->MapWindow();
}
void TMemStatViewerGUI::MakePrint()
{
fViewer->MakeReport( fCurLib.c_str(), fCurFunc.c_str(), 0, "/tmp/memstatprint.txt");
fText->LoadFile("/tmp/memstatprint.txt");
}
void TMemStatViewerGUI::MakeSelection(TGCompositeFrame *frame)
{
if (!fViewer)
return;
TGGroupFrame *grp = new TGGroupFrame(frame, "Selections");
frame->AddFrame(grp, new TGLayoutHints(kLHintsExpandX));
TGLabel *lblFun = new TGLabel(grp, "Function");
grp->AddFrame(lblFun, new TGLayoutHints(kLHintsExpandX ));
TGComboBox *lboxFunctions = new TGComboBox(grp);
lboxFunctions->Resize(100, 20);
grp->AddFrame(lboxFunctions, new TGLayoutHints(kLHintsExpandX ));
lboxFunctions->Connect("Selected(const char*)", "TMemStatViewerGUI", this, "HandleFuncSelect(const char*)");
lboxFunctions->AddEntry("*", 0);
TMemStat::Selection_t container;
fViewer->GetFillSelection( &container, TMemStat::kFunction );
for_each(container.begin(), container.end(),
bind2nd(SStringToListBox_t(), lboxFunctions));
lboxFunctions->Select(0);
TGLabel *lblLib = new TGLabel(grp, "Libraries");
grp->AddFrame(lblLib, new TGLayoutHints(kLHintsExpandX));
TGComboBox *lboxLibraries = new TGComboBox(grp);
lboxLibraries->Resize(100, 20);
grp->AddFrame(lboxLibraries, new TGLayoutHints(kLHintsExpandX ));
lboxLibraries->Connect("Selected(const char*)", "TMemStatViewerGUI", this, "HandleLibSelect(const char*)");
lboxLibraries->AddEntry("*", 0);
container.clear();
fViewer->GetFillSelection( &container, TMemStat::kLibrary );
for_each(container.begin(), container.end(),
bind2nd(SStringToListBox_t(), lboxLibraries));
lboxLibraries->Select(0);
}
void TMemStatViewerGUI::HandleFuncSelect(const char* _val)
{
fCurFunc = _val;
if ( fCurFunc.find("*") != string::npos )
fCurFunc.clear();
MakePrint();
}
void TMemStatViewerGUI::HandleLibSelect(const char* _val)
{
fCurLib = _val;
if ( fCurLib.find("*") != string::npos )
fCurLib.clear();
MakePrint();
}
Last change: Fri Jul 4 14:51:21 2008
Last generated: 2008-07-04 14:51
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.