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