|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <HbToolBar> |
|
19 #include <HbAction> |
|
20 #include <HbDataForm> |
|
21 #include <HbDataFormModel> |
|
22 #include <HbProgressDialog> |
|
23 #include <HbMessageBox> |
|
24 #include <HbLabel> |
|
25 |
|
26 #include "memspyheapdumpsview.h" |
|
27 #include "enginewrapper.h" |
|
28 |
|
29 const QStringList MODE_ITEMS = QStringList() << |
|
30 MemSpyHeapDumpsView::tr("Kernel") << |
|
31 MemSpyHeapDumpsView::tr("User") << |
|
32 MemSpyHeapDumpsView::tr("Both"); |
|
33 |
|
34 MemSpyHeapDumpsView::MemSpyHeapDumpsView(EngineWrapper &engine, ViewManager &viewManager) : |
|
35 MemSpyView(engine, viewManager), |
|
36 mModel(0), |
|
37 mModeItem(0), |
|
38 mFilterItem(0), |
|
39 mDwoProgressDialog(0) |
|
40 { |
|
41 } |
|
42 |
|
43 MemSpyHeapDumpsView::~MemSpyHeapDumpsView() |
|
44 { |
|
45 delete mDwoProgressDialog; |
|
46 } |
|
47 |
|
48 void MemSpyHeapDumpsView::initialize(const QVariantMap& params) |
|
49 { |
|
50 setTitle(tr("Heap Dumps")); |
|
51 |
|
52 MemSpyView::initialize(params); |
|
53 } |
|
54 |
|
55 HbToolBar* MemSpyHeapDumpsView::createToolBar() |
|
56 { |
|
57 HbToolBar* toolBar = new HbToolBar(); |
|
58 toolBar->addAction(tr("Dump Now"), this, SLOT(dump())); |
|
59 return toolBar; |
|
60 } |
|
61 |
|
62 HbWidget* MemSpyHeapDumpsView::createCentralWidget() |
|
63 { |
|
64 mModel = new HbDataFormModel(this); |
|
65 |
|
66 //TODO: uncomment after kernel heap dumps are implemented |
|
67 // mModeItem = mModel->appendDataFormItem( |
|
68 // HbDataFormModelItem::ComboBoxItem, tr("Heap Dump")); |
|
69 // mModeItem->setContentWidgetData("items", MODE_ITEMS); |
|
70 // mModeItem->setContentWidgetData("currentIndex", mEngine.settings().heapDumpsMode()); |
|
71 // modeChanged(mEngine.settings().heapDumpsMode()); |
|
72 |
|
73 //TODO: remove after kernel heap dumps are implemented |
|
74 createFilterItem(); |
|
75 |
|
76 HbDataForm* form = new HbDataForm(this); |
|
77 form->setModel(mModel); |
|
78 |
|
79 //TODO: uncomment after kernel heap dumps are implemented |
|
80 // form->addConnection(mModeItem, SIGNAL(currentIndexChanged(int)), this, SLOT(modeChanged(int))); |
|
81 |
|
82 return form; |
|
83 } |
|
84 |
|
85 void MemSpyHeapDumpsView::modeChanged(int mode) |
|
86 { |
|
87 if (mode == HeapDumpsModeKernel && mFilterItem) |
|
88 removeFilterItem(); |
|
89 else if (mode != HeapDumpsModeKernel && !mFilterItem) |
|
90 createFilterItem(); |
|
91 } |
|
92 |
|
93 void MemSpyHeapDumpsView::createFilterItem() |
|
94 { |
|
95 mFilterItem = mModel->appendDataFormItem( |
|
96 HbDataFormModelItem::TextItem, tr("Filter")); |
|
97 } |
|
98 |
|
99 void MemSpyHeapDumpsView::removeFilterItem() |
|
100 { |
|
101 mModel->removeItem(mFilterItem); |
|
102 mFilterItem = 0; |
|
103 } |
|
104 |
|
105 void MemSpyHeapDumpsView::dump() |
|
106 { |
|
107 mEngine.updateOutputSettings(); |
|
108 |
|
109 HeapDumpsMode mode = HeapDumpsModeUser; |
|
110 //TODO: uncomment after kernel heap dumps are implemented |
|
111 //static_cast<HeapDumpsMode>(mModeItem->contentWidgetData("currentIndex").toInt()); |
|
112 |
|
113 // save settings |
|
114 //TODO: uncomment after kernel heap dumps are implemented |
|
115 //mEngine.settings().setHeapDumpsMode(mode); |
|
116 |
|
117 if (mode == HeapDumpsModeKernel || mode == HeapDumpsModeBoth) { |
|
118 // dump kernel heap |
|
119 mDwoProgressDialog = new HbProgressDialog(HbProgressDialog::WaitDialog); |
|
120 mDwoProgressDialog->setText(tr("Please wait...")); |
|
121 mDwoProgressDialog->show(); |
|
122 |
|
123 MemSpyKernelHeapDumpTracker* tracker = mEngine.createKernelHeapDumpTracker(); |
|
124 connect(tracker, SIGNAL(finished(int)), this, SLOT(asyncOperationFinished(int))); |
|
125 tracker->start(); |
|
126 } |
|
127 |
|
128 if (mode == HeapDumpsModeUser || mode == HeapDumpsModeBoth) { |
|
129 // dump user heap |
|
130 |
|
131 QString filter = mFilterItem->contentWidgetData("text").toString(); |
|
132 if (!filter.isEmpty()) { |
|
133 |
|
134 int errorCode = mEngine.outputThreadHeapData(filter); |
|
135 if (errorCode == KErrNotFound) { |
|
136 HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation); |
|
137 messageBox->setText(tr("No thread matches your filter")); |
|
138 HbLabel *header = new HbLabel(tr("No such thread"), messageBox); |
|
139 messageBox->setHeadingWidget(header); |
|
140 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
141 messageBox->setTimeout(HbPopup::StandardTimeout); |
|
142 messageBox->open(); |
|
143 } |
|
144 |
|
145 |
|
146 } else { |
|
147 mDwoProgressDialog = new HbProgressDialog(HbProgressDialog::ProgressDialog); |
|
148 mDwoProgressDialog->setMinimum(0); |
|
149 mDwoProgressDialog->setMaximum(100); |
|
150 mDwoProgressDialog->show(); |
|
151 |
|
152 MemSpyDwoTracker* tracker = mEngine.createDeviceWideOperation(OutputHeapData); |
|
153 connect(tracker, SIGNAL(progress(int,QString)), this, SLOT(updateDwoProgress(int,QString))); |
|
154 connect(tracker, SIGNAL(finished(int)), this, SLOT(asyncOperationFinished(int))); |
|
155 connect(mDwoProgressDialog, SIGNAL(cancelled()), tracker, SLOT(cancel())); |
|
156 tracker->start(); |
|
157 } |
|
158 } |
|
159 } |
|
160 |
|
161 void MemSpyHeapDumpsView::updateDwoProgress(int progress, const QString& processName) |
|
162 { |
|
163 mDwoProgressDialog->setText(processName); |
|
164 mDwoProgressDialog->setProgressValue(progress); |
|
165 } |
|
166 |
|
167 void MemSpyHeapDumpsView::asyncOperationFinished(int errorCode) |
|
168 { |
|
169 mDwoProgressDialog->hide(); |
|
170 delete mDwoProgressDialog; |
|
171 mDwoProgressDialog = 0; |
|
172 |
|
173 delete sender(); |
|
174 |
|
175 if (errorCode != KErrNone && errorCode != KErrCancel) { |
|
176 HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning); |
|
177 messageBox->setText(tr("An error occured during the operation. Error code: %1").arg(errorCode)); |
|
178 HbLabel *header = new HbLabel(tr("Error"), messageBox); |
|
179 messageBox->setHeadingWidget(header); |
|
180 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
181 messageBox->setTimeout(HbPopup::StandardTimeout); |
|
182 messageBox->open(); |
|
183 } |
|
184 } |