51
|
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 <memspy/engine/memspyenginehelperprocess.h>
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <e32debug.h>
|
|
22 |
|
|
23 |
// Driver includes
|
|
24 |
#include <memspy/driver/memspydriverclient.h>
|
|
25 |
|
|
26 |
// User includes
|
|
27 |
#include <memspy/engine/memspyengine.h>
|
|
28 |
#include <memspy/engine/memspyenginemidwife.h>
|
|
29 |
#include <memspy/engine/memspyengineoutputsink.h>
|
|
30 |
#include <memspy/engine/memspyengineobjectthread.h>
|
|
31 |
#include <memspy/engine/memspyengineobjectprocess.h>
|
|
32 |
#include <memspy/engine/memspyenginehelperchunk.h>
|
|
33 |
#include <memspy/engine/memspyenginehelpercodesegment.h>
|
|
34 |
#include <memspy/engine/memspyenginehelperthread.h>
|
|
35 |
#include <memspy/engine/memspyengineprocessmemorytracker.h>
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
CMemSpyEngineHelperProcess::CMemSpyEngineHelperProcess( CMemSpyEngine& aEngine )
|
|
40 |
: iEngine( aEngine )
|
|
41 |
{
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
CMemSpyEngineHelperProcess::~CMemSpyEngineHelperProcess()
|
|
46 |
{
|
|
47 |
delete iUndertaker;
|
|
48 |
iEngine.Midwife().RemoveObserver( *this );
|
|
49 |
//
|
|
50 |
iMemoryTrackers.ResetAndDestroy();
|
|
51 |
iMemoryTrackers.Close();
|
|
52 |
iMemoryTrackerAutoStartProcessList.Close();
|
|
53 |
}
|
|
54 |
|
|
55 |
|
|
56 |
void CMemSpyEngineHelperProcess::ConstructL()
|
|
57 |
{
|
|
58 |
iUndertaker = CMemSpyEngineUndertaker::NewL( iEngine.Driver() );
|
|
59 |
iUndertaker->AddObserverL( *this );
|
|
60 |
iEngine.Midwife().AddObserverL( *this );
|
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
CMemSpyEngineHelperProcess* CMemSpyEngineHelperProcess::NewL( CMemSpyEngine& aEngine )
|
|
65 |
{
|
|
66 |
CMemSpyEngineHelperProcess* self = new(ELeave) CMemSpyEngineHelperProcess( aEngine );
|
|
67 |
CleanupStack::PushL( self );
|
|
68 |
self->ConstructL();
|
|
69 |
CleanupStack::Pop( self );
|
|
70 |
return self;
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
EXPORT_C void CMemSpyEngineHelperProcess::ImpersonateL( TUint32 aSID )
|
|
75 |
{
|
|
76 |
const TInt err = iEngine.Driver().Impersonate( aSID );
|
|
77 |
User::LeaveIfError( err );
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
EXPORT_C void CMemSpyEngineHelperProcess::OutputProcessInfoL( const CMemSpyProcess& aProcess )
|
|
82 |
{
|
|
83 |
OutputProcessInfoL( aProcess, EFalse );
|
|
84 |
}
|
|
85 |
|
|
86 |
|
|
87 |
EXPORT_C void CMemSpyEngineHelperProcess::OutputProcessInfoDetailedL( const CMemSpyProcess& aProcess )
|
|
88 |
{
|
|
89 |
OutputProcessInfoL( aProcess, ETrue );
|
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
void CMemSpyEngineHelperProcess::OutputProcessInfoL( const CMemSpyProcess& aProcess, TBool aDetailed )
|
|
94 |
{
|
|
95 |
const TUint pid = aProcess.Id();
|
|
96 |
const TUint sid = aProcess.SID();
|
|
97 |
RProcess process;
|
|
98 |
User::LeaveIfError( iEngine.Driver().OpenProcess( pid, process ) );
|
|
99 |
CleanupClosePushL( process );
|
|
100 |
|
|
101 |
const TPtrC procName( aProcess.Name() );
|
|
102 |
TBuf<512> infoBuf;
|
|
103 |
//
|
|
104 |
_LIT(KProcessInfo, "SUMMARY FOR PROCESS \'%S\'");
|
|
105 |
infoBuf.Format(KProcessInfo, &procName);
|
|
106 |
iEngine.Sink().OutputSectionHeadingL( infoBuf, '=' );
|
|
107 |
|
|
108 |
_LIT(KProcessId, "Id");
|
|
109 |
iEngine.Sink().OutputItemAndValueL( KProcessId, pid );
|
|
110 |
|
|
111 |
_LIT(KProcessPri, "Priority");
|
|
112 |
TBuf<30> priority;
|
|
113 |
const TProcessPriority procPriValue = process.Priority();
|
|
114 |
CMemSpyProcess::AppendPriority( priority, procPriValue );
|
|
115 |
iEngine.Sink().OutputItemAndValueL( KProcessPri, priority );
|
|
116 |
|
|
117 |
_LIT(KProcessSID, "SID");
|
|
118 |
iEngine.Sink().OutputItemAndValueL( KProcessSID, sid, ETrue );
|
|
119 |
CleanupStack::PopAndDestroy( &process );
|
|
120 |
|
|
121 |
if ( aDetailed )
|
|
122 |
{
|
|
123 |
iEngine.ProcessSuspendLC( pid );
|
|
124 |
iEngine.HelperChunk().OutputChunkInfoForProcessL( aProcess );
|
|
125 |
iEngine.HelperCodeSegment().OutputCodeSegmentsL( pid, infoBuf, KNullDesC, '-', ETrue );
|
|
126 |
CleanupStack::PopAndDestroy(); // ProcessSuspendLC
|
|
127 |
}
|
|
128 |
|
|
129 |
const TInt count = aProcess.Count();
|
|
130 |
for(TInt i=0; i<count; i++)
|
|
131 |
{
|
|
132 |
const CMemSpyThread& thread = aProcess.At( i );
|
|
133 |
iEngine.HelperThread().OutputThreadInfoL( thread, aDetailed );
|
|
134 |
}
|
|
135 |
}
|
|
136 |
|
|
137 |
|
|
138 |
EXPORT_C void CMemSpyEngineHelperProcess::SetMemoryTrackingAutoStartProcessListL( const RArray<TUid>& aProcessUids )
|
|
139 |
{
|
|
140 |
iEngine.Driver().ProcessInspectionAutoStartItemsReset();
|
|
141 |
//
|
|
142 |
const TInt count = aProcessUids.Count();
|
|
143 |
iMemoryTrackerAutoStartProcessList.Reset();
|
|
144 |
//
|
|
145 |
for( TInt i=0; i<count; i++ )
|
|
146 |
{
|
|
147 |
const TUid uid = aProcessUids[ i ];
|
|
148 |
#ifdef _DEBUG
|
|
149 |
RDebug::Printf( "CMemSpyEngineHelperProcess::SetMemoryTrackingAutoStartProcessListL() - uid[%2d] => 0x%08x", i, uid.iUid );
|
|
150 |
#endif
|
|
151 |
//
|
|
152 |
User::LeaveIfError( iMemoryTrackerAutoStartProcessList.Append( uid ) );
|
|
153 |
//
|
|
154 |
const TInt driverErr = iEngine.Driver().ProcessInspectionAutoStartItemsAdd( uid.iUid );
|
|
155 |
#ifdef _DEBUG
|
|
156 |
RDebug::Printf( "CMemSpyEngineHelperProcess::SetMemoryTrackingAutoStartProcessListL() - driver err: %d", driverErr );
|
|
157 |
#endif
|
|
158 |
User::LeaveIfError( driverErr );
|
|
159 |
}
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
CMemSpyEngineProcessMemoryTracker* CMemSpyEngineHelperProcess::TrackerOrNull( const TProcessId& aId )
|
|
164 |
{
|
|
165 |
CMemSpyEngineProcessMemoryTracker* ret = NULL;
|
|
166 |
//
|
|
167 |
const TInt count = iMemoryTrackers.Count();
|
|
168 |
for( TInt i=0; i<count; i++ )
|
|
169 |
{
|
|
170 |
CMemSpyEngineProcessMemoryTracker* tracker = iMemoryTrackers[ i ];
|
|
171 |
//
|
|
172 |
if ( tracker->ProcessId() == aId )
|
|
173 |
{
|
|
174 |
ret = tracker;
|
|
175 |
break;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
//
|
|
179 |
return ret;
|
|
180 |
}
|
|
181 |
|
|
182 |
|
|
183 |
CMemSpyEngineProcessMemoryTracker& CMemSpyEngineHelperProcess::TrackerL( const TProcessId& aId )
|
|
184 |
{
|
|
185 |
CMemSpyEngineProcessMemoryTracker* tracker = TrackerOrNull( aId );
|
|
186 |
//
|
|
187 |
if ( tracker == NULL )
|
|
188 |
{
|
|
189 |
// Make a new entry
|
|
190 |
tracker = CMemSpyEngineProcessMemoryTracker::NewLC( iEngine, aId );
|
|
191 |
User::LeaveIfError( iMemoryTrackers.Append( tracker ) );
|
|
192 |
CleanupStack::Pop( tracker );
|
|
193 |
}
|
|
194 |
//
|
|
195 |
return *tracker;
|
|
196 |
}
|
|
197 |
|
|
198 |
|
|
199 |
CMemSpyEngineProcessMemoryTracker& CMemSpyEngineHelperProcess::TrackerL( const CMemSpyProcess& aProcess )
|
|
200 |
{
|
|
201 |
return TrackerL( aProcess.Id() );
|
|
202 |
}
|
|
203 |
|
|
204 |
|
|
205 |
void CMemSpyEngineHelperProcess::ThreadIsBornL( const TThreadId& aId, const RThread& aThread )
|
|
206 |
{
|
|
207 |
#ifdef _DEBUG
|
|
208 |
RDebug::Printf( "CMemSpyEngineHelperProcess::ThreadIsBornL() - aId: 0x%08x, aThread handle: 0x%08x", (TUint) aId, aThread.Handle() );
|
|
209 |
#else
|
|
210 |
(void) aId;
|
|
211 |
(void) aThread;
|
|
212 |
#endif
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
void CMemSpyEngineHelperProcess::ProcessIsBornL( const TProcessId& aId, const RProcess& aProcess )
|
|
217 |
{
|
|
218 |
#ifdef _DEBUG
|
|
219 |
RDebug::Printf( "CMemSpyEngineHelperProcess::ProcessIsBornL() - aId: 0x%08x, aProcess handle: 0x%08x", (TUint) aId, aProcess.Handle() );
|
|
220 |
#else
|
|
221 |
(void) aId;
|
|
222 |
(void) aProcess;
|
|
223 |
#endif
|
|
224 |
|
|
225 |
if ( aProcess.Handle() != KNullHandle )
|
|
226 |
{
|
|
227 |
const TBool isAutoStart = IsAutoStartupProcess( aProcess.SecureId() );
|
|
228 |
//
|
|
229 |
if ( isAutoStart )
|
|
230 |
{
|
|
231 |
CMemSpyEngineProcessMemoryTracker& tracker = TrackerL( aId );
|
|
232 |
tracker.StartL();
|
|
233 |
}
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
|
|
238 |
void CMemSpyEngineHelperProcess::ThreadIsDeadL( const TThreadId& aId, const RThread& aThread )
|
|
239 |
{
|
|
240 |
#ifdef _DEBUG
|
|
241 |
RDebug::Printf( "CMemSpyEngineHelperProcess::ThreadIsDeadL() - aId: 0x%08x, aThread handle: 0x%08x", (TUint) aId, aThread.Handle() );
|
|
242 |
#else
|
|
243 |
(void) aId;
|
|
244 |
(void) aThread;
|
|
245 |
#endif
|
|
246 |
}
|
|
247 |
|
|
248 |
|
|
249 |
void CMemSpyEngineHelperProcess::ProcessIsDeadL( const TProcessId& aId, const RProcess& aProcess )
|
|
250 |
{
|
|
251 |
#ifdef _DEBUG
|
|
252 |
RDebug::Printf( "CMemSpyEngineHelperProcess::ProcessIsDeadL() - aId: 0x%08x, aProcess handle: 0x%08x", (TUint) aId, aProcess.Handle() );
|
|
253 |
#else
|
|
254 |
(void) aProcess;
|
|
255 |
#endif
|
|
256 |
|
|
257 |
CMemSpyEngineProcessMemoryTracker* tracker = TrackerOrNull( aId );
|
|
258 |
if ( tracker )
|
|
259 |
{
|
|
260 |
#ifdef _DEBUG
|
|
261 |
RDebug::Printf( "CMemSpyEngineHelperProcess::ProcessIsDeadL() - tracker for this process should take care of cleanup by itself..." );
|
|
262 |
#endif
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
|
|
267 |
TBool CMemSpyEngineHelperProcess::IsAutoStartupProcess( TUid aUid ) const
|
|
268 |
{
|
|
269 |
TBool match = EFalse;
|
|
270 |
//
|
|
271 |
const TInt count = iMemoryTrackerAutoStartProcessList.Count();
|
|
272 |
for( TInt i=0; i<count; i++ )
|
|
273 |
{
|
|
274 |
const TUid uid = iMemoryTrackerAutoStartProcessList[ i ];
|
|
275 |
if ( uid == aUid )
|
|
276 |
{
|
|
277 |
match = ETrue;
|
|
278 |
break;
|
|
279 |
}
|
|
280 |
}
|
|
281 |
//
|
|
282 |
#ifdef _DEBUG
|
|
283 |
RDebug::Printf( "CMemSpyEngineHelperProcess::IsAutoStartupProcess() - aUid: 0x%08x, ret: %d", aUid.iUid, match );
|
|
284 |
#endif
|
|
285 |
return match;
|
|
286 |
}
|
|
287 |
|
|
288 |
|
|
289 |
|