|
1 // memspy.cpp |
|
2 // |
|
3 // Copyright (c) 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/ioutils.h> |
|
14 #include <fshell/common.mmh> |
|
15 #include <fshell/ltkutils.h> |
|
16 #include <memspy/engine/memspyengine.h> |
|
17 #include <memspy/engine/memspyenginehelpersysmemtracker.h> |
|
18 #include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h> |
|
19 #include <memspy/engine/memspyenginehelperheap.h> |
|
20 #include <memspy/engine/memspyenginehelperchunk.h> |
|
21 #include <memspy/engine/MemSpyEngineObjectContainer.h> |
|
22 |
|
23 using namespace IoUtils; |
|
24 |
|
25 class CCmdMemspy : public CCommandBase |
|
26 { |
|
27 public: |
|
28 static CCommandBase* NewLC(); |
|
29 ~CCmdMemspy(); |
|
30 private: |
|
31 CCmdMemspy(); |
|
32 private: // From CCommandBase. |
|
33 virtual const TDesC& Name() const; |
|
34 virtual void DoRunL(); |
|
35 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
36 virtual void OptionsL(RCommandOptionList& aOptions); |
|
37 private: |
|
38 enum TCmd |
|
39 { |
|
40 ESymtDump, |
|
41 ESymtStart, |
|
42 EHeapDump, |
|
43 ECellDump, |
|
44 EChunkInfo, |
|
45 }; |
|
46 TCmd iCmd; |
|
47 HBufC* iParameter; |
|
48 |
|
49 CMemSpyEngine* iEngine; |
|
50 }; |
|
51 |
|
52 EXE_BOILER_PLATE(CCmdMemspy) |
|
53 |
|
54 CCommandBase* CCmdMemspy::NewLC() |
|
55 { |
|
56 CCmdMemspy* self = new(ELeave) CCmdMemspy(); |
|
57 CleanupStack::PushL(self); |
|
58 self->BaseConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 CCmdMemspy::~CCmdMemspy() |
|
63 { |
|
64 delete iEngine; |
|
65 delete iParameter; |
|
66 } |
|
67 |
|
68 CCmdMemspy::CCmdMemspy() |
|
69 : CCommandBase(EManualComplete) |
|
70 { |
|
71 } |
|
72 |
|
73 const TDesC& CCmdMemspy::Name() const |
|
74 { |
|
75 _LIT(KName, "memspy"); |
|
76 return KName; |
|
77 } |
|
78 |
|
79 void CCmdMemspy::ArgumentsL(RCommandArgumentList& aArguments) |
|
80 { |
|
81 aArguments.AppendEnumL((TInt&)iCmd, _L("command")); |
|
82 aArguments.AppendStringL(iParameter, _L("parameter")); |
|
83 } |
|
84 |
|
85 void CCmdMemspy::OptionsL(RCommandOptionList& /*aOptions*/) |
|
86 { |
|
87 } |
|
88 |
|
89 void CCmdMemspy::DoRunL() |
|
90 { |
|
91 TRAPL(iEngine = CMemSpyEngine::NewL(FsL()), _L("Couldn't construct CMemSpyEngine")); |
|
92 iEngine->InstallSinkL(ESinkTypeFile); |
|
93 |
|
94 //LtkUtils::BreakpointPushL(); |
|
95 |
|
96 TMemSpyEngineHelperSysMemTrackerConfig config; |
|
97 config.iEnabledCategories = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory |
|
98 | TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap |
|
99 ; |
|
100 config.iDumpData = EFalse; |
|
101 TBool complete = ETrue; |
|
102 |
|
103 if (iCmd == ESymtDump) |
|
104 { |
|
105 iEngine->HelperSysMemTracker().SetConfigL(config); |
|
106 iEngine->HelperSysMemTracker().CheckForChangesNowL(); |
|
107 } |
|
108 else if (iCmd == ESymtStart) |
|
109 { |
|
110 iEngine->HelperSysMemTracker().StartL(config); |
|
111 complete = EFalse; |
|
112 } |
|
113 else if (iCmd == EHeapDump) |
|
114 { |
|
115 CMemSpyProcess* process = NULL; |
|
116 CMemSpyThread* thread = NULL; |
|
117 LeaveIfErr(iEngine->Container().ProcessAndThreadByPartialName(iParameter ? *iParameter : KNullDesC(), process, thread), _L("Couldn't find thread")); |
|
118 |
|
119 iEngine->HelperHeap().OutputHeapDataUserL(*thread); |
|
120 } |
|
121 else if (iCmd == ECellDump) |
|
122 { |
|
123 CMemSpyProcess* process = NULL; |
|
124 CMemSpyThread* thread = NULL; |
|
125 LeaveIfErr(iEngine->Container().ProcessAndThreadByPartialName(iParameter ? *iParameter : KNullDesC(), process, thread), _L("Couldn't find thread")); |
|
126 |
|
127 iEngine->HelperHeap().OutputCellListingUserL(*thread); |
|
128 } |
|
129 else if (iCmd == EChunkInfo) |
|
130 { |
|
131 CMemSpyProcess* process = NULL; |
|
132 CMemSpyThread* thread = NULL; |
|
133 LeaveIfErr(iEngine->Container().ProcessAndThreadByPartialName(iParameter ? *iParameter : KNullDesC(), process, thread), _L("Couldn't find process")); |
|
134 iEngine->HelperChunk().OutputChunkInfoForProcessL(*process); |
|
135 } |
|
136 |
|
137 //CleanupStack::Pop(); |
|
138 |
|
139 if (complete) Complete(); |
|
140 } |