00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <sstream>
00014 #include <algorithm>
00015
00016 #include "TGLabel.h"
00017 #include "TGComboBox.h"
00018 #include "TGNumberEntry.h"
00019 #include "TGButton.h"
00020 #include "TCanvas.h"
00021 #include "TRootEmbeddedCanvas.h"
00022
00023 #include "TMemStat.h"
00024 #include "TMemStatDrawDlg.h"
00025 #include "TMemStatResource.h"
00026
00027 using namespace std;
00028
00029
00030 struct SFill_t : public binary_function<string, TGComboBox*, bool>
00031 {
00032 bool operator()(const string &val, TGComboBox* box) const
00033 {
00034 if (!box)
00035 return false;
00036
00037 box->AddEntry(val.c_str(), box->GetNumberOfEntries());
00038 return true;
00039 }
00040 };
00041
00042
00043 TMemStatDrawDlg::TMemStatDrawDlg(TGCompositeFrame *parent, TMemStat *MemStat):
00044 fMemStat(MemStat),
00045 fboxOrder(NULL),
00046 fboxSortStat(NULL),
00047 fboxSortStamp(NULL),
00048 fNmbStackDeep(NULL),
00049 fNmbSortDeep(NULL),
00050 fNmbMaxLength(NULL),
00051 fEc(NULL)
00052 {
00053
00054 PlaceCtrls(parent);
00055 }
00056
00057
00058 TMemStatDrawDlg::~TMemStatDrawDlg()
00059 {
00060
00061 }
00062
00063
00064 void TMemStatDrawDlg::PlaceCtrls(TGCompositeFrame *frame)
00065 {
00066
00067
00068 TGCompositeFrame *cont = new TGCompositeFrame(frame, 800, 400, kHorizontalFrame | kFitWidth | kFitHeight);
00069 frame->AddFrame(cont, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY | kLHintsExpandX, 2, 2, 2, 2));
00070
00071 TGCompositeFrame *contR = new TGCompositeFrame(cont, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
00072 cont->AddFrame(contR, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 2, 2, 2, 2));
00073
00074 StringVector_t values;
00075
00076 values.push_back("increasing");
00077 values.push_back("decreasing");
00078 PlaceLBoxCtrl(contR, &fboxOrder, "Order: ", values, resCBoxOrder);
00079
00080 values.clear();
00081 values.push_back("TotalAllocCount");
00082 values.push_back("TotalAlocSize");
00083 values.push_back("AllocCount");
00084 values.push_back("AllocSize");
00085 PlaceLBoxCtrl(contR, &fboxSortStat, "Sort stat: ", values, resCBoxSortStat);
00086
00087 values.clear();
00088 values.push_back("Current");
00089 values.push_back("MaxSize");
00090 values.push_back("MaxCount");
00091 PlaceLBoxCtrl(contR, &fboxSortStamp, "Sort stamp: ", values, resCBoxSortStamp);
00092
00093 PlaceDeepCtrl(contR);
00094
00095
00096 TGTextButton *btnDraw = new TGTextButton(contR);
00097 btnDraw->Connect("Clicked()", "TMemStatDrawDlg", this, "HandleDrawMemStat()");
00098 btnDraw->SetText("Draw");
00099 contR->AddFrame(btnDraw,
00100 new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 10, 10, 10, 10));
00101
00102
00103 PlaceEmbeddedCanvas(cont);
00104 }
00105
00106
00107 void TMemStatDrawDlg::PlaceLBoxCtrl(TGCompositeFrame *frame, TGComboBox **box,
00108 const string &Label, const StringVector_t &Vealues, Int_t resource)
00109 {
00110
00111
00112 TGHorizontalFrame *horz = new TGHorizontalFrame(frame);
00113 frame->AddFrame(horz, new TGLayoutHints(kLHintsExpandX));
00114
00115 TGLabel *lbl = new TGLabel(horz, Label.c_str());
00116 horz->AddFrame(lbl,
00117 new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
00118
00119
00120 *box = new TGComboBox( horz, resource );
00121 (*box)->Resize(120, 20);
00122 horz->AddFrame((*box), new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00123
00124
00125 for_each(Vealues.begin(), Vealues.end(), bind2nd(SFill_t(), (*box)));
00126
00127 (*box)->Select(0);
00128 }
00129
00130
00131 void TMemStatDrawDlg::PlaceDeepCtrl(TGCompositeFrame *frame)
00132 {
00133
00134
00135
00136 TGGroupFrame *contDeep = new TGGroupFrame(frame, "Deepnes", kVerticalFrame | kFitWidth | kFitHeight);
00137 frame->AddFrame(contDeep, new TGLayoutHints(kLHintsExpandX));
00138
00139
00140 TGHorizontalFrame *horz0 = new TGHorizontalFrame(contDeep);
00141 contDeep->AddFrame(horz0, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00142
00143
00144 TGLabel *lblStackDeep = new TGLabel(horz0, "Stack deep:");
00145 horz0->AddFrame(lblStackDeep, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00146
00147 fNmbStackDeep = new TGNumberEntry(horz0, fMemStat->GetStackDeep(), 1, resNmbStackDeep, TGNumberFormat::kNESInteger,
00148 TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
00149 horz0->AddFrame(fNmbStackDeep, new TGLayoutHints( kLHintsRight, 2, 2, 2, 2));
00150 fNmbStackDeep->Resize(100, 20);
00151
00152
00153 TGHorizontalFrame *horz1 = new TGHorizontalFrame(contDeep);
00154 contDeep->AddFrame(horz1, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00155
00156 TGLabel *lSortDeep = new TGLabel(horz1, "Sort deep:");
00157 horz1->AddFrame(lSortDeep, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00158
00159 fNmbSortDeep = new TGNumberEntry(horz1, fMemStat->GetSortDeep(), 1, resNmbSortDeep, TGNumberFormat::kNESInteger,
00160 TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
00161 horz1->AddFrame(fNmbSortDeep, new TGLayoutHints( kLHintsRight, 2, 2, 2, 2));
00162 fNmbSortDeep->Resize(100, 20);
00163
00164
00165 TGHorizontalFrame *horz2 = new TGHorizontalFrame(contDeep);
00166 contDeep->AddFrame(horz2, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00167
00168 TGLabel *lbl = new TGLabel(horz2, "Max length:");
00169 horz2->AddFrame(lbl, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00170
00171 fNmbMaxLength = new TGNumberEntry(horz2, fMemStat->GetMaxStringLength(), 1, resNmbMaxLength, TGNumberFormat::kNESInteger,
00172 TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 500);
00173 horz2->AddFrame(fNmbMaxLength, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00174 fNmbMaxLength->Resize(100, 20);
00175 }
00176
00177
00178 void TMemStatDrawDlg::ReDraw()
00179 {
00180
00181
00182 if (!fMemStat)
00183 return;
00184
00185
00186 ostringstream ss;
00187
00188 if (fboxOrder)
00189 ss << "order " << fboxOrder->GetSelected();
00190
00191 if (fboxSortStat)
00192 ss << " sortstat " << fboxSortStat->GetSelected();
00193
00194 if (fboxSortStamp)
00195 ss << " sortstamp " << fboxSortStamp->GetSelected();
00196
00197 if (fNmbStackDeep)
00198 ss << " sortdeep " << fNmbStackDeep->GetIntNumber();
00199
00200 if (fNmbSortDeep)
00201 ss << " stackdeep " << fNmbSortDeep->GetIntNumber();
00202
00203 if (fNmbMaxLength)
00204 ss << " maxlength " << fNmbMaxLength->GetIntNumber();
00205
00206 fMemStat->Draw(ss.str().c_str());
00207 fEc->GetCanvas()->Modified();
00208 fEc->GetCanvas()->Update();
00209 }
00210
00211
00212 void TMemStatDrawDlg::HandleDrawMemStat()
00213 {
00214
00215 ReDraw();
00216 }
00217
00218
00219 void TMemStatDrawDlg::PlaceEmbeddedCanvas(TGCompositeFrame *frame)
00220 {
00221
00222 if (fEc)
00223 return;
00224
00225 fEc = new TRootEmbeddedCanvas("ec", frame, 200, 200);
00226 frame->AddFrame(fEc, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00227 fEc->GetCanvas()->SetBorderMode(0);
00228 }