memspyui/ui/hb/inc/enginewrapper.h
branchRCL_3
changeset 21 b3cee849fa46
equal deleted inserted replaced
20:48060abbbeaf 21:b3cee849fa46
       
     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 #ifndef ENGINEWRAPPER_H_
       
    19 #define ENGINEWRAPPER_H_
       
    20 
       
    21 #include <QObject>
       
    22 #include <QVariantList>
       
    23 #include <QSettings>
       
    24 
       
    25 #include <memspysession.h>
       
    26 
       
    27 typedef quint64 ProcessId;
       
    28 typedef quint64 ThreadId;
       
    29 
       
    30 enum ThreadPriority
       
    31 {
       
    32 	ThreadPriorityNull=(-30),
       
    33 	ThreadPriorityMuchLess=(-20),
       
    34 	ThreadPriorityLess=(-10),
       
    35 	ThreadPriorityNormal=0,
       
    36 	ThreadPriorityMore=10,
       
    37 	ThreadPriorityMuchMore=20,
       
    38 	ThreadPriorityRealTime=30,
       
    39 	ThreadPriorityAbsoluteVeryLow=100,
       
    40 	ThreadPriorityAbsoluteLowNormal=150,
       
    41 	ThreadPriorityAbsoluteLow=200,
       
    42 	ThreadPriorityAbsoluteBackgroundNormal=250,
       
    43 	ThreadPriorityAbsoluteBackground=300,
       
    44 	ThreadPriorityAbsoluteForegroundNormal=350,
       
    45 	ThreadPriorityAbsoluteForeground=400,
       
    46 	ThreadPriorityAbsoluteHighNormal=450,
       
    47 	ThreadPriorityAbsoluteHigh=500,
       
    48 	ThreadPriorityAbsoluteRealTime1=810,
       
    49 	ThreadPriorityAbsoluteRealTime2=820,
       
    50 	ThreadPriorityAbsoluteRealTime3=830,
       
    51 	ThreadPriorityAbsoluteRealTime4=840,
       
    52 	ThreadPriorityAbsoluteRealTime5=850,
       
    53 	ThreadPriorityAbsoluteRealTime6=860,
       
    54 	ThreadPriorityAbsoluteRealTime7=870, 
       
    55 	ThreadPriorityAbsoluteRealTime8=880
       
    56 };
       
    57 
       
    58 enum KernelObjectType
       
    59 {
       
    60 	KernelObjectTypeUnknown = -1,
       
    61 	KernelObjectTypeThread = 0,
       
    62 	KernelObjectTypeProcess,
       
    63 	KernelObjectTypeChunk,
       
    64 	KernelObjectTypeLibrary,
       
    65 	KernelObjectTypeSemaphore,
       
    66 	KernelObjectTypeMutex,
       
    67 	KernelObjectTypeTimer,
       
    68 	KernelObjectTypeServer,
       
    69 	KernelObjectTypeSession,
       
    70 	KernelObjectTypeLogicalDevice,
       
    71 	KernelObjectTypePhysicalDevice,
       
    72 	KernelObjectTypeLogicalChannel,
       
    73 	KernelObjectTypeChangeNotifier,
       
    74 	KernelObjectTypeUndertaker,
       
    75 	KernelObjectTypeMsgQueue,
       
    76 	KernelObjectTypePropertyRef,
       
    77 	KernelObjectTypeCondVar
       
    78 };
       
    79 
       
    80 enum ThreadInfoType
       
    81 {
       
    82 	ThreadInfoTypeGeneral = EMemSpyThreadInfoItemTypeGeneralInfo,
       
    83 	ThreadInfoTypeHeap = EMemSpyThreadInfoItemTypeHeap,
       
    84 	ThreadInfoTypeStack = EMemSpyThreadInfoItemTypeStack,
       
    85 	ThreadInfoTypeChunk = EMemSpyThreadInfoItemTypeChunk,
       
    86 	ThreadInfoTypeCodeSeg = EMemSpyThreadInfoItemTypeCodeSeg,
       
    87 	ThreadInfoTypeOpenFiles = EMemSpyThreadInfoItemTypeOpenFiles,
       
    88 	ThreadInfoTypeActiveObjects = EMemSpyThreadInfoItemTypeActiveObject,
       
    89 	ThreadInfoTypeOwnedThreadHandles = EMemSpyThreadInfoItemTypeOwnedThreadHandles,
       
    90 	ThreadInfoTypeOwnedProcessHandles = EMemSpyThreadInfoItemTypeOwnedProcessHandles,
       
    91 	ThreadInfoTypeServer = EMemSpyThreadInfoItemTypeServer,
       
    92 	ThreadInfoTypeSession = EMemSpyThreadInfoItemTypeSession,
       
    93 	ThreadInfoTypeSemaphore = EMemSpyThreadInfoItemTypeSemaphore,
       
    94 	ThreadInfoTypeOtherThreads = EMemSpyThreadInfoItemTypeOtherThreads,
       
    95 	ThreadInfoTypeOtherProcesses = EMemSpyThreadInfoItemTypeOtherProcesses,
       
    96 	ThreadInfoTypeMutex = EMemSpyThreadInfoItemTypeMutex,
       
    97 	ThreadInfoTypeTimer = EMemSpyThreadInfoItemTypeTimer,
       
    98 	ThreadInfoTypeChannel = EMemSpyThreadInfoItemTypeLogicalChannel,
       
    99 	ThreadInfoTypeChangeNotifier = EMemSpyThreadInfoItemTypeChangeNotifier,
       
   100 	ThreadInfoTypeUndertaker = EMemSpyThreadInfoItemTypeUndertaker,
       
   101 	ThreadInfoTypeMessageQueue = EMemSpyThreadInfoItemTypeMessageQueue,
       
   102 	ThreadInfoTypeConditionalVariable = EMemSpyThreadInfoItemTypeConditionalVariable,
       
   103 	ThreadInfoTypeLDD = EMemSpyThreadInfoItemTypeLDD,
       
   104 	ThreadInfoTypePDD = EMemSpyThreadInfoItemTypePDD,
       
   105 };
       
   106 
       
   107 enum DeviceWideOperation
       
   108 {
       
   109 	OutputPhoneInfo = 0,
       
   110 	    
       
   111 	OutputDetailedPhoneInfo,
       
   112 	    
       
   113 	OutputHeapInfo,
       
   114 	    
       
   115 	OutputCompactHeapInfo,
       
   116 	    
       
   117 	OutputHeapCellListing,
       
   118 	    
       
   119 	OutputHeapData,
       
   120 	    
       
   121 	OutputStackInfo,
       
   122 	    
       
   123 	OutputCompactStackInfo,
       
   124 	    
       
   125 	OutputUserStackData,
       
   126 	    
       
   127 	OutputKernelStackData
       
   128 };
       
   129 
       
   130 enum SwmtMode
       
   131 {
       
   132 	SwmtModeBasic = 0,
       
   133 	SwmtModeFull,
       
   134 	SwmtModeCustom
       
   135 };
       
   136 
       
   137 enum HeapDumpsMode
       
   138 {
       
   139 	HeapDumpsModeKernel = 0,
       
   140 	HeapDumpsModeUser,
       
   141 	HeapDumpsModeBoth
       
   142 };
       
   143 
       
   144 enum OutputMode
       
   145 {
       
   146 	OutputModeTrace = 0,
       
   147 	OutputModeFile
       
   148 };
       
   149 
       
   150 class MemSpyProcess
       
   151 {
       
   152 public:
       
   153 	MemSpyProcess(CMemSpyApiProcess* process)
       
   154 		: mProcess(process)
       
   155 	{}
       
   156 	
       
   157 	virtual  ~MemSpyProcess() { delete mProcess; }
       
   158 	
       
   159 	ProcessId id() const { return mProcess->Id(); }
       
   160 	
       
   161 	QString name() const { return QString((QChar*) mProcess->Name().Ptr(), mProcess->Name().Length()); }
       
   162 	
       
   163 	QString exitInfo() const;
       
   164 	
       
   165 	int priority() const { return mProcess->Priority(); }
       
   166 	
       
   167 	int threadCount() const { return mProcess->ThreadCount(); }
       
   168 	
       
   169 	int sid() const { return mProcess->SID(); }
       
   170 	
       
   171 	int vid() const { return mProcess->VID(); }
       
   172 	
       
   173 	bool isDead() const { return mProcess->IsDead(); }
       
   174 	
       
   175 private:
       
   176 	CMemSpyApiProcess *mProcess;
       
   177 };
       
   178 
       
   179 class MemSpyThread
       
   180 {
       
   181 public:
       
   182 	MemSpyThread(CMemSpyApiThread* thread)
       
   183 		: mThread(thread)
       
   184 	{}
       
   185 	
       
   186 	virtual ~MemSpyThread() { delete mThread;	}
       
   187 	
       
   188 	ThreadId id() const { return mThread->Id(); }
       
   189 	
       
   190 	QString name() const { return QString((QChar*) mThread->Name().Ptr(), mThread->Name().Length()); }
       
   191 	
       
   192 	int priority() const { return mThread->ThreadPriority(); }
       
   193 	
       
   194 	
       
   195 private:
       
   196 	CMemSpyApiThread *mThread;
       
   197 };
       
   198 
       
   199 class MemSpyKernelObjectType
       
   200 {
       
   201 public:
       
   202 	MemSpyKernelObjectType(CMemSpyApiKernelObject* type)
       
   203 		: mType(type)
       
   204 	{}
       
   205 	
       
   206 	virtual ~MemSpyKernelObjectType() { delete mType; }
       
   207 	
       
   208 	int id() const { return mType->Type(); }
       
   209 	
       
   210 	QString name() const { return QString((QChar*) mType->Name().Ptr(), mType->Name().Length()); }
       
   211 	
       
   212 	int count() const { return mType->Count(); }
       
   213 	
       
   214 	qint64 size() const { return mType->Size(); }
       
   215 	
       
   216 private:
       
   217 	CMemSpyApiKernelObject *mType;
       
   218 };
       
   219 
       
   220 class MemSpyKernelObject
       
   221 {
       
   222 public:
       
   223 	MemSpyKernelObject(CMemSpyApiKernelObjectItem* object)
       
   224 		: mObject(object)
       
   225 	{}
       
   226 	
       
   227 	virtual ~MemSpyKernelObject() { delete mObject; }
       
   228 	
       
   229 	int type() const { return mObject->Type(); }
       
   230 	
       
   231 	QString name() const { return QString::fromLatin1((char*)mObject->Name().Ptr(), mObject->Name().Length()); }
       
   232 	
       
   233 	QString nameDetail() const { return QString::fromLatin1((char*)mObject->NameDetail().Ptr(), mObject->NameDetail().Length()); }
       
   234 	
       
   235 	int accessCount() const { return mObject->AccessCount(); }
       
   236 	
       
   237 	int uniqueId() const { return mObject->UniqueID(); }
       
   238 	
       
   239 	unsigned int protection() const { return mObject->Protection(); }
       
   240 	
       
   241 	unsigned int addressOfKernelOwner() const { return reinterpret_cast<unsigned int>(mObject->AddressOfKernelOwner()); }
       
   242 	
       
   243 	unsigned int kernelAddress() const { return reinterpret_cast<unsigned int>(mObject->Handle()); }
       
   244 	
       
   245 	unsigned int addressOfOwningProcess() const { return reinterpret_cast<unsigned int>(mObject->AddressOfOwningProcess()); }
       
   246 	
       
   247 	int id() const { return mObject->Id(); }
       
   248 	
       
   249 	int priority() const { return mObject->Priority(); }
       
   250 	
       
   251 	QString nameOfOwner() const { return QString::fromLatin1((char*)mObject->NameOfOwner().Ptr(), mObject->NameOfOwner().Length()); }
       
   252 	
       
   253 	unsigned int creatorId() const { return mObject->CreatorId(); }
       
   254 	
       
   255 	int attributes() const { return mObject->Attributes(); }
       
   256 	
       
   257 	unsigned int addressOfDataBssStackChunk() const { return reinterpret_cast<unsigned int>(mObject->AddressOfDataBssStackChunk()); }
       
   258 	
       
   259 	unsigned int securityZone() const { return mObject->SecurityZone(); }
       
   260 	
       
   261 	unsigned int size() const { return mObject->Size(); }
       
   262 	
       
   263 	unsigned int maxSize() const { return mObject->MaxSize(); }
       
   264 	
       
   265 	unsigned int bottom() const { return mObject->Bottom(); }
       
   266 	
       
   267 	unsigned int top() const { return mObject->Top(); }
       
   268 	
       
   269 	unsigned int startPos() const { return mObject->StartPos(); }
       
   270 	
       
   271 	unsigned int controllingOwner() const { return mObject->ControllingOwner(); }
       
   272 	
       
   273 	unsigned int restrictions() const { return mObject->Restrictions(); }
       
   274 	
       
   275 	unsigned int mapAttr() const { return mObject->Restrictions(); }
       
   276 	
       
   277 	unsigned int chunkType() const { return mObject->ChunkType(); }
       
   278 	
       
   279 	int mapCount() const { return mObject->MapCount(); }
       
   280 	
       
   281 	unsigned int state() const { return mObject->State(); }
       
   282 	
       
   283 	unsigned int addressOfCodeSeg() const { return reinterpret_cast<unsigned int>(mObject->AddressOfCodeSeg()); }
       
   284 	
       
   285 	unsigned int resetting() const { return mObject->Resetting(); }
       
   286 	
       
   287 	unsigned int order() const { return mObject->Order(); }
       
   288 	
       
   289 	QString version() const { return QString((QChar*) mObject->Version().Name().Ptr(), mObject->Version().Name().Length()); }
       
   290 	
       
   291 	unsigned int parseMask() const { return mObject->ParseMask(); }
       
   292 	
       
   293 	unsigned int unitsMask() const { return mObject->UnitsMask(); }
       
   294 	
       
   295 	unsigned int changes() const { return mObject->Changes(); }
       
   296 	
       
   297 	int count() const { return mObject->Count(); }
       
   298 	
       
   299 	int waitCount() const { return mObject->WaitCount(); }
       
   300 
       
   301 	int sessionType() const { return mObject->SessionType(); }
       
   302 
       
   303 	int timerType() const { return mObject->TimerType(); }
       
   304 	
       
   305 	int timerState() const { return mObject->TimerState(); }
       
   306 	
       
   307 	unsigned int addressOfOwningThread() const { return reinterpret_cast<unsigned int>(mObject->AddressOfOwningThread()); }
       
   308 	
       
   309 	unsigned int addressOfServer() const { return reinterpret_cast<unsigned int>(mObject->AddressOfServer()); }
       
   310 	
       
   311 	unsigned int svrSessionType() const { return mObject->SvrSessionType(); }
       
   312 	
       
   313 	int msgCount() const { return mObject->MsgCount(); }
       
   314 	
       
   315 	int msgLimit() const { return mObject->MsgLimit(); }
       
   316 	
       
   317 	unsigned int totalAccessCount() const { return mObject->TotalAccessCount(); }
       
   318 	
       
   319 	int openChannels() const { return mObject->OpenChannels(); }
       
   320 	
       
   321 private:
       
   322 	CMemSpyApiKernelObjectItem *mObject;
       
   323 };
       
   324 
       
   325 class MemSpyThreadInfoItem 
       
   326 {
       
   327 public:
       
   328 	MemSpyThreadInfoItem(CMemSpyApiThreadInfoItem *item)
       
   329 		: mItem(item)
       
   330 	{}
       
   331 	
       
   332 	virtual  ~MemSpyThreadInfoItem() { delete mItem;	}
       
   333 	
       
   334 	QString caption() const { return QString((QChar*) mItem->Caption().Ptr(), mItem->Caption().Length()); }
       
   335 	
       
   336 	QString value() const { return QString((QChar*) mItem->Value().Ptr(), mItem->Value().Length()); }
       
   337 	
       
   338 private:
       
   339 	CMemSpyApiThreadInfoItem* mItem;
       
   340 };
       
   341 
       
   342 class MemSpyDwoProgressTracker : public QObject, public CActive
       
   343 {
       
   344 	Q_OBJECT
       
   345 
       
   346 public:
       
   347 	MemSpyDwoProgressTracker(RMemSpySession &session);
       
   348 	virtual ~MemSpyDwoProgressTracker();
       
   349 	
       
   350 public slots:
       
   351 
       
   352 	void start();
       
   353 
       
   354 	void cancel();
       
   355 	
       
   356 protected: // from CActive
       
   357 	
       
   358 	virtual void RunL();
       
   359 	 
       
   360 	virtual void DoCancel();
       
   361 	 
       
   362 	virtual TInt RunError(TInt aError);
       
   363 	
       
   364 signals:
       
   365 	void progress(int progress, const QString& processName);
       
   366 	
       
   367 private:
       
   368 	TMemSpyDeviceWideOperationProgress mProgress;
       
   369 	RMemSpySession mSession;
       
   370 };
       
   371 
       
   372 class MemSpyDwoTracker : public QObject, public CActive
       
   373 {
       
   374 	Q_OBJECT
       
   375 
       
   376 public:
       
   377 	MemSpyDwoTracker(RMemSpySession &session, DeviceWideOperation operation);
       
   378 	virtual ~MemSpyDwoTracker();
       
   379 	
       
   380 public slots:
       
   381 
       
   382 	void start();
       
   383 	
       
   384 	void cancel();
       
   385 	
       
   386 protected: // from CActive
       
   387 	
       
   388 	virtual void RunL();
       
   389 	 
       
   390 	virtual void DoCancel();
       
   391 	 
       
   392 	virtual TInt RunError(TInt aError);
       
   393 	
       
   394 signals:
       
   395 	void finished(int errorCode);
       
   396 	void progress(int progress, const QString& processName);
       
   397 	
       
   398 private:
       
   399 	RMemSpySession mSession;
       
   400 	MemSpyDwoProgressTracker *mProgressTracker;
       
   401 	DeviceWideOperation mOperation;
       
   402 };
       
   403 
       
   404 class MemSpyAsyncTracker : public QObject, public CActive
       
   405 {
       
   406 	Q_OBJECT
       
   407 	
       
   408 public:
       
   409 	
       
   410 	MemSpyAsyncTracker(RMemSpySession& session, void (RMemSpySession::*function)(TRequestStatus&));
       
   411 	
       
   412 	void start();
       
   413 	
       
   414 	virtual void RunL();
       
   415 	
       
   416 	virtual void DoCancel();
       
   417 	
       
   418 	virtual TInt RunError(TInt aError);
       
   419 	
       
   420 signals:
       
   421 	
       
   422 	void finished(int errorCode);
       
   423 	
       
   424 private:
       
   425 	void (RMemSpySession::*mFunction)(TRequestStatus&);
       
   426 	RMemSpySession& mSession;
       
   427 };
       
   428 
       
   429 class MemSpySwmtDumpTracker : public MemSpyAsyncTracker
       
   430 {
       
   431 public:
       
   432 	MemSpySwmtDumpTracker(RMemSpySession& session) : 
       
   433 		MemSpyAsyncTracker(session, &RMemSpySession::ForceSwmtUpdate)
       
   434 	{}
       
   435 };
       
   436 
       
   437 class MemSpyKernelHeapDumpTracker : public MemSpyAsyncTracker
       
   438 {
       
   439 public:
       
   440 	MemSpyKernelHeapDumpTracker(RMemSpySession& session) : 
       
   441 		MemSpyAsyncTracker(session, &RMemSpySession::OutputKernelHeapData)
       
   442 	{}
       
   443 };
       
   444 
       
   445 class MemSpySettings : private QSettings
       
   446 {
       
   447 public:
       
   448 	
       
   449 	MemSpySettings();
       
   450 	
       
   451 	OutputMode outputMode() const;
       
   452 	void setOutputMode(OutputMode mode);
       
   453 	
       
   454 	QString outputPath() const;
       
   455 	void setOutputPath(const QString& path);
       
   456 		
       
   457 	int swmtTimerPeriod() const;
       
   458 	void setSwmtTimerPeriod(int period);
       
   459 	
       
   460 	SwmtMode swmtMode() const;
       
   461 	void setSwmtMode(SwmtMode mode);
       
   462 	
       
   463 	QVariantList swmtCategories() const;
       
   464 	void setSwmtCategories(const QVariantList& categories);
       
   465 	
       
   466 	HeapDumpsMode heapDumpsMode() const;
       
   467 	void setHeapDumpsMode(HeapDumpsMode mode);
       
   468 };
       
   469 
       
   470 class EngineWrapper : public QObject
       
   471 {
       
   472 	Q_OBJECT
       
   473 	
       
   474 public:
       
   475 	EngineWrapper();
       
   476 	
       
   477 	virtual ~EngineWrapper();
       
   478 	
       
   479 	bool initialize();
       
   480 	
       
   481 	MemSpySettings& settings();
       
   482 	
       
   483 	const MemSpySettings& settings() const;
       
   484 	
       
   485 	
       
   486 	
       
   487 	QList<MemSpyProcess*> getProcesses();
       
   488 	
       
   489 	QList<MemSpyThread*> getThreads(ProcessId processId);
       
   490 	
       
   491 	QList<MemSpyThreadInfoItem*> getThreadInfo(ThreadId threadId, ThreadInfoType type);
       
   492 	
       
   493 	void setThreadPriority(ThreadId threadId, ThreadPriority priority);
       
   494 	
       
   495 	QList<MemSpyKernelObjectType*> getKernelObjectTypes();
       
   496 	
       
   497 	QList<MemSpyKernelObject*> getKernelObjects(int type);
       
   498 	
       
   499 	MemSpyDwoTracker* createDeviceWideOperation(DeviceWideOperation operation);
       
   500 	
       
   501 	MemSpyKernelHeapDumpTracker* createKernelHeapDumpTracker();
       
   502 	
       
   503 	MemSpySwmtDumpTracker* createSwmtDumpTracker();
       
   504 	
       
   505 	void setSwmtSettings(SwmtMode mode, const QVariantList& categories);
       
   506 	
       
   507 	bool isSwmtRunning();
       
   508 	
       
   509 	void startSwmt(int period);
       
   510 	
       
   511 	void stopSwmt();
       
   512 	
       
   513 	void forceSwmtDump();
       
   514 	
       
   515 	void outputKernelHeapData();
       
   516 	
       
   517 	int outputThreadHeapData(const QString& filter);
       
   518 	
       
   519 	void updateOutputSettings();
       
   520 	
       
   521 private:
       
   522 	RMemSpySession mSession;
       
   523 	
       
   524 	bool mSwmtRunning;
       
   525 	
       
   526 	MemSpySettings mSettings;
       
   527 };
       
   528 
       
   529 #endif /* ENGINEWRAPPER_H_ */