perfapps/memspyui/ui/hb/src/enginewrapper.cpp
author hgs
Fri, 17 Sep 2010 14:22:55 +0300
changeset 52 36d60d12b4af
parent 51 b048e15729d6
permissions -rw-r--r--
201037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
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 <QMessageBox>
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include "enginewrapper.h"
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
// CONSTANTS
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
const QString OUTPUT_MODE = "output/mode";
hgs
parents:
diff changeset
    27
const QString OUTPUT_PATH = "output/path";
hgs
parents:
diff changeset
    28
const QString SWMT_PERIOD = "swmt/period";
hgs
parents:
diff changeset
    29
const QString SWMT_MODE = "swmt/mode";
hgs
parents:
diff changeset
    30
const QString SWMT_CATEGORIES = "swmt/categories";
hgs
parents:
diff changeset
    31
const QString HEAP_DUMPS_MODE = "heapdumps/mode";
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
QString MemSpyProcess::exitInfo() const
hgs
parents:
diff changeset
    34
{
hgs
parents:
diff changeset
    35
    QChar exitType[] = {'K', 'T', 'P', 'R'};
hgs
parents:
diff changeset
    36
    QString result = QString("[%1]").arg(exitType[mProcess->ExitType()]);
hgs
parents:
diff changeset
    37
    
hgs
parents:
diff changeset
    38
    if (mProcess->ExitType() != EExitKill && mProcess->ExitType() != EExitPending) {
hgs
parents:
diff changeset
    39
        
hgs
parents:
diff changeset
    40
        QString exitCategory = QString((QChar*) mProcess->ExitCategory().Ptr(), mProcess->ExitCategory().Length());
hgs
parents:
diff changeset
    41
        result.append(QString(" %1-%2").arg(exitCategory).arg(mProcess->ExitReason()));
hgs
parents:
diff changeset
    42
    }
hgs
parents:
diff changeset
    43
    
hgs
parents:
diff changeset
    44
    return result;
hgs
parents:
diff changeset
    45
}
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
MemSpyDwoProgressTracker::MemSpyDwoProgressTracker(RMemSpySession &session) :
hgs
parents:
diff changeset
    49
	CActive(EPriorityStandard), mSession(session)
hgs
parents:
diff changeset
    50
{
hgs
parents:
diff changeset
    51
	CActiveScheduler::Add(this);
hgs
parents:
diff changeset
    52
}
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
MemSpyDwoProgressTracker::~MemSpyDwoProgressTracker()
hgs
parents:
diff changeset
    55
{
hgs
parents:
diff changeset
    56
	Cancel();
hgs
parents:
diff changeset
    57
}
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
void MemSpyDwoProgressTracker::start()
hgs
parents:
diff changeset
    60
{
hgs
parents:
diff changeset
    61
	mSession.NotifyDeviceWideOperationProgress(mProgress, iStatus);
hgs
parents:
diff changeset
    62
	
hgs
parents:
diff changeset
    63
	SetActive();
hgs
parents:
diff changeset
    64
}
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
void MemSpyDwoProgressTracker::cancel()
hgs
parents:
diff changeset
    67
{
hgs
parents:
diff changeset
    68
	Cancel();
hgs
parents:
diff changeset
    69
}
hgs
parents:
diff changeset
    70
hgs
parents:
diff changeset
    71
// Event handler method.
hgs
parents:
diff changeset
    72
 
hgs
parents:
diff changeset
    73
void MemSpyDwoProgressTracker::RunL()
hgs
parents:
diff changeset
    74
    {
hgs
parents:
diff changeset
    75
 
hgs
parents:
diff changeset
    76
    // If an error occurred handle it in RunError().
hgs
parents:
diff changeset
    77
    User::LeaveIfError(iStatus.Int());
hgs
parents:
diff changeset
    78
 
hgs
parents:
diff changeset
    79
    // Resubmit the request immediately
hgs
parents:
diff changeset
    80
    
hgs
parents:
diff changeset
    81
    mSession.NotifyDeviceWideOperationProgress(mProgress, iStatus);
hgs
parents:
diff changeset
    82
 
hgs
parents:
diff changeset
    83
    SetActive();
hgs
parents:
diff changeset
    84
 
hgs
parents:
diff changeset
    85
    emit progress(mProgress.Progress(), QString((QChar*) mProgress.Description().Ptr(), mProgress.Description().Length()));
hgs
parents:
diff changeset
    86
    }
hgs
parents:
diff changeset
    87
 
hgs
parents:
diff changeset
    88
void MemSpyDwoProgressTracker::DoCancel()
hgs
parents:
diff changeset
    89
{ 
hgs
parents:
diff changeset
    90
	// this is not yet implemented, as it is not required in current use cases
hgs
parents:
diff changeset
    91
}
hgs
parents:
diff changeset
    92
 
hgs
parents:
diff changeset
    93
TInt MemSpyDwoProgressTracker::RunError(TInt aError)
hgs
parents:
diff changeset
    94
{ 
hgs
parents:
diff changeset
    95
	// KErrNotReady and KErrCancel errors are OK, they just notify 
hgs
parents:
diff changeset
    96
	// us about the outstanding notification request that won't be 
hgs
parents:
diff changeset
    97
	// processed.
hgs
parents:
diff changeset
    98
	Q_UNUSED(aError);
hgs
parents:
diff changeset
    99
	
hgs
parents:
diff changeset
   100
    return KErrNone;
hgs
parents:
diff changeset
   101
}
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
MemSpyDwoTracker::MemSpyDwoTracker(RMemSpySession &session, DeviceWideOperation operation) :
hgs
parents:
diff changeset
   104
	CActive(EPriorityStandard), 
hgs
parents:
diff changeset
   105
	mSession(session),
hgs
parents:
diff changeset
   106
	mProgressTracker(new MemSpyDwoProgressTracker(session)),
hgs
parents:
diff changeset
   107
	mOperation(operation)
hgs
parents:
diff changeset
   108
{
hgs
parents:
diff changeset
   109
	CActiveScheduler::Add(this);
hgs
parents:
diff changeset
   110
	connect(mProgressTracker, SIGNAL(progress(int,QString)), this, SIGNAL(progress(int,QString)));
hgs
parents:
diff changeset
   111
}
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
MemSpyDwoTracker::~MemSpyDwoTracker()
hgs
parents:
diff changeset
   114
{
hgs
parents:
diff changeset
   115
	Cancel();
hgs
parents:
diff changeset
   116
	
hgs
parents:
diff changeset
   117
	delete mProgressTracker;
hgs
parents:
diff changeset
   118
}
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
void MemSpyDwoTracker::start()
hgs
parents:
diff changeset
   121
{
hgs
parents:
diff changeset
   122
	void (RMemSpySession::*functions[])(TRequestStatus&) = { 
hgs
parents:
diff changeset
   123
			&RMemSpySession::OutputPhoneInfo,
hgs
parents:
diff changeset
   124
			&RMemSpySession::OutputDetailedPhoneInfo,
hgs
parents:
diff changeset
   125
			&RMemSpySession::OutputHeapInfo,
hgs
parents:
diff changeset
   126
			&RMemSpySession::OutputCompactHeapInfo,
hgs
parents:
diff changeset
   127
			&RMemSpySession::OutputHeapCellListing,
hgs
parents:
diff changeset
   128
			&RMemSpySession::OutputHeapData,
hgs
parents:
diff changeset
   129
			&RMemSpySession::OutputStackInfo,
hgs
parents:
diff changeset
   130
			&RMemSpySession::OutputCompactStackInfo,
hgs
parents:
diff changeset
   131
			&RMemSpySession::OutputUserStackData,
hgs
parents:
diff changeset
   132
			&RMemSpySession::OutputKernelStackData };
hgs
parents:
diff changeset
   133
	
hgs
parents:
diff changeset
   134
	(mSession.*functions[mOperation])(iStatus);
hgs
parents:
diff changeset
   135
	
hgs
parents:
diff changeset
   136
	mProgressTracker->start();
hgs
parents:
diff changeset
   137
	
hgs
parents:
diff changeset
   138
	SetActive();
hgs
parents:
diff changeset
   139
}
hgs
parents:
diff changeset
   140
hgs
parents:
diff changeset
   141
void MemSpyDwoTracker::cancel()
hgs
parents:
diff changeset
   142
{
hgs
parents:
diff changeset
   143
	Cancel();
hgs
parents:
diff changeset
   144
}
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
// Event handler method.
hgs
parents:
diff changeset
   147
 
hgs
parents:
diff changeset
   148
void MemSpyDwoTracker::RunL()
hgs
parents:
diff changeset
   149
    {
hgs
parents:
diff changeset
   150
 
hgs
parents:
diff changeset
   151
    // If an error occurred handle it in RunError().
hgs
parents:
diff changeset
   152
    User::LeaveIfError(iStatus.Int());
hgs
parents:
diff changeset
   153
 
hgs
parents:
diff changeset
   154
    // Operation has finished successfully 
hgs
parents:
diff changeset
   155
    emit finished(0);
hgs
parents:
diff changeset
   156
    }
hgs
parents:
diff changeset
   157
 
hgs
parents:
diff changeset
   158
void MemSpyDwoTracker::DoCancel()
hgs
parents:
diff changeset
   159
{
hgs
parents:
diff changeset
   160
	// Cancel progress tracker
hgs
parents:
diff changeset
   161
	mProgressTracker->cancel();
hgs
parents:
diff changeset
   162
	
hgs
parents:
diff changeset
   163
	mSession.CancelDeviceWideOperationL();
hgs
parents:
diff changeset
   164
}
hgs
parents:
diff changeset
   165
 
hgs
parents:
diff changeset
   166
TInt MemSpyDwoTracker::RunError(TInt aError)
hgs
parents:
diff changeset
   167
{ 
hgs
parents:
diff changeset
   168
	// Emit the finished signal to notify user 
hgs
parents:
diff changeset
   169
	// operation was canceled
hgs
parents:
diff changeset
   170
	emit finished(aError);
hgs
parents:
diff changeset
   171
	
hgs
parents:
diff changeset
   172
    return KErrNone;
hgs
parents:
diff changeset
   173
}
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
MemSpyAsyncTracker::MemSpyAsyncTracker(RMemSpySession& session, void (RMemSpySession::*function)(TRequestStatus&)) :
hgs
parents:
diff changeset
   176
	CActive(EPriorityStandard), 
hgs
parents:
diff changeset
   177
	mFunction(function),
hgs
parents:
diff changeset
   178
	mSession(session)
hgs
parents:
diff changeset
   179
{
hgs
parents:
diff changeset
   180
	CActiveScheduler::Add(this);
hgs
parents:
diff changeset
   181
}
hgs
parents:
diff changeset
   182
hgs
parents:
diff changeset
   183
void MemSpyAsyncTracker::RunL()
hgs
parents:
diff changeset
   184
{ 
hgs
parents:
diff changeset
   185
    // If an error occurred handle it in RunError().
hgs
parents:
diff changeset
   186
    User::LeaveIfError(iStatus.Int());
hgs
parents:
diff changeset
   187
 
hgs
parents:
diff changeset
   188
    // Operation has finished successfully 
hgs
parents:
diff changeset
   189
    emit finished(0);
hgs
parents:
diff changeset
   190
}
hgs
parents:
diff changeset
   191
hgs
parents:
diff changeset
   192
void MemSpyAsyncTracker::DoCancel()
hgs
parents:
diff changeset
   193
{
hgs
parents:
diff changeset
   194
	// nothing to do here
hgs
parents:
diff changeset
   195
}
hgs
parents:
diff changeset
   196
hgs
parents:
diff changeset
   197
TInt MemSpyAsyncTracker::RunError(TInt aError)
hgs
parents:
diff changeset
   198
{ 
hgs
parents:
diff changeset
   199
	// Emit the finished signal to notify user 
hgs
parents:
diff changeset
   200
	// that operation was canceled
hgs
parents:
diff changeset
   201
	emit finished(aError);
hgs
parents:
diff changeset
   202
	
hgs
parents:
diff changeset
   203
    return KErrNone;
hgs
parents:
diff changeset
   204
}
hgs
parents:
diff changeset
   205
hgs
parents:
diff changeset
   206
void MemSpyAsyncTracker::start()
hgs
parents:
diff changeset
   207
{
hgs
parents:
diff changeset
   208
	(mSession.*mFunction)(iStatus);
hgs
parents:
diff changeset
   209
	
hgs
parents:
diff changeset
   210
	SetActive();
hgs
parents:
diff changeset
   211
}
hgs
parents:
diff changeset
   212
hgs
parents:
diff changeset
   213
MemSpySettings::MemSpySettings() : 
hgs
parents:
diff changeset
   214
	QSettings("Nokia", "MemSpy") 
hgs
parents:
diff changeset
   215
{
hgs
parents:
diff changeset
   216
}
hgs
parents:
diff changeset
   217
hgs
parents:
diff changeset
   218
OutputMode MemSpySettings::outputMode() const
hgs
parents:
diff changeset
   219
{
hgs
parents:
diff changeset
   220
	return static_cast<OutputMode>(value(OUTPUT_MODE, 0).toInt());
hgs
parents:
diff changeset
   221
}
hgs
parents:
diff changeset
   222
hgs
parents:
diff changeset
   223
void MemSpySettings::setOutputMode(OutputMode mode)
hgs
parents:
diff changeset
   224
{
hgs
parents:
diff changeset
   225
	setValue(OUTPUT_MODE, mode);
hgs
parents:
diff changeset
   226
}
hgs
parents:
diff changeset
   227
	
hgs
parents:
diff changeset
   228
QString MemSpySettings::outputPath() const
hgs
parents:
diff changeset
   229
{
hgs
parents:
diff changeset
   230
	return value(OUTPUT_PATH).toString();
hgs
parents:
diff changeset
   231
}
hgs
parents:
diff changeset
   232
hgs
parents:
diff changeset
   233
void MemSpySettings::setOutputPath(const QString& path)
hgs
parents:
diff changeset
   234
{
hgs
parents:
diff changeset
   235
	setValue(OUTPUT_PATH, path);
hgs
parents:
diff changeset
   236
}
hgs
parents:
diff changeset
   237
hgs
parents:
diff changeset
   238
int MemSpySettings::swmtTimerPeriod() const
hgs
parents:
diff changeset
   239
{
hgs
parents:
diff changeset
   240
	return value(SWMT_PERIOD, 30).toInt();
hgs
parents:
diff changeset
   241
}
hgs
parents:
diff changeset
   242
hgs
parents:
diff changeset
   243
void MemSpySettings::setSwmtMode(SwmtMode mode)
hgs
parents:
diff changeset
   244
{
hgs
parents:
diff changeset
   245
	setValue(SWMT_MODE, mode);
hgs
parents:
diff changeset
   246
}
hgs
parents:
diff changeset
   247
hgs
parents:
diff changeset
   248
SwmtMode MemSpySettings::swmtMode() const
hgs
parents:
diff changeset
   249
{
hgs
parents:
diff changeset
   250
	return static_cast<SwmtMode>(value(SWMT_MODE, 0).toInt());
hgs
parents:
diff changeset
   251
}
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
void MemSpySettings::setSwmtTimerPeriod(int period)
hgs
parents:
diff changeset
   254
{
hgs
parents:
diff changeset
   255
	setValue(SWMT_PERIOD, period);
hgs
parents:
diff changeset
   256
}
hgs
parents:
diff changeset
   257
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
QVariantList MemSpySettings::swmtCategories() const
hgs
parents:
diff changeset
   260
{
hgs
parents:
diff changeset
   261
	return value(SWMT_CATEGORIES).toList();
hgs
parents:
diff changeset
   262
}
hgs
parents:
diff changeset
   263
hgs
parents:
diff changeset
   264
void MemSpySettings::setSwmtCategories(const QVariantList& categories)
hgs
parents:
diff changeset
   265
{
hgs
parents:
diff changeset
   266
	setValue(SWMT_CATEGORIES, categories);
hgs
parents:
diff changeset
   267
}
hgs
parents:
diff changeset
   268
hgs
parents:
diff changeset
   269
HeapDumpsMode MemSpySettings::heapDumpsMode() const
hgs
parents:
diff changeset
   270
{
hgs
parents:
diff changeset
   271
	return static_cast<HeapDumpsMode>(value(HEAP_DUMPS_MODE).toInt());
hgs
parents:
diff changeset
   272
}
hgs
parents:
diff changeset
   273
hgs
parents:
diff changeset
   274
void MemSpySettings::setHeapDumpsMode(HeapDumpsMode mode)
hgs
parents:
diff changeset
   275
{
hgs
parents:
diff changeset
   276
	setValue(HEAP_DUMPS_MODE, mode);
hgs
parents:
diff changeset
   277
}
hgs
parents:
diff changeset
   278
hgs
parents:
diff changeset
   279
hgs
parents:
diff changeset
   280
EngineWrapper::EngineWrapper() :
hgs
parents:
diff changeset
   281
	mSwmtRunning(false)
hgs
parents:
diff changeset
   282
{
hgs
parents:
diff changeset
   283
}
hgs
parents:
diff changeset
   284
hgs
parents:
diff changeset
   285
EngineWrapper::~EngineWrapper()
hgs
parents:
diff changeset
   286
{
hgs
parents:
diff changeset
   287
	mSession.Close();
hgs
parents:
diff changeset
   288
}
hgs
parents:
diff changeset
   289
hgs
parents:
diff changeset
   290
bool EngineWrapper::initialize()
hgs
parents:
diff changeset
   291
{
hgs
parents:
diff changeset
   292
	return mSession.Connect() == KErrNone;
hgs
parents:
diff changeset
   293
}
hgs
parents:
diff changeset
   294
hgs
parents:
diff changeset
   295
MemSpySettings& EngineWrapper::settings()
hgs
parents:
diff changeset
   296
{
hgs
parents:
diff changeset
   297
	return mSettings;
hgs
parents:
diff changeset
   298
}
hgs
parents:
diff changeset
   299
hgs
parents:
diff changeset
   300
const MemSpySettings& EngineWrapper::settings() const
hgs
parents:
diff changeset
   301
{
hgs
parents:
diff changeset
   302
	return mSettings;
hgs
parents:
diff changeset
   303
}
hgs
parents:
diff changeset
   304
hgs
parents:
diff changeset
   305
hgs
parents:
diff changeset
   306
hgs
parents:
diff changeset
   307
QList<MemSpyProcess*> EngineWrapper::getProcesses()
hgs
parents:
diff changeset
   308
{
hgs
parents:
diff changeset
   309
	QList<MemSpyProcess*> result;
hgs
parents:
diff changeset
   310
	
hgs
parents:
diff changeset
   311
	RArray<CMemSpyApiProcess*> proc;
hgs
parents:
diff changeset
   312
	
hgs
parents:
diff changeset
   313
	QT_TRAP_THROWING(mSession.GetProcessesL(proc));
hgs
parents:
diff changeset
   314
	
hgs
parents:
diff changeset
   315
	for (TInt i=0; i<proc.Count(); i++)
hgs
parents:
diff changeset
   316
        result.append(new MemSpyProcess(proc[i]));
hgs
parents:
diff changeset
   317
	
hgs
parents:
diff changeset
   318
	return result;
hgs
parents:
diff changeset
   319
}
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
QList<MemSpyThread*> EngineWrapper::getThreads(ProcessId processId)
hgs
parents:
diff changeset
   322
{
hgs
parents:
diff changeset
   323
	QList<MemSpyThread*> result;
hgs
parents:
diff changeset
   324
	
hgs
parents:
diff changeset
   325
	RArray<CMemSpyApiThread*> proc;
hgs
parents:
diff changeset
   326
	
hgs
parents:
diff changeset
   327
	QT_TRAP_THROWING(mSession.GetThreadsL(processId, proc));
hgs
parents:
diff changeset
   328
	
hgs
parents:
diff changeset
   329
    for (TInt i=0; i<proc.Count(); i++)
hgs
parents:
diff changeset
   330
        result.append(new MemSpyThread(proc[i]));
hgs
parents:
diff changeset
   331
	
hgs
parents:
diff changeset
   332
	return result;
hgs
parents:
diff changeset
   333
}
hgs
parents:
diff changeset
   334
hgs
parents:
diff changeset
   335
QList<MemSpyThreadInfoItem*> EngineWrapper::getThreadInfo(ThreadId threadId, ThreadInfoType type)
hgs
parents:
diff changeset
   336
{
hgs
parents:
diff changeset
   337
	QList<MemSpyThreadInfoItem*> result;
hgs
parents:
diff changeset
   338
	RArray<CMemSpyApiThreadInfoItem*> threadInfo;
hgs
parents:
diff changeset
   339
	qt_symbian_throwIfError(mSession.GetThreadInfoItems(threadInfo, threadId, 
hgs
parents:
diff changeset
   340
			static_cast<TMemSpyThreadInfoItemType>(type)));
hgs
parents:
diff changeset
   341
	
hgs
parents:
diff changeset
   342
	for (TInt i=0; i<threadInfo.Count(); i++)
hgs
parents:
diff changeset
   343
		result.append(new MemSpyThreadInfoItem(threadInfo[i]));
hgs
parents:
diff changeset
   344
	
hgs
parents:
diff changeset
   345
	return result;
hgs
parents:
diff changeset
   346
}
hgs
parents:
diff changeset
   347
hgs
parents:
diff changeset
   348
void EngineWrapper::setThreadPriority(ThreadId threadId, ThreadPriority priority)
hgs
parents:
diff changeset
   349
{
hgs
parents:
diff changeset
   350
	TRAP_IGNORE(mSession.SetThreadPriorityL(threadId, priority));
hgs
parents:
diff changeset
   351
}
hgs
parents:
diff changeset
   352
hgs
parents:
diff changeset
   353
QList<MemSpyKernelObjectType*> EngineWrapper::getKernelObjectTypes()
hgs
parents:
diff changeset
   354
{
hgs
parents:
diff changeset
   355
	QList<MemSpyKernelObjectType*> result;
hgs
parents:
diff changeset
   356
		
hgs
parents:
diff changeset
   357
	RArray<CMemSpyApiKernelObject*> types;
hgs
parents:
diff changeset
   358
	qt_symbian_throwIfError(mSession.GetKernelObjects(types));
hgs
parents:
diff changeset
   359
	
hgs
parents:
diff changeset
   360
	for(TInt i=0; i<types.Count(); i++)
hgs
parents:
diff changeset
   361
		result.append(new MemSpyKernelObjectType(types[i]));
hgs
parents:
diff changeset
   362
	
hgs
parents:
diff changeset
   363
	return result;
hgs
parents:
diff changeset
   364
}
hgs
parents:
diff changeset
   365
hgs
parents:
diff changeset
   366
QList<MemSpyKernelObject*> EngineWrapper::getKernelObjects(int type)
hgs
parents:
diff changeset
   367
{
hgs
parents:
diff changeset
   368
	QList<MemSpyKernelObject*> result;
hgs
parents:
diff changeset
   369
		
hgs
parents:
diff changeset
   370
	RArray<CMemSpyApiKernelObjectItem*> objects;
hgs
parents:
diff changeset
   371
	qt_symbian_throwIfError(mSession.GetKernelObjectItems(objects, 
hgs
parents:
diff changeset
   372
			static_cast<TMemSpyDriverContainerType>(type)));
hgs
parents:
diff changeset
   373
	
hgs
parents:
diff changeset
   374
	for (TInt i=0; i<objects.Count(); i++)
hgs
parents:
diff changeset
   375
		result.append(new MemSpyKernelObject(objects[i]));
hgs
parents:
diff changeset
   376
	
hgs
parents:
diff changeset
   377
	return result;
hgs
parents:
diff changeset
   378
}
hgs
parents:
diff changeset
   379
hgs
parents:
diff changeset
   380
QList<MemSpyServer*> EngineWrapper::getServers()
hgs
parents:
diff changeset
   381
{
hgs
parents:
diff changeset
   382
    QList<MemSpyServer*> result;
hgs
parents:
diff changeset
   383
        
hgs
parents:
diff changeset
   384
    RArray<CMemSpyApiServer*> proc;
hgs
parents:
diff changeset
   385
    
hgs
parents:
diff changeset
   386
    QT_TRAP_THROWING(mSession.GetServersL(proc));
hgs
parents:
diff changeset
   387
    
hgs
parents:
diff changeset
   388
    for (TInt i=0; i<proc.Count(); i++)
hgs
parents:
diff changeset
   389
        result.append(new MemSpyServer(proc[i]));
hgs
parents:
diff changeset
   390
    
hgs
parents:
diff changeset
   391
    return result;
hgs
parents:
diff changeset
   392
}
hgs
parents:
diff changeset
   393
hgs
parents:
diff changeset
   394
QList<MemSpyEComCategory*> EngineWrapper::getEComCategories()
hgs
parents:
diff changeset
   395
{
hgs
parents:
diff changeset
   396
    QList<MemSpyEComCategory*> result;
hgs
parents:
diff changeset
   397
        
hgs
parents:
diff changeset
   398
    RArray<CMemSpyApiEComCategory*> cat;
hgs
parents:
diff changeset
   399
    
hgs
parents:
diff changeset
   400
    QT_TRAP_THROWING(mSession.GetEComCategoriesL(cat));
hgs
parents:
diff changeset
   401
    
hgs
parents:
diff changeset
   402
    for (TInt i=0; i<cat.Count(); i++)
hgs
parents:
diff changeset
   403
        result.append(new MemSpyEComCategory(cat[i]));
hgs
parents:
diff changeset
   404
    
hgs
parents:
diff changeset
   405
    return result;
hgs
parents:
diff changeset
   406
}
hgs
parents:
diff changeset
   407
hgs
parents:
diff changeset
   408
QList<MemSpyEComInterface*> EngineWrapper::getEComInterfaces(int categoryId)
hgs
parents:
diff changeset
   409
{
hgs
parents:
diff changeset
   410
    QList<MemSpyEComInterface*> result;
hgs
parents:
diff changeset
   411
            
hgs
parents:
diff changeset
   412
    RArray<CMemSpyApiEComInterface*> interfaces;
hgs
parents:
diff changeset
   413
    
hgs
parents:
diff changeset
   414
    QT_TRAP_THROWING(mSession.GetEComInterfacesL(TUid::Uid(categoryId), interfaces));
hgs
parents:
diff changeset
   415
    
hgs
parents:
diff changeset
   416
    for (TInt i=0; i<interfaces.Count(); i++)
hgs
parents:
diff changeset
   417
        result.append(new MemSpyEComInterface(interfaces[i]));
hgs
parents:
diff changeset
   418
    
hgs
parents:
diff changeset
   419
    return result;
hgs
parents:
diff changeset
   420
}
hgs
parents:
diff changeset
   421
hgs
parents:
diff changeset
   422
QList<MemSpyEComImplementation*> EngineWrapper::getEComImplementations(int interfaceId)
hgs
parents:
diff changeset
   423
{
hgs
parents:
diff changeset
   424
    QList<MemSpyEComImplementation*> result;
hgs
parents:
diff changeset
   425
                
hgs
parents:
diff changeset
   426
    RArray<CMemSpyApiEComImplementation*> implementations;
hgs
parents:
diff changeset
   427
    
hgs
parents:
diff changeset
   428
    QT_TRAP_THROWING(mSession.GetEComImplementationsL(TUid::Uid(interfaceId), implementations));
hgs
parents:
diff changeset
   429
    
hgs
parents:
diff changeset
   430
    for (TInt i=0; i<implementations.Count(); i++)
hgs
parents:
diff changeset
   431
        result.append(new MemSpyEComImplementation(implementations[i]));
hgs
parents:
diff changeset
   432
    
hgs
parents:
diff changeset
   433
    return result;
hgs
parents:
diff changeset
   434
}
hgs
parents:
diff changeset
   435
52
hgs
parents: 51
diff changeset
   436
QList<MemSpyWindowGroup*> EngineWrapper::getWindowGroups()
hgs
parents: 51
diff changeset
   437
{
hgs
parents: 51
diff changeset
   438
    QList<MemSpyWindowGroup*> result;
hgs
parents: 51
diff changeset
   439
                    
hgs
parents: 51
diff changeset
   440
    RArray<CMemSpyApiWindowGroup*> groups;
hgs
parents: 51
diff changeset
   441
    
hgs
parents: 51
diff changeset
   442
    QT_TRAP_THROWING(mSession.GetWindowGroupsL(groups));
hgs
parents: 51
diff changeset
   443
    
hgs
parents: 51
diff changeset
   444
    for (TInt i=0; i<groups.Count(); i++)
hgs
parents: 51
diff changeset
   445
        result.append(new MemSpyWindowGroup(groups[i]));
hgs
parents: 51
diff changeset
   446
    
hgs
parents: 51
diff changeset
   447
    return result;
hgs
parents: 51
diff changeset
   448
}
hgs
parents: 51
diff changeset
   449
51
hgs
parents:
diff changeset
   450
hgs
parents:
diff changeset
   451
MemSpyDwoTracker* EngineWrapper::createDeviceWideOperation(DeviceWideOperation operation)
hgs
parents:
diff changeset
   452
{
hgs
parents:
diff changeset
   453
	return new MemSpyDwoTracker(mSession, operation);
hgs
parents:
diff changeset
   454
}
hgs
parents:
diff changeset
   455
hgs
parents:
diff changeset
   456
MemSpyKernelHeapDumpTracker* EngineWrapper::createKernelHeapDumpTracker()
hgs
parents:
diff changeset
   457
{
hgs
parents:
diff changeset
   458
	return new MemSpyKernelHeapDumpTracker(mSession);
hgs
parents:
diff changeset
   459
}
hgs
parents:
diff changeset
   460
hgs
parents:
diff changeset
   461
MemSpySwmtDumpTracker* EngineWrapper::createSwmtDumpTracker()
hgs
parents:
diff changeset
   462
{
hgs
parents:
diff changeset
   463
	return new MemSpySwmtDumpTracker(mSession);
hgs
parents:
diff changeset
   464
}
hgs
parents:
diff changeset
   465
hgs
parents:
diff changeset
   466
void EngineWrapper::setSwmtSettings(SwmtMode mode, const QVariantList& categories)
hgs
parents:
diff changeset
   467
{
hgs
parents:
diff changeset
   468
	int bits = 0;
hgs
parents:
diff changeset
   469
	bool heapDumps = false;
hgs
parents:
diff changeset
   470
	switch (mode)
hgs
parents:
diff changeset
   471
	{
hgs
parents:
diff changeset
   472
	case SwmtModeBasic:
hgs
parents:
diff changeset
   473
		bits = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap | 
52
hgs
parents: 51
diff changeset
   474
			//TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserStacks |
hgs
parents: 51
diff changeset
   475
			//TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalData |
51
hgs
parents:
diff changeset
   476
			TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory;
hgs
parents:
diff changeset
   477
		
hgs
parents:
diff changeset
   478
		break;
hgs
parents:
diff changeset
   479
		
hgs
parents:
diff changeset
   480
	case SwmtModeFull:
hgs
parents:
diff changeset
   481
		bits = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryAll;
hgs
parents:
diff changeset
   482
		heapDumps = true;
hgs
parents:
diff changeset
   483
		
hgs
parents:
diff changeset
   484
		break;
hgs
parents:
diff changeset
   485
		
hgs
parents:
diff changeset
   486
	case SwmtModeCustom:
hgs
parents:
diff changeset
   487
		bits = 0;
hgs
parents:
diff changeset
   488
		// this needs to be in sync. with swmt view categories
hgs
parents:
diff changeset
   489
		TMemSpyEngineHelperSysMemTrackerConfig::TMemSpyEngineSysMemTrackerCategories cats[] = {
hgs
parents:
diff changeset
   490
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryFileServerCache,
hgs
parents:
diff changeset
   491
            //TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryBitmapHandles,
hgs
parents:
diff changeset
   492
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap,
hgs
parents:
diff changeset
   493
            //TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHeap,
hgs
parents:
diff changeset
   494
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryLocalChunks,
hgs
parents:
diff changeset
   495
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalChunks,
hgs
parents:
diff changeset
   496
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMDrive,
hgs
parents:
diff changeset
   497
            //TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserStacks,
hgs
parents:
diff changeset
   498
            //TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalData,
hgs
parents:
diff changeset
   499
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMLoadedCode,
hgs
parents:
diff changeset
   500
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHandles,
hgs
parents:
diff changeset
   501
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryOpenFiles,
hgs
parents:
diff changeset
   502
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryDiskusage,
hgs
parents:
diff changeset
   503
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory,
hgs
parents:
diff changeset
   504
            TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryWindowGroups
hgs
parents:
diff changeset
   505
		};
hgs
parents:
diff changeset
   506
hgs
parents:
diff changeset
   507
		foreach (const QVariant& bit, categories)
hgs
parents:
diff changeset
   508
			bits |= cats[bit.toInt()];
hgs
parents:
diff changeset
   509
		
hgs
parents:
diff changeset
   510
		break;
hgs
parents:
diff changeset
   511
	}
hgs
parents:
diff changeset
   512
	
hgs
parents:
diff changeset
   513
	TRAP_IGNORE(mSession.SetSwmtCategoriesL(bits));
hgs
parents:
diff changeset
   514
	TRAP_IGNORE(mSession.SetSwmtHeapDumpsEnabledL(heapDumps));
hgs
parents:
diff changeset
   515
}
hgs
parents:
diff changeset
   516
hgs
parents:
diff changeset
   517
bool EngineWrapper::isSwmtRunning()
hgs
parents:
diff changeset
   518
{
hgs
parents:
diff changeset
   519
	return mSwmtRunning;
hgs
parents:
diff changeset
   520
}
hgs
parents:
diff changeset
   521
	
hgs
parents:
diff changeset
   522
void EngineWrapper::startSwmt(int period)
hgs
parents:
diff changeset
   523
{
hgs
parents:
diff changeset
   524
	mSwmtRunning = true;
hgs
parents:
diff changeset
   525
	updateOutputSettings();
hgs
parents:
diff changeset
   526
	TRAP_IGNORE(mSession.StartSwmtTimerL(period));
hgs
parents:
diff changeset
   527
}
hgs
parents:
diff changeset
   528
hgs
parents:
diff changeset
   529
void EngineWrapper::stopSwmt()
hgs
parents:
diff changeset
   530
{
hgs
parents:
diff changeset
   531
	mSwmtRunning = false;
hgs
parents:
diff changeset
   532
	TRAP_IGNORE(mSession.StopSwmtTimerL());
hgs
parents:
diff changeset
   533
}
hgs
parents:
diff changeset
   534
hgs
parents:
diff changeset
   535
void EngineWrapper::forceSwmtDump()
hgs
parents:
diff changeset
   536
{
hgs
parents:
diff changeset
   537
	updateOutputSettings();	
hgs
parents:
diff changeset
   538
	TRAP_IGNORE(mSession.ForceSwmtUpdateL());
hgs
parents:
diff changeset
   539
}
hgs
parents:
diff changeset
   540
hgs
parents:
diff changeset
   541
void EngineWrapper::outputKernelHeapData()
hgs
parents:
diff changeset
   542
{
hgs
parents:
diff changeset
   543
	updateOutputSettings();
hgs
parents:
diff changeset
   544
	TRAP_IGNORE(mSession.OutputKernelHeapDataL());
hgs
parents:
diff changeset
   545
}
hgs
parents:
diff changeset
   546
hgs
parents:
diff changeset
   547
int EngineWrapper::outputThreadHeapData(const QString& filter)
hgs
parents:
diff changeset
   548
{
hgs
parents:
diff changeset
   549
	TPtrC customFilterDesc(static_cast<const TUint16*>(filter.utf16()), filter.length());
hgs
parents:
diff changeset
   550
	
hgs
parents:
diff changeset
   551
	TRAPD(err, mSession.OutputThreadHeapDataL(customFilterDesc));
hgs
parents:
diff changeset
   552
	
hgs
parents:
diff changeset
   553
	return err;
hgs
parents:
diff changeset
   554
}
hgs
parents:
diff changeset
   555
hgs
parents:
diff changeset
   556
void EngineWrapper::updateOutputSettings()
hgs
parents:
diff changeset
   557
{
hgs
parents:
diff changeset
   558
	switch (mSettings.outputMode()) {
hgs
parents:
diff changeset
   559
		case OutputModeTrace:
hgs
parents:
diff changeset
   560
			TRAP_IGNORE(mSession.SwitchOutputToTraceL());
hgs
parents:
diff changeset
   561
			break;
hgs
parents:
diff changeset
   562
		
hgs
parents:
diff changeset
   563
		case OutputModeFile:
hgs
parents:
diff changeset
   564
		
hgs
parents:
diff changeset
   565
			if (mSettings.outputPath().isEmpty()) {
hgs
parents:
diff changeset
   566
				TRAP_IGNORE(mSession.SwitchOutputToFileL(KNullDesC));
hgs
parents:
diff changeset
   567
			
hgs
parents:
diff changeset
   568
			} else {
hgs
parents:
diff changeset
   569
				
hgs
parents:
diff changeset
   570
				QString root = mSettings.outputPath();
hgs
parents:
diff changeset
   571
				TPtrC rootDesc (static_cast<const TUint16*>(root.utf16()), root.length());
hgs
parents:
diff changeset
   572
			
hgs
parents:
diff changeset
   573
				TRAP_IGNORE(mSession.SwitchOutputToFileL(rootDesc));
hgs
parents:
diff changeset
   574
			}
hgs
parents:
diff changeset
   575
	
hgs
parents:
diff changeset
   576
	}
hgs
parents:
diff changeset
   577
}
hgs
parents:
diff changeset
   578
hgs
parents:
diff changeset
   579
void EngineWrapper::killProcess(ProcessId process)
hgs
parents:
diff changeset
   580
{
hgs
parents:
diff changeset
   581
    TRAP_IGNORE(mSession.EndProcessL(process, EKill));
hgs
parents:
diff changeset
   582
}
hgs
parents:
diff changeset
   583
    
hgs
parents:
diff changeset
   584
void EngineWrapper::panicProcess(ProcessId process)
hgs
parents:
diff changeset
   585
{
hgs
parents:
diff changeset
   586
    TRAP_IGNORE(mSession.EndProcessL(process, EPanic));
hgs
parents:
diff changeset
   587
}
hgs
parents:
diff changeset
   588
hgs
parents:
diff changeset
   589
void EngineWrapper::terminateProcess(ProcessId process)
hgs
parents:
diff changeset
   590
{
hgs
parents:
diff changeset
   591
    TRAP_IGNORE(mSession.EndProcessL(process, ETerminate));
hgs
parents:
diff changeset
   592
}