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