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 "MemSpyDriverInspectedProcess.h"
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
#include <kern_priv.h>
|
|
22 |
#include <nk_trace.h>
|
|
23 |
#include <u32hal.h>
|
|
24 |
|
|
25 |
#ifdef __MARM__
|
|
26 |
#include "kdebug.h"
|
|
27 |
#endif //__MARM__
|
|
28 |
|
|
29 |
// User includes
|
|
30 |
#include "MemSpyDriverUtils.h"
|
|
31 |
#include "MemSpyDriverDevice.h"
|
|
32 |
#include "MemSpyDriverOSAdaption.h"
|
|
33 |
#include "MemSpyDriverInspectedProcessManager.h"
|
|
34 |
|
|
35 |
// Constants
|
|
36 |
_LIT8( KMemSpyLitDollarHeap, "$HEAP" );
|
|
37 |
_LIT8( KMemSpyLitDollarDllData, "DLL$DATA" );
|
|
38 |
_LIT8( KMemSpyLitDollarDat, "$DAT" );
|
|
39 |
_LIT( KMemSpyInspectedProcessMutexName, "MemSpyInspectedProcess_0x" );
|
|
40 |
|
|
41 |
|
|
42 |
DMemSpyInspectedProcess::DMemSpyInspectedProcess( DMemSpyDriverDevice& aDevice )
|
|
43 |
: iDevice( aDevice )
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
DMemSpyInspectedProcess::~DMemSpyInspectedProcess()
|
|
49 |
{
|
|
50 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - START - this: 0x%08x, %O", this, iProcess ));
|
|
51 |
EventMonitor().RequestEventsCancel( *this );
|
|
52 |
|
|
53 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - calling NotifyOnChangeCancel..." ) );
|
|
54 |
NotifyOnChangeCancel();
|
|
55 |
|
|
56 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - calling ResetTrackedList..." ) );
|
|
57 |
ResetTrackedList();
|
|
58 |
|
|
59 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - calling ResetPendingChanges..." ) );
|
|
60 |
ResetPendingChanges();
|
|
61 |
|
|
62 |
if ( iLock )
|
|
63 |
{
|
|
64 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - closing mutex..." ) );
|
|
65 |
iLock->Close(NULL);
|
|
66 |
}
|
|
67 |
|
|
68 |
if ( iProcess )
|
|
69 |
{
|
|
70 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - closing process..." ) );
|
|
71 |
Kern::SafeClose( (DObject*&) iProcess, NULL );
|
|
72 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - closed process!" ) );
|
|
73 |
}
|
|
74 |
|
|
75 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::~DMemSpyInspectedProcess() - END - this: 0x%08x", this ) );
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
TInt DMemSpyInspectedProcess::Open( DProcess* aProcess )
|
|
80 |
{
|
|
81 |
__ASSERT_CRITICAL;
|
|
82 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::Open() - START - this: 0x%08x, aProcess: 0x%08x (%O)", this, aProcess, aProcess ));
|
|
83 |
|
|
84 |
TInt error = KErrNone;
|
|
85 |
//
|
|
86 |
iProcess = aProcess;
|
|
87 |
error = iProcess->Open();
|
|
88 |
//
|
|
89 |
if ( error == KErrNone )
|
|
90 |
{
|
|
91 |
iProcessId = iDevice.OSAdaption().DProcess().GetId( *aProcess );
|
|
92 |
|
|
93 |
// Create mutex
|
|
94 |
TName name( KMemSpyInspectedProcessMutexName );
|
|
95 |
name.AppendNumFixedWidth( (TUint) this, EHex, 8 );
|
|
96 |
error = Kern::MutexCreate( iLock, name, KMutexOrdNone );
|
|
97 |
//
|
|
98 |
if ( error == KErrNone )
|
|
99 |
{
|
|
100 |
// Get size of all stacks (user & supervsior) for process. Also
|
|
101 |
// updates iUserThreadStackSize with the current size of just
|
|
102 |
// the user-side thread stacks.
|
|
103 |
iInfoCurrent.iMemoryStack = StackSize( *aProcess );
|
|
104 |
|
62
|
105 |
// Request events
|
|
106 |
// Ignore error since it can only be KErrAlreadyExists or KErrNone
|
|
107 |
(void) EventMonitor().RequestEvents( *this );
|
51
|
108 |
|
|
109 |
// Find initial chunks that are mapped into process
|
|
110 |
FindChunks( *aProcess );
|
|
111 |
|
|
112 |
// Indicate that we have data waiting for client. This will
|
|
113 |
// cause the client's RS to be completed as soon as it
|
|
114 |
// registers with us...
|
62
|
115 |
(void) UpdateStatistics();// Ignore return since we don't care if it's different or not
|
|
116 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
51
|
117 |
}
|
|
118 |
}
|
|
119 |
//
|
|
120 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::Open() - END - this: 0x%08x, error: %d", this, error ));
|
|
121 |
return error;
|
|
122 |
}
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
TInt DMemSpyInspectedProcess::NotifyOnChange( DThread* aThread, TRequestStatus* aRequestStatus, TMemSpyDriverProcessInspectionInfo* aInfo )
|
|
132 |
{
|
|
133 |
Lock();
|
|
134 |
|
|
135 |
TInt err = KErrInUse;
|
|
136 |
const TBool notificationQueued = NotifyOnChangeQueued();
|
|
137 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChange() - START - this: 0x%08x, iAmDead: %d, aRequestStatus: 0x%08x, notificationQueued: %d, iChangeObserverThread: 0x%08x (%O)", this, iAmDead, aRequestStatus, notificationQueued, iChangeObserverThread, iChangeObserverThread ) );
|
|
138 |
//
|
|
139 |
if ( notificationQueued == EFalse )
|
|
140 |
{
|
|
141 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChange() - Saving client RS..." ) );
|
|
142 |
iChangeObserverThread = aThread;
|
|
143 |
iChangeObserverRS = aRequestStatus;
|
|
144 |
iChangeObserverInfo = aInfo;
|
|
145 |
|
|
146 |
// Whilst we still have items in the buffer, we let the client drain them fully.
|
|
147 |
// However, if the process is now marked as dead and the buffer is exhausted,
|
|
148 |
// we indicate this via KErrDied completion which will cause the client to
|
|
149 |
// stop requesting any more changes.
|
|
150 |
if ( !iPendingChanges.IsEmpty() )
|
|
151 |
{
|
|
152 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChange() - Have buffered changes - SENDING TO CLIENT IMMEDIATELY..." ) );
|
|
153 |
|
|
154 |
// We have something in the pending buffer so we can
|
|
155 |
// give it back to the client immediately.
|
|
156 |
TMemSpyTrackedChunkChangeInfo* cachedChange = _LOFF( iPendingChanges.First(), TMemSpyTrackedChunkChangeInfo, iLink );
|
|
157 |
cachedChange->iLink.Deque();
|
|
158 |
|
|
159 |
// Notify about change
|
|
160 |
CompleteClientsRequest( KErrNone, &cachedChange->iInfo );
|
|
161 |
|
|
162 |
// Discard cached entry
|
|
163 |
delete cachedChange;
|
|
164 |
}
|
|
165 |
else if ( iAmDead )
|
|
166 |
{
|
|
167 |
// We must stop listening outside of an event monitor callback...
|
|
168 |
EventMonitor().RequestEventsCancel( *this );
|
|
169 |
CompleteClientsRequest( KErrDied );
|
|
170 |
}
|
|
171 |
//
|
|
172 |
err = KErrNone;
|
|
173 |
}
|
|
174 |
//
|
|
175 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChange() - END - this: 0x%08x, err: %d", this, err ) );
|
|
176 |
|
|
177 |
Unlock();
|
|
178 |
return err;
|
|
179 |
}
|
|
180 |
|
|
181 |
|
|
182 |
TInt DMemSpyInspectedProcess::NotifyOnChangeCancel()
|
|
183 |
{
|
|
184 |
Lock();
|
|
185 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeCancel() - START - this: 0x%08x, queued: %d, iChangeObserverThread: 0x%08x, iChangeObserverRS: 0x%08x", this, NotifyOnChangeQueued(), iChangeObserverThread, iChangeObserverRS ) );
|
|
186 |
//
|
|
187 |
if ( NotifyOnChangeQueued() )
|
|
188 |
{
|
|
189 |
TRACE( Kern::Printf( "DMemSpyInspectedProcess::NotifyOnChangeCancel() - this: 0x%08x, iChangeObserverRS: 0x%08x, iProcessId: %d (0x%04x)", this, iChangeObserverRS, iProcessId, iProcessId ) );
|
|
190 |
Kern::RequestComplete( iChangeObserverThread, iChangeObserverRS, KErrCancel );
|
|
191 |
iChangeObserverThread = NULL;
|
|
192 |
iChangeObserverRS = NULL;
|
|
193 |
iChangeObserverInfo = NULL;
|
|
194 |
}
|
|
195 |
//
|
|
196 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeCancel() - END - this: 0x%08x", this ) );
|
|
197 |
Unlock();
|
|
198 |
|
|
199 |
return KErrNone;
|
|
200 |
}
|
|
201 |
|
|
202 |
|
|
203 |
TBool DMemSpyInspectedProcess::NotifyOnChangeQueued() const
|
|
204 |
{
|
|
205 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeQueued() - START - this: 0x%08x", this ) );
|
|
206 |
//
|
|
207 |
Lock();
|
|
208 |
const TBool queued = ( iChangeObserverRS != NULL );
|
|
209 |
Unlock();
|
|
210 |
//
|
|
211 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::NotifyOnChangeQueued() - END - this: 0x%08x, queued: %d", this, queued ) );
|
|
212 |
return queued;
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
void DMemSpyInspectedProcess::CompleteClientsRequest( TInt aCompletionCode, TMemSpyDriverProcessInspectionInfo* aInfo )
|
|
224 |
{
|
|
225 |
const TBool notificationQueued = NotifyOnChangeQueued();
|
|
226 |
TRACE( Kern::Printf( "DMemSpyInspectedProcess::CompleteClientsRequest() - START - this: 0x%08x, iChangeObserverThread: 0x%08x, iChangeObserverRS: 0x%08x, iChangeObserverInfo: 0x%08x, notificationQueued: %d", this, iChangeObserverThread, iChangeObserverRS, iChangeObserverInfo, notificationQueued ) );
|
|
227 |
TRACE( Kern::Printf( "DMemSpyInspectedProcess::CompleteClientsRequest() - iAmDead: %d, buffer is empty: %d, aCompletionCode: %d, iProcessId: %d (0x%04x), aInfo: 0x%08x, iChangeDeliveryCounter: %d", iAmDead, iPendingChanges.IsEmpty(), aCompletionCode, iProcessId, iProcessId, aInfo, iChangeDeliveryCounter ) );
|
|
228 |
|
|
229 |
if ( notificationQueued )
|
|
230 |
{
|
|
231 |
++iChangeDeliveryCounter;
|
|
232 |
TInt completionCode = aCompletionCode;
|
|
233 |
|
|
234 |
// Write them to client...
|
|
235 |
if ( aInfo != NULL )
|
|
236 |
{
|
|
237 |
const TInt writeErr = Kern::ThreadRawWrite( iChangeObserverThread, iChangeObserverInfo, aInfo, sizeof(TMemSpyDriverProcessInspectionInfo) );
|
|
238 |
if ( writeErr != KErrNone )
|
|
239 |
{
|
|
240 |
completionCode = writeErr;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
// Complete client's async request
|
|
245 |
DThread* changeThread = iChangeObserverThread;
|
|
246 |
TRequestStatus* changeRS = iChangeObserverRS;
|
|
247 |
|
|
248 |
// Zero these out first to avoid race condition
|
|
249 |
iChangeObserverThread = NULL;
|
|
250 |
iChangeObserverRS = NULL;
|
|
251 |
iChangeObserverInfo = NULL;
|
|
252 |
|
|
253 |
// ...and then tell client.
|
|
254 |
TRACE( Kern::Printf( "DMemSpyInspectedProcess::CompleteClientsRequest() - SENDING CHANGE [%4d] TO CLIENT [err: %d]", iChangeDeliveryCounter, completionCode ) );
|
|
255 |
Kern::RequestComplete( changeThread, changeRS, completionCode );
|
|
256 |
}
|
|
257 |
else if ( aInfo )
|
|
258 |
{
|
|
259 |
// Buffer the change for next time around...
|
|
260 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::CompleteClientsRequest() - BUFFERING change event whilst client is AWOL...", this ) );
|
|
261 |
NKern::ThreadEnterCS();
|
|
262 |
|
|
263 |
TMemSpyTrackedChunkChangeInfo* changeInfo = new TMemSpyTrackedChunkChangeInfo();
|
|
264 |
if ( changeInfo )
|
|
265 |
{
|
|
266 |
changeInfo->iInfo = *aInfo;
|
|
267 |
iPendingChanges.Add( &changeInfo->iLink );
|
|
268 |
}
|
|
269 |
//
|
|
270 |
NKern::ThreadLeaveCS();
|
|
271 |
}
|
|
272 |
|
|
273 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::CompleteClientsRequest() - END - this: 0x%08x", this ) );
|
|
274 |
}
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
void DMemSpyInspectedProcess::ResetTrackedList()
|
|
288 |
{
|
|
289 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ResetTrackedList() - START - this: 0x%08x", this ) );
|
|
290 |
NKern::ThreadEnterCS();
|
|
291 |
//
|
|
292 |
SDblQueLink* link = iTrackedChunks.GetFirst();
|
|
293 |
while( link )
|
|
294 |
{
|
|
295 |
TMemSpyTrackedChunk* object = _LOFF( link, TMemSpyTrackedChunk, iLink );
|
|
296 |
delete object;
|
|
297 |
link = iTrackedChunks.GetFirst();
|
|
298 |
}
|
|
299 |
//
|
|
300 |
NKern::ThreadLeaveCS();
|
|
301 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ResetTrackedList() - END - this: 0x%08x", this ) );
|
|
302 |
}
|
|
303 |
|
|
304 |
|
|
305 |
void DMemSpyInspectedProcess::SetTrackedListUnused()
|
|
306 |
{
|
|
307 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::SetTrackedListUnused() - START - this: 0x%08x", this ) );
|
|
308 |
SDblQueLink* anchor = &iTrackedChunks.iA;
|
|
309 |
for (SDblQueLink* link = iTrackedChunks.First(); link != anchor; link = link->iNext)
|
|
310 |
{
|
|
311 |
TMemSpyTrackedChunk* trackedChunk = _LOFF( link, TMemSpyTrackedChunk, iLink );
|
|
312 |
trackedChunk->SetUnused( ETrue );
|
|
313 |
}
|
|
314 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::SetTrackedListUnused() - END - this: 0x%08x", this ) );
|
|
315 |
}
|
|
316 |
|
|
317 |
|
|
318 |
void DMemSpyInspectedProcess::SetTrackedListUnusedStatusByType( TMemSpyTrackedChunk::TType aType, TBool aUnusedStatus )
|
|
319 |
{
|
|
320 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::SetTrackedListUnusedStatusByType() - START - this: 0x%08x", this ) );
|
|
321 |
SDblQueLink* anchor = &iTrackedChunks.iA;
|
|
322 |
for (SDblQueLink* link = iTrackedChunks.First(); link != anchor; link = link->iNext)
|
|
323 |
{
|
|
324 |
TMemSpyTrackedChunk* trackedChunk = _LOFF( link, TMemSpyTrackedChunk, iLink );
|
|
325 |
if ( trackedChunk->Type() == aType )
|
|
326 |
{
|
|
327 |
trackedChunk->SetUnused( aUnusedStatus );
|
|
328 |
}
|
|
329 |
}
|
|
330 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::SetTrackedListUnusedStatusByType() - END - this: 0x%08x", this ) );
|
|
331 |
}
|
|
332 |
|
|
333 |
|
|
334 |
void DMemSpyInspectedProcess::DiscardUnusedTrackListItems()
|
|
335 |
{
|
|
336 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::DiscardUnusedTrackListItems() - START - this: 0x%08x", this ) );
|
|
337 |
NKern::ThreadEnterCS();
|
|
338 |
const SDblQueLink* const anchor = &iTrackedChunks.iA;
|
|
339 |
//
|
|
340 |
SDblQueLink* link = iTrackedChunks.First();
|
|
341 |
while( link && link != anchor )
|
|
342 |
{
|
|
343 |
TMemSpyTrackedChunk* trackedChunk = _LOFF( link, TMemSpyTrackedChunk, iLink );
|
|
344 |
const TBool unused = trackedChunk->iUnused;
|
|
345 |
//
|
|
346 |
link = link->iNext;
|
|
347 |
//
|
|
348 |
if ( unused )
|
|
349 |
{
|
|
350 |
trackedChunk->iLink.Deque();
|
|
351 |
delete trackedChunk;
|
|
352 |
}
|
|
353 |
else
|
|
354 |
{
|
|
355 |
trackedChunk->SetUnused( EFalse );
|
|
356 |
}
|
|
357 |
}
|
|
358 |
//
|
|
359 |
NKern::ThreadLeaveCS();
|
|
360 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::DiscardUnusedTrackListItems() - END - this: 0x%08x", this ) );
|
|
361 |
}
|
|
362 |
|
|
363 |
|
|
364 |
void DMemSpyInspectedProcess::AddTrackedChunk( DChunk* aChunk, TMemSpyTrackedChunk::TType aType )
|
|
365 |
{
|
|
366 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::AddTrackedChunk() - START - this: 0x%08x, aChunk: 0x%08x (%O)", this, aChunk, aChunk ) );
|
|
367 |
NKern::ThreadEnterCS();
|
|
368 |
//
|
|
369 |
TMemSpyTrackedChunk* wrapper = new TMemSpyTrackedChunk( aChunk, aType );
|
|
370 |
if ( wrapper )
|
|
371 |
{
|
|
372 |
DMemSpyDriverOSAdaptionDChunk& chunkAdaption = iDevice.OSAdaption().DChunk();
|
|
373 |
const TInt cSize = chunkAdaption.GetSize( *aChunk );
|
|
374 |
wrapper->SetSize( cSize );
|
|
375 |
iTrackedChunks.Add( &wrapper->iLink );
|
|
376 |
}
|
|
377 |
//
|
|
378 |
NKern::ThreadLeaveCS();
|
|
379 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::AddTrackedChunk() - END - this: 0x%08x", this ) );
|
|
380 |
}
|
|
381 |
|
|
382 |
|
|
383 |
TMemSpyTrackedChunk* DMemSpyInspectedProcess::TrackedChunkByHandle( TAny* aHandle )
|
|
384 |
{
|
|
385 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::TrackedChunkByHandle() - START - this: 0x%08x", this ) );
|
|
386 |
TMemSpyTrackedChunk* ret = NULL;
|
|
387 |
//
|
|
388 |
const SDblQueLink* const anchor = &iTrackedChunks.iA;
|
|
389 |
for (SDblQueLink* link = iTrackedChunks.First(); link != anchor; link = link->iNext)
|
|
390 |
{
|
|
391 |
TMemSpyTrackedChunk* const trackedChunk = _LOFF( link, TMemSpyTrackedChunk, iLink );
|
|
392 |
|
|
393 |
if ( trackedChunk && trackedChunk->Handle() == aHandle )
|
|
394 |
{
|
|
395 |
ret = trackedChunk;
|
|
396 |
break;
|
|
397 |
}
|
|
398 |
}
|
|
399 |
//
|
|
400 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::TrackedChunkByHandle() - END - this: 0x%08x, entry: 0x%08x (%O)", this, ret, ret ? ret->iChunk : NULL ) );
|
|
401 |
return ret;
|
|
402 |
}
|
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
DMemSpyInspectedProcessManager& DMemSpyInspectedProcess::PManager()
|
|
415 |
{
|
|
416 |
return iDevice.ProcessInspectionManager();
|
|
417 |
}
|
|
418 |
|
|
419 |
|
|
420 |
DMemSpyEventMonitor& DMemSpyInspectedProcess::EventMonitor()
|
|
421 |
{
|
|
422 |
return iDevice.EventMonitor();
|
|
423 |
}
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
TUint DMemSpyInspectedProcess::EMTypeMask() const
|
|
432 |
{
|
|
433 |
TUint ret = EMemSpyEventThreadAdd | EMemSpyEventThreadRemove | EMemSpyEventThreadKill |
|
|
434 |
EMemSpyEventProcessUpdate | EMemSpyEventProcessRemove |
|
|
435 |
EMemSpyEventChunkAdd | EMemSpyEventChunkUpdate | EMemSpyEventChunkDelete;
|
|
436 |
|
|
437 |
if ( iAmDead )
|
|
438 |
{
|
|
439 |
// Not interested anymore...
|
|
440 |
ret = 0;
|
|
441 |
}
|
|
442 |
|
|
443 |
return ret;
|
|
444 |
}
|
|
445 |
|
|
446 |
|
|
447 |
void DMemSpyInspectedProcess::EMHandleProcessUpdated( DProcess& aProcess )
|
|
448 |
{
|
|
449 |
const TUint procId = iDevice.OSAdaption().DProcess().GetId( aProcess );
|
|
450 |
if ( procId == iProcessId )
|
|
451 |
{
|
|
452 |
Lock();
|
|
453 |
|
|
454 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessUpdated() - START - this: 0x%08x, iProcess: 0x%08x (%O)", this, iProcess, iProcess ) );
|
|
455 |
|
|
456 |
// Mark all tracked chunks as dirty whilst we work out
|
|
457 |
// what is and isn't mapped into the process
|
|
458 |
SetTrackedListUnused();
|
|
459 |
SetTrackedListUnusedStatusByType( TMemSpyTrackedChunk::ETypeChunkGlobalData, EFalse /* global data chunks are still in use */ );
|
|
460 |
|
|
461 |
// Locate any suitable chunks, tagging existing entries as
|
|
462 |
// 'in use' so that we can easily spot ones which are no longer
|
|
463 |
// mapped into the process.
|
|
464 |
FindChunks( *iProcess );
|
|
465 |
|
|
466 |
// Throw away and tracked chunks which aren't mapped into the
|
|
467 |
// process anymore.
|
|
468 |
DiscardUnusedTrackListItems();
|
|
469 |
|
|
470 |
// Calculate latest statistics...
|
|
471 |
const TBool changeDetected = UpdateStatistics();
|
|
472 |
if ( changeDetected )
|
|
473 |
{
|
|
474 |
// Inform observer about new results.
|
|
475 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
|
476 |
}
|
|
477 |
|
|
478 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessUpdated() - END - this: 0x%08x", this ) );
|
|
479 |
|
|
480 |
Unlock();
|
|
481 |
}
|
|
482 |
}
|
|
483 |
|
|
484 |
|
|
485 |
void DMemSpyInspectedProcess::EMHandleProcessRemoved( DProcess& aProcess )
|
|
486 |
{
|
|
487 |
DMemSpyDriverOSAdaptionDProcess& dProcessAdaption = iDevice.OSAdaption().DProcess();
|
|
488 |
const TUint pid = dProcessAdaption.GetId( aProcess );
|
|
489 |
|
|
490 |
if ( pid == iProcessId )
|
|
491 |
{
|
|
492 |
Lock();
|
|
493 |
|
|
494 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessRemoved() - START - this: 0x%08x", this ) );
|
|
495 |
|
|
496 |
// We will implement a multi phased approach to the process being removed.
|
|
497 |
//
|
|
498 |
// The first notification we will send will show that the process heap and
|
|
499 |
// local chunks have been removed, leaving shared chunk sizes intact.
|
|
500 |
//
|
|
501 |
// We will then send another change, this time setting everything to zero...
|
|
502 |
SetTrackedListUnused();
|
|
503 |
SetTrackedListUnusedStatusByType( TMemSpyTrackedChunk::ETypeChunkShared, EFalse /* shared chunks are still in use */ );
|
|
504 |
SetTrackedListUnusedStatusByType( TMemSpyTrackedChunk::ETypeChunkGlobalData, EFalse /* global data chunks are still in use */ );
|
|
505 |
DiscardUnusedTrackListItems();
|
|
506 |
const TBool changeDetected1 = UpdateStatistics();
|
|
507 |
if ( changeDetected1 )
|
|
508 |
{
|
|
509 |
// Inform observer about new results.
|
|
510 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
|
511 |
}
|
|
512 |
|
|
513 |
// Now repeat the exercise, this time removing everything.
|
|
514 |
ResetTrackedList();
|
|
515 |
|
|
516 |
// ... including stack
|
|
517 |
iInfoCurrent.iMemoryStack = 0;
|
|
518 |
|
|
519 |
const TBool changeDetected2 = UpdateStatistics();
|
|
520 |
if ( changeDetected2 )
|
|
521 |
{
|
|
522 |
// Inform observer about new results.
|
|
523 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
|
524 |
}
|
|
525 |
|
|
526 |
// Stop listening to events since we've drained everything now...
|
|
527 |
iAmDead = ETrue;
|
|
528 |
|
|
529 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleProcessRemoved() - END - this: 0x%08x", this ) );
|
|
530 |
|
|
531 |
Unlock();
|
|
532 |
}
|
|
533 |
}
|
|
534 |
|
|
535 |
|
|
536 |
void DMemSpyInspectedProcess::EMHandleThreadAdd( DThread& aThread )
|
|
537 |
{
|
|
538 |
DMemSpyDriverOSAdaptionDThread& dThreadAdaption = iDevice.OSAdaption().DThread();
|
|
539 |
DMemSpyDriverOSAdaptionDProcess& dProcessAdaption = iDevice.OSAdaption().DProcess();
|
|
540 |
//
|
|
541 |
DProcess* owningProcess = dThreadAdaption.GetOwningProcess( aThread );
|
|
542 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleThreadAdd() - this: 0x%08x, aThread: 0x%08x, owningProcess: 0x%08x", this, &aThread, owningProcess ) );
|
|
543 |
if ( owningProcess )
|
|
544 |
{
|
|
545 |
const TUint owningProcessId = dProcessAdaption.GetId( *owningProcess );
|
|
546 |
const TUint myId = dProcessAdaption.GetId( *iProcess );
|
|
547 |
//
|
|
548 |
if ( myId == owningProcessId )
|
|
549 |
{
|
|
550 |
EMHandleThreadChanged( aThread );
|
|
551 |
}
|
|
552 |
}
|
|
553 |
}
|
|
554 |
|
|
555 |
|
|
556 |
void DMemSpyInspectedProcess::EMHandleThreadRemoved( DThread& aThread )
|
|
557 |
{
|
|
558 |
DMemSpyDriverOSAdaptionDThread& dThreadAdaption = iDevice.OSAdaption().DThread();
|
|
559 |
DMemSpyDriverOSAdaptionDProcess& dProcessAdaption = iDevice.OSAdaption().DProcess();
|
|
560 |
//
|
|
561 |
DProcess* owningProcess = dThreadAdaption.GetOwningProcess( aThread );
|
|
562 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleThreadRemoved() - this: 0x%08x, aThread: 0x%08x, owningProcess: 0x%08x", this, &aThread, owningProcess ) );
|
|
563 |
if ( owningProcess )
|
|
564 |
{
|
|
565 |
const TUint owningProcessId = dProcessAdaption.GetId( *owningProcess );
|
|
566 |
const TUint myId = dProcessAdaption.GetId( *iProcess );
|
|
567 |
//
|
|
568 |
if ( myId == owningProcessId )
|
|
569 |
{
|
|
570 |
EMHandleThreadChanged( aThread );
|
|
571 |
}
|
|
572 |
}
|
|
573 |
}
|
|
574 |
|
|
575 |
|
|
576 |
void DMemSpyInspectedProcess::EMHandleThreadKilled( DThread& aThread )
|
|
577 |
{
|
|
578 |
//
|
|
579 |
DMemSpyDriverOSAdaptionDThread& dThreadAdaption = iDevice.OSAdaption().DThread();
|
|
580 |
DMemSpyDriverOSAdaptionDProcess& dProcessAdaption = iDevice.OSAdaption().DProcess();
|
|
581 |
//
|
|
582 |
DProcess* owningProcess = dThreadAdaption.GetOwningProcess( aThread );
|
|
583 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleThreadKilled() - this: 0x%08x, aThread: 0x%08x, owningProcess: 0x%08x", this, &aThread, owningProcess ) );
|
|
584 |
if ( owningProcess )
|
|
585 |
{
|
|
586 |
const TUint owningProcessId = dProcessAdaption.GetId( *owningProcess );
|
|
587 |
const TUint myId = dProcessAdaption.GetId( *iProcess );
|
|
588 |
//
|
|
589 |
if ( myId == owningProcessId )
|
|
590 |
{
|
|
591 |
EMHandleThreadChanged( aThread );
|
|
592 |
}
|
|
593 |
}
|
|
594 |
}
|
|
595 |
|
|
596 |
|
|
597 |
void DMemSpyInspectedProcess::EMHandleThreadChanged( DThread& /*aThread*/ )
|
|
598 |
{
|
|
599 |
Lock();
|
|
600 |
|
|
601 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleThreadChanged() - START - this: 0x%08x", this ) );
|
|
602 |
|
|
603 |
// This is called when a thread is added, changed, or terminated/killed.
|
|
604 |
// We must be careful to only access the members of aThread that still
|
|
605 |
// exist as if it is being destroyed, the object may be in an intermediate
|
|
606 |
// state.
|
|
607 |
|
|
608 |
// All we are really interested in is recalculating the stack usage
|
|
609 |
// for the process...
|
|
610 |
iInfoCurrent.iMemoryStack = StackSize( *iProcess );
|
|
611 |
|
|
612 |
// Always inform observer about new results.
|
|
613 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
|
614 |
|
|
615 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleThreadChanged() - END - this: 0x%08x", this ) );
|
|
616 |
|
|
617 |
Unlock();
|
|
618 |
}
|
|
619 |
|
|
620 |
|
|
621 |
void DMemSpyInspectedProcess::EMHandleChunkAdd( DChunk& aChunk )
|
|
622 |
{
|
|
623 |
Lock();
|
|
624 |
|
|
625 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - START - this: 0x%08x, aChunk: 0x%08x (%O)", this, &aChunk, &aChunk ) );
|
|
626 |
|
|
627 |
// Is this chunk related to our process somehow?
|
|
628 |
if ( IsChunkRelevantToOurProcess( aChunk ) )
|
|
629 |
{
|
|
630 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - processes match, checking chunk type..." ) );
|
|
631 |
|
|
632 |
const TMemSpyTrackedChunk::TType type = ChunkType( &aChunk );
|
|
633 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - chunkType: %d", type ) );
|
|
634 |
|
|
635 |
if ( type != TMemSpyTrackedChunk::ETypeNotRelevant )
|
|
636 |
{
|
|
637 |
// It's a new entry in our process
|
|
638 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - this: 0x%08x, creating new entry for chunk: 0x%08x", this, &aChunk ) );
|
|
639 |
|
|
640 |
AddTrackedChunk( &aChunk, type );
|
|
641 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - added chunk..." ));
|
|
642 |
|
|
643 |
const TBool changeDetected = UpdateStatistics();
|
|
644 |
if ( changeDetected )
|
|
645 |
{
|
|
646 |
// Inform observer about new results.
|
|
647 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
|
648 |
}
|
|
649 |
}
|
|
650 |
}
|
|
651 |
|
|
652 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkAdd() - END - this: 0x%08x", this ) );
|
|
653 |
|
|
654 |
Unlock();
|
|
655 |
}
|
|
656 |
|
|
657 |
|
|
658 |
void DMemSpyInspectedProcess::EMHandleChunkUpdated( DChunk& aChunk )
|
|
659 |
{
|
|
660 |
Lock();
|
|
661 |
|
|
662 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkUpdated() - START - this: 0x%08x, aChunk: 0x%08x [S: %8d] (%O)", this, &aChunk, aChunk.Size(), &aChunk ) );
|
|
663 |
|
|
664 |
// Is this chunk mapped into our process?
|
|
665 |
TMemSpyTrackedChunk* trackedEntry = TrackedChunkByHandle( &aChunk );
|
|
666 |
if ( trackedEntry != NULL )
|
|
667 |
{
|
|
668 |
const TInt oldSize = trackedEntry->Size();
|
|
669 |
const TInt newSize = iDevice.OSAdaption().DChunk().GetSize( aChunk );
|
|
670 |
|
|
671 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkUpdated() - was tracked entry [0x%08x, size; %10d, type: %d] vs new size: %d", trackedEntry, oldSize, trackedEntry->Type(), newSize ) );
|
|
672 |
|
|
673 |
// If the existing entry had a size of 0 and the new size is non-zero
|
|
674 |
// then we may have enough data such that we can validate type information.
|
|
675 |
// For example, any secondary heap chunk that is created within the process will
|
|
676 |
// most likely have a Local-NNNNNN style name, and this chunk will be created with
|
|
677 |
// an initial size of zero.
|
|
678 |
//
|
|
679 |
// We can only identify it's type once the chunk has been updated with some data
|
|
680 |
// that supports vTable verification. Hence the type may fluctuate...
|
|
681 |
if ( oldSize == 0 && newSize > 0 )
|
|
682 |
{
|
|
683 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkUpdated() - checking type again as chunk size was zero..." ) );
|
|
684 |
|
|
685 |
PrintChunkInfo( aChunk );
|
|
686 |
const TMemSpyTrackedChunk::TType type = ChunkType( &aChunk );
|
|
687 |
if ( type != trackedEntry->Type() )
|
|
688 |
{
|
|
689 |
// Type has changed
|
|
690 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkUpdated() - type has transitioned from: %d to %d", trackedEntry->Type(), type ) );
|
|
691 |
trackedEntry->SetType( type );
|
|
692 |
}
|
|
693 |
}
|
|
694 |
|
|
695 |
// Update our record with new chunk size
|
|
696 |
trackedEntry->SetSize( newSize );
|
|
697 |
|
|
698 |
const TBool changeDetected = UpdateStatistics();
|
|
699 |
if ( changeDetected )
|
|
700 |
{
|
|
701 |
// Inform observer about new results.
|
|
702 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
|
703 |
}
|
|
704 |
}
|
|
705 |
|
|
706 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkUpdated() - END - this: 0x%08x", this ) );
|
|
707 |
|
|
708 |
Unlock();
|
|
709 |
}
|
|
710 |
|
|
711 |
|
|
712 |
void DMemSpyInspectedProcess::EMHandleChunkDeleted( DChunk& aChunk )
|
|
713 |
{
|
|
714 |
Lock();
|
|
715 |
|
|
716 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkDeleted() - START - this: 0x%08x", this ) );
|
|
717 |
|
|
718 |
// Is this chunk mapped into our process?
|
|
719 |
TMemSpyTrackedChunk* trackedEntry = TrackedChunkByHandle( &aChunk );
|
|
720 |
if ( trackedEntry != NULL )
|
|
721 |
{
|
|
722 |
// Delete entry
|
|
723 |
trackedEntry->iLink.Deque();
|
|
724 |
delete trackedEntry;
|
|
725 |
|
|
726 |
const TBool changeDetected = UpdateStatistics();
|
|
727 |
if ( changeDetected )
|
|
728 |
{
|
|
729 |
// Inform observer about new results.
|
|
730 |
CompleteClientsRequest( KErrNone, &iInfoCurrent );
|
|
731 |
}
|
|
732 |
}
|
|
733 |
|
|
734 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::EMHandleChunkDeleted() - END - this: 0x%08x", this ) );
|
|
735 |
|
|
736 |
Unlock();
|
|
737 |
}
|
|
738 |
|
|
739 |
|
|
740 |
void DMemSpyInspectedProcess::PrintChunkInfo( DChunk& aChunk ) const
|
|
741 |
{
|
|
742 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::PrintChunkInfo() - iProcess*: 0x%08x", iProcess ) );
|
|
743 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::PrintChunkInfo() - iProcess id: 0x%04x", iProcessId ) );
|
|
744 |
MemSpyDriverUtils::PrintChunkInfo( aChunk, iDevice.OSAdaption() );
|
|
745 |
}
|
|
746 |
|
|
747 |
|
|
748 |
TBool DMemSpyInspectedProcess::IsChunkRelevantToOurProcess( DChunk& aChunk ) const
|
|
749 |
{
|
|
750 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsChunkRelevantToOurProcess() - START - this: 0x%08x, iProcess: 0x%08x (%4d), aChunk: 0x%08x (%O)", this, iProcess, iProcessId, &aChunk, &aChunk) );
|
|
751 |
|
|
752 |
TBool relevant = EFalse;
|
|
753 |
DMemSpyDriverOSAdaptionDChunk& chunkAdaption = iDevice.OSAdaption().DChunk();
|
|
754 |
//
|
|
755 |
PrintChunkInfo( aChunk );
|
|
756 |
//
|
|
757 |
DProcess* chunkProc = chunkAdaption.GetOwningProcess( aChunk );
|
|
758 |
if ( chunkProc )
|
|
759 |
{
|
|
760 |
const TUint procId = iDevice.OSAdaption().DProcess().GetId( *chunkProc );
|
|
761 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsChunkRelevantToOurProcess() - [Owning Process] Comparing chunk pid: 0x%04x with procPid: 0x%04x", this, procId, iProcessId ) );
|
|
762 |
relevant = ( procId == iProcessId );
|
|
763 |
}
|
|
764 |
else if ( chunkAdaption.GetOwner( aChunk ) == iProcess )
|
|
765 |
{
|
|
766 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsChunkRelevantToOurProcess() - [Owner Match]" ) );
|
|
767 |
relevant = ETrue;
|
|
768 |
}
|
|
769 |
else
|
|
770 |
{
|
|
771 |
const TUint controllingOwnerPid = chunkAdaption.GetControllingOwnerId( aChunk );
|
|
772 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsChunkRelevantToOurProcess() - [Controlling Owner] Comparing chunk owner: 0x%04x with procPid: 0x%04x", this, controllingOwnerPid, iProcessId ) );
|
|
773 |
relevant = ( controllingOwnerPid == iProcessId );
|
|
774 |
}
|
|
775 |
|
|
776 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsChunkRelevantToOurProcess() - END - this: 0x%08x, relevant: %d", this, relevant ) );
|
|
777 |
return relevant;
|
|
778 |
}
|
|
779 |
|
|
780 |
|
|
781 |
TMemSpyTrackedChunk::TType DMemSpyInspectedProcess::ChunkType( DObject* aObject ) const
|
|
782 |
{
|
|
783 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - START - this: 0x%08x, iProcess: 0x%08x, aObject: 0x%08x (%O)", this, iProcess, aObject, aObject ) );
|
|
784 |
TMemSpyTrackedChunk::TType ret = TMemSpyTrackedChunk::ETypeNotRelevant;
|
|
785 |
|
|
786 |
// Firstly, check if it's actually held within the chunk container.
|
|
787 |
if ( aObject )
|
|
788 |
{
|
|
789 |
DMemSpyDriverOSAdaptionDChunk& chunkAdaption = iDevice.OSAdaption().DChunk();
|
|
790 |
const TObjectType objectType = chunkAdaption.GetObjectType( *aObject );
|
|
791 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - objectType: %d vs EChunk (%d)", objectType, EChunk ) );
|
|
792 |
|
|
793 |
if ( objectType == EChunk )
|
|
794 |
{
|
|
795 |
DChunk* chunk = (DChunk*) aObject;
|
|
796 |
//
|
|
797 |
if ( IsChunkRelevantToOurProcess( *chunk ) )
|
|
798 |
{
|
|
799 |
TName name;
|
|
800 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - getting chunk name..." ) );
|
|
801 |
chunk->Name( name );
|
|
802 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - name: %S", &name ) );
|
|
803 |
|
|
804 |
// It is definitely owned by this process. That means that
|
|
805 |
// it could be a heap, or then it's a just some other kind
|
|
806 |
// of data chunk which our process happens to have created.
|
|
807 |
//
|
|
808 |
// The main thread within a process results in the creation
|
|
809 |
// of a heap called $HEAP, but that isn't the case for other
|
|
810 |
// secondary (etc) threads.
|
|
811 |
//
|
|
812 |
// Only way I can think to identify these is via vTables.
|
|
813 |
if ( name == KMemSpyLitDollarDllData )
|
|
814 |
{
|
|
815 |
// This chunk contains Dll Global Data for the process
|
|
816 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - TMemSpyTrackedChunk::ETypeChunkGlobalData" ) );
|
|
817 |
ret = TMemSpyTrackedChunk::ETypeChunkGlobalData;
|
|
818 |
}
|
|
819 |
else if ( name == KMemSpyLitDollarDat )
|
|
820 |
{
|
|
821 |
// This chunk contains process global data as well as user-side stacks for
|
|
822 |
// the process. However, we calculate the stacks independently, so we must
|
|
823 |
// adjust this later on to remove stack overhead.
|
|
824 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - TMemSpyTrackedChunk::ETypeChunkProcessGlobalDataAndUserStack" ) );
|
|
825 |
ret = TMemSpyTrackedChunk::ETypeChunkProcessGlobalDataAndUserStack;
|
|
826 |
}
|
|
827 |
else if ( IsHeapChunk( *chunk, name ) )
|
|
828 |
{
|
|
829 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - TMemSpyTrackedChunk::ETypeChunkHeap" ) );
|
|
830 |
ret = TMemSpyTrackedChunk::ETypeChunkHeap;
|
|
831 |
}
|
|
832 |
else
|
|
833 |
{
|
|
834 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - TMemSpyTrackedChunk::ETypeChunkLocal" ) );
|
|
835 |
ret = TMemSpyTrackedChunk::ETypeChunkLocal;
|
|
836 |
}
|
|
837 |
}
|
|
838 |
else
|
|
839 |
{
|
|
840 |
// It's a chunk that is mapped into our process,
|
|
841 |
// but isn't owned by us. Therefore it is shared by some
|
|
842 |
// other process.
|
|
843 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - TMemSpyTrackedChunk::ETypeChunkShared" ) );
|
|
844 |
ret = TMemSpyTrackedChunk::ETypeChunkShared;
|
|
845 |
}
|
|
846 |
}
|
|
847 |
}
|
|
848 |
|
|
849 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ChunkType() - END - this: 0x%08x, ret: %d", this, ret ) );
|
|
850 |
return ret;
|
|
851 |
}
|
|
852 |
|
|
853 |
|
|
854 |
TBool DMemSpyInspectedProcess::IsHeapChunk( DChunk& aChunk, const TName& aName ) const
|
|
855 |
{
|
|
856 |
const TUint rHeapVTable = iDevice.RHeapVTable();
|
|
857 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - START - this: 0x%08x, aChunk: 0x%08x, RHeapVTable: 0x%08x, iProcess: 0x%08x, aName: %S, (%O)", this, &aChunk, rHeapVTable, iProcess, &aName, &aChunk ) );
|
|
858 |
|
|
859 |
// The first 4 bytes of every chunk correspond to the allocator VTable (For heap chunks).
|
|
860 |
// If it matches RHeap's vtable, we'll treat it as a heap.
|
|
861 |
TBool isHeap = EFalse;
|
|
862 |
|
|
863 |
DMemSpyDriverOSAdaptionDChunk& chunkAdaption = iDevice.OSAdaption().DChunk();
|
|
864 |
TUint8* base = chunkAdaption.GetBase( aChunk );
|
|
865 |
const TInt size = chunkAdaption.GetSize( aChunk );
|
|
866 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - base: 0x%08x, size: %d", base, size ) );
|
|
867 |
|
|
868 |
if ( iProcess && size >= 4 )
|
|
869 |
{
|
|
870 |
// Chunks are mapped into entire process so any thread within the process is enough...
|
|
871 |
DThread* firstThread = iProcess->FirstThread();
|
|
872 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - firstThread: 0x%08x (%O)", firstThread, firstThread ) );
|
|
873 |
if ( firstThread != NULL )
|
|
874 |
{
|
|
875 |
NKern::ThreadEnterCS();
|
|
876 |
TInt err = firstThread->Open();
|
|
877 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - firstThread open result: %d", err ) );
|
|
878 |
|
|
879 |
if ( err == KErrNone )
|
|
880 |
{
|
|
881 |
TBuf8<4> allocatorVTableBuffer;
|
|
882 |
err = Kern::ThreadRawRead( firstThread, base, (TUint8*) allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength() );
|
|
883 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk - read result of vtable data from requested thread is: %d", err ));
|
|
884 |
//
|
|
885 |
if ( err == KErrNone )
|
|
886 |
{
|
|
887 |
TRACE( MemSpyDriverUtils::DataDump("possible chunk vtable data - %lS", allocatorVTableBuffer.Ptr(), allocatorVTableBuffer.MaxLength(), allocatorVTableBuffer.MaxLength() ) );
|
|
888 |
allocatorVTableBuffer.SetLength( allocatorVTableBuffer.MaxLength() );
|
|
889 |
|
|
890 |
const TUint32 vtable = allocatorVTableBuffer[0] +
|
|
891 |
(allocatorVTableBuffer[1] << 8) +
|
|
892 |
(allocatorVTableBuffer[2] << 16) +
|
|
893 |
(allocatorVTableBuffer[3] << 24);
|
|
894 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk - [possible] vTable within chunk is: 0x%08x", vtable) );
|
|
895 |
|
|
896 |
// Check the v-table to work out if it really is an RHeap
|
|
897 |
isHeap = ( vtable == rHeapVTable );
|
|
898 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - isHeap: %d", isHeap ) );
|
|
899 |
}
|
|
900 |
|
|
901 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - closing first thread..." ) );
|
|
902 |
Kern::SafeClose( (DObject*&) firstThread, NULL );
|
|
903 |
}
|
|
904 |
NKern::ThreadLeaveCS();
|
|
905 |
}
|
|
906 |
}
|
|
907 |
//
|
|
908 |
if ( !isHeap && aName == KMemSpyLitDollarHeap )
|
|
909 |
{
|
|
910 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - is standard Symbian OS initial heap chunk - $HEAP" ) );
|
|
911 |
isHeap = ETrue;
|
|
912 |
}
|
|
913 |
//
|
|
914 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::IsHeapChunk() - END - this: 0x%08x, isHeap: %d", this, isHeap ) );
|
|
915 |
return isHeap;
|
|
916 |
}
|
|
917 |
|
|
918 |
|
|
919 |
TUint32 DMemSpyInspectedProcess::TotalStatistics( const TMemSpyDriverProcessInspectionInfo& aStats, TBool aIncludeShared )
|
|
920 |
{
|
|
921 |
TUint32 total = aStats.iMemoryStack +
|
|
922 |
aStats.iMemoryHeap +
|
|
923 |
aStats.iMemoryChunkLocal +
|
|
924 |
aStats.iMemoryGlobalData;
|
|
925 |
//
|
|
926 |
if ( aIncludeShared )
|
|
927 |
{
|
|
928 |
total += aStats.iMemoryChunkShared;
|
|
929 |
}
|
|
930 |
//
|
|
931 |
return total;
|
|
932 |
}
|
|
933 |
|
|
934 |
|
|
935 |
TBool DMemSpyInspectedProcess::IsEqual( const TMemSpyDriverProcessInspectionInfo& aLeft, const TMemSpyDriverProcessInspectionInfo& aRight )
|
|
936 |
{
|
|
937 |
const TBool equal = ( aLeft.iMemoryStack == aRight.iMemoryStack &&
|
|
938 |
aLeft.iMemoryHeap == aRight.iMemoryHeap &&
|
|
939 |
aLeft.iMemoryChunkLocal == aRight.iMemoryChunkLocal &&
|
|
940 |
aLeft.iMemoryChunkShared == aRight.iMemoryChunkShared &&
|
|
941 |
aLeft.iMemoryGlobalData == aRight.iMemoryGlobalData
|
|
942 |
);
|
|
943 |
return equal;
|
|
944 |
}
|
|
945 |
|
|
946 |
|
|
947 |
void DMemSpyInspectedProcess::ResetStatistics( TMemSpyDriverProcessInspectionInfo& aStats )
|
|
948 |
{
|
|
949 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ResetStatistics() - START - this: 0x%08x", this ) );
|
|
950 |
aStats.iProcessId = iProcessId;
|
|
951 |
aStats.iMemoryHeap = 0;
|
|
952 |
aStats.iMemoryChunkLocal = 0;
|
|
953 |
aStats.iMemoryChunkShared = 0;
|
|
954 |
aStats.iMemoryGlobalData = 0;
|
|
955 |
aStats.iTime = Kern::SystemTime();
|
|
956 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ResetStatistics() - END - this: 0x%08x", this ) );
|
|
957 |
}
|
|
958 |
|
|
959 |
|
|
960 |
TBool DMemSpyInspectedProcess::UpdateStatistics()
|
|
961 |
{
|
|
962 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - START - this: 0x%08x, iChangeDeliveryCounter: %04d, iProcess: 0x%08x %O", this, iChangeDeliveryCounter, iProcess, iProcess ) );
|
|
963 |
|
|
964 |
// Preserve last stats so we can identify if something really changed...
|
|
965 |
iInfoLast = iInfoCurrent;
|
|
966 |
|
|
967 |
// Reset current stats ready for updating. This doesn't wipe the stack field, since
|
|
968 |
// that only changes when some kind of thread event occurs...
|
|
969 |
ResetStatistics( iInfoCurrent );
|
|
970 |
|
|
971 |
// Go through all tracked chunks and update our stats based upon
|
|
972 |
// their current values...
|
|
973 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
974 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
975 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
976 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() CHUNK ENTRIES:" ) );
|
|
977 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
978 |
const SDblQueLink* const anchor = &iTrackedChunks.iA;
|
|
979 |
for (SDblQueLink* link = iTrackedChunks.First(); link != anchor; link = link->iNext)
|
|
980 |
{
|
|
981 |
TMemSpyTrackedChunk* const trackedChunk = _LOFF( link, TMemSpyTrackedChunk, iLink );
|
|
982 |
//
|
|
983 |
switch( trackedChunk->Type() )
|
|
984 |
{
|
|
985 |
case TMemSpyTrackedChunk::ETypeChunkHeap:
|
|
986 |
iInfoCurrent.iMemoryHeap += trackedChunk->Size();
|
|
987 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - [0x%08x] TMemSpyTrackedChunk::ETypeChunkHeap - %12d (0x%08x, %O)", trackedChunk, trackedChunk->Size(), trackedChunk->iChunk, trackedChunk->iChunk ) );
|
|
988 |
break;
|
|
989 |
case TMemSpyTrackedChunk::ETypeChunkLocal:
|
|
990 |
iInfoCurrent.iMemoryChunkLocal += trackedChunk->Size();
|
|
991 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - [0x%08x] TMemSpyTrackedChunk::ETypeChunkLocal - %12d (0x%08x, %O)", trackedChunk, trackedChunk->Size(), trackedChunk->iChunk, trackedChunk->iChunk ) );
|
|
992 |
break;
|
|
993 |
case TMemSpyTrackedChunk::ETypeChunkShared:
|
|
994 |
iInfoCurrent.iMemoryChunkShared += trackedChunk->Size();
|
|
995 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - [0x%08x] TMemSpyTrackedChunk::ETypeChunkShared - %12d (0x%08x, %O)", trackedChunk, trackedChunk->Size(), trackedChunk->iChunk, trackedChunk->iChunk ) );
|
|
996 |
break;
|
|
997 |
case TMemSpyTrackedChunk::ETypeChunkGlobalData:
|
|
998 |
iInfoCurrent.iMemoryGlobalData += trackedChunk->Size();
|
|
999 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - [0x%08x] TMemSpyTrackedChunk::ETypeChunkGlobalData - %12d (0x%08x, %O)", trackedChunk, trackedChunk->Size(), trackedChunk->iChunk, trackedChunk->iChunk ) );
|
|
1000 |
break;
|
|
1001 |
case TMemSpyTrackedChunk::ETypeChunkProcessGlobalDataAndUserStack:
|
|
1002 |
break;
|
|
1003 |
|
|
1004 |
default:
|
|
1005 |
case TMemSpyTrackedChunk::ETypeNotRelevant:
|
|
1006 |
break;
|
|
1007 |
}
|
|
1008 |
}
|
|
1009 |
|
|
1010 |
const TUint32 totalLastIncShared = TotalStatistics( iInfoLast );
|
|
1011 |
const TUint32 totalLastExcShared = TotalStatistics( iInfoLast, EFalse );
|
|
1012 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1013 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1014 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() LAST:" ) );
|
|
1015 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1016 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoLast.iMemoryStack: %12d", iInfoLast.iMemoryStack ) );
|
|
1017 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoLast.iMemoryHeap: %12d", iInfoLast.iMemoryHeap ) );
|
|
1018 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoLast.iMemoryChunkLocal: %12d", iInfoLast.iMemoryChunkLocal ) );
|
|
1019 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoLast.iMemoryChunkShared: %12d", iInfoLast.iMemoryChunkShared ) );
|
|
1020 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoLast.iMemoryGlobalData: %12d", iInfoLast.iMemoryGlobalData ) );
|
|
1021 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - --------------------------------------------------------------------------" ) );
|
|
1022 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoLast total: %12d / %12d", totalLastIncShared, totalLastExcShared ) );
|
|
1023 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1024 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1025 |
|
|
1026 |
|
|
1027 |
const TUint32 totalCurrentIncShared = TotalStatistics( iInfoCurrent );
|
|
1028 |
const TUint32 totalCurrentExcShared = TotalStatistics( iInfoCurrent, EFalse );
|
|
1029 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() CURRENT:" ) );
|
|
1030 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1031 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoCurrent.iMemoryStack: %12d", iInfoCurrent.iMemoryStack ) );
|
|
1032 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoCurrent.iMemoryHeap: %12d", iInfoCurrent.iMemoryHeap ) );
|
|
1033 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoCurrent.iMemoryChunkLocal: %12d", iInfoCurrent.iMemoryChunkLocal ) );
|
|
1034 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoCurrent.iMemoryChunkShared: %12d", iInfoCurrent.iMemoryChunkShared ) );
|
|
1035 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoCurrent.iMemoryGlobalData: %12d", iInfoCurrent.iMemoryGlobalData ) );
|
|
1036 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - --------------------------------------------------------------------------" ) );
|
|
1037 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoCurrent total: %12d / %12d", totalCurrentIncShared, totalCurrentExcShared ) );
|
|
1038 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1039 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1040 |
|
|
1041 |
// Update peaks, i.e. how large each individual element reached
|
|
1042 |
const TUint32 totalPeaks = TotalStatistics( iInfoPeaks );
|
|
1043 |
iInfoPeaks.iMemoryStack = Max( iInfoPeaks.iMemoryStack, iInfoCurrent.iMemoryStack );
|
|
1044 |
iInfoPeaks.iMemoryHeap = Max( iInfoPeaks.iMemoryHeap, iInfoCurrent.iMemoryHeap );
|
|
1045 |
iInfoPeaks.iMemoryChunkLocal = Max( iInfoPeaks.iMemoryChunkLocal, iInfoCurrent.iMemoryChunkLocal );
|
|
1046 |
iInfoPeaks.iMemoryChunkShared = Max( iInfoPeaks.iMemoryChunkShared, iInfoCurrent.iMemoryChunkShared );
|
|
1047 |
iInfoPeaks.iMemoryGlobalData = Max( iInfoPeaks.iMemoryGlobalData, iInfoCurrent.iMemoryGlobalData );
|
|
1048 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() PEAK:" ) );
|
|
1049 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1050 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoPeaks.iMemoryStack: %12d", iInfoPeaks.iMemoryStack ) );
|
|
1051 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoPeaks.iMemoryHeap: %12d", iInfoPeaks.iMemoryHeap ) );
|
|
1052 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoPeaks.iMemoryChunkLocal: %12d", iInfoPeaks.iMemoryChunkLocal ) );
|
|
1053 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoPeaks.iMemoryChunkShared: %12d", iInfoPeaks.iMemoryChunkShared ) );
|
|
1054 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoPeaks.iMemoryGlobalData: %12d", iInfoPeaks.iMemoryGlobalData ) );
|
|
1055 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - -----------------------------------------------------" ) );
|
|
1056 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoPeaks total: %12d", totalPeaks ) );
|
|
1057 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1058 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1059 |
|
|
1060 |
// Update HWM, i.e. the largest total so far.
|
|
1061 |
const TUint32 totalHWMIncShared = TotalStatistics( iInfoHWMIncShared );
|
|
1062 |
const TUint32 totalHWMExcShared = TotalStatistics( iInfoHWMIncShared, EFalse );
|
|
1063 |
if ( totalCurrentIncShared > totalHWMIncShared )
|
|
1064 |
{
|
|
1065 |
iInfoHWMIncShared = iInfoCurrent;
|
|
1066 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() HWM INC SHARED:" ) );
|
|
1067 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1068 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMIncShared.iMemoryStack: %12d", iInfoHWMIncShared.iMemoryStack ) );
|
|
1069 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMIncShared.iMemoryHeap: %12d", iInfoHWMIncShared.iMemoryHeap ) );
|
|
1070 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMIncShared.iMemoryChunkLocal: %12d", iInfoHWMIncShared.iMemoryChunkLocal ) );
|
|
1071 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMIncShared.iMemoryChunkShared: %12d", iInfoHWMIncShared.iMemoryChunkShared ) );
|
|
1072 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMIncShared.iMemoryGlobalData: %12d", iInfoHWMIncShared.iMemoryGlobalData ) );
|
|
1073 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - -----------------------------------------------------" ) );
|
|
1074 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMIncShared total: %12d", totalHWMIncShared ) );
|
|
1075 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1076 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1077 |
}
|
|
1078 |
if ( totalCurrentExcShared > totalHWMExcShared )
|
|
1079 |
{
|
|
1080 |
iInfoHWMExcShared = iInfoCurrent;
|
|
1081 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() HWM EXC SHARED:" ) );
|
|
1082 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1083 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMExcShared.iMemoryStack: %12d", iInfoHWMExcShared.iMemoryStack ) );
|
|
1084 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMExcShared.iMemoryHeap: %12d", iInfoHWMExcShared.iMemoryHeap ) );
|
|
1085 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMExcShared.iMemoryChunkLocal: %12d", iInfoHWMExcShared.iMemoryChunkLocal ) );
|
|
1086 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMExcShared.iMemoryChunkShared: %12d", iInfoHWMExcShared.iMemoryChunkShared ) );
|
|
1087 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMExcShared.iMemoryGlobalData: %12d", iInfoHWMExcShared.iMemoryGlobalData ) );
|
|
1088 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - -----------------------------------------------------" ) );
|
|
1089 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - iInfoHWMExcShared total: %12d", totalHWMExcShared ) );
|
|
1090 |
}
|
|
1091 |
|
|
1092 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1093 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() " ) );
|
|
1094 |
|
|
1095 |
// Work out if something changed...
|
|
1096 |
const TBool statsChanged = !IsEqual( iInfoLast, iInfoCurrent );
|
|
1097 |
if ( statsChanged )
|
|
1098 |
{
|
|
1099 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - STATS CHANGED!" ) );
|
|
1100 |
}
|
|
1101 |
|
|
1102 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::UpdateStatistics() - END - this: 0x%08x, statsChanged: %d, iChangeDeliveryCounter: %04d, iProcess: 0x%08x %O", this, statsChanged, iChangeDeliveryCounter, iProcess, iProcess ) );
|
|
1103 |
return statsChanged;
|
|
1104 |
}
|
|
1105 |
|
|
1106 |
|
|
1107 |
void DMemSpyInspectedProcess::FindChunks( DProcess& aProcess )
|
|
1108 |
{
|
|
1109 |
__ASSERT_CRITICAL;
|
|
1110 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - START - this: 0x%08x", this ) );
|
|
1111 |
|
|
1112 |
DMemSpyDriverOSAdaptionDChunk& chunkAdaption = iDevice.OSAdaption().DChunk();
|
|
1113 |
DMemSpyDriverOSAdaptionDProcess& processAdaption = iDevice.OSAdaption().DProcess();
|
|
1114 |
|
|
1115 |
// Iterate through each handle in the process
|
|
1116 |
if ( processAdaption.IsHandleIndexValid( aProcess ) )
|
|
1117 |
{
|
|
1118 |
MemSpyObjectIx* processHandles = processAdaption.GetHandles( aProcess );
|
|
1119 |
|
|
1120 |
MemSpyObjectIx_HandleLookupLock();
|
|
1121 |
const TInt count = processHandles->Count();
|
|
1122 |
MemSpyObjectIx_HandleLookupUnlock();
|
|
1123 |
|
|
1124 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - got: %d handles...", count ) );
|
|
1125 |
|
|
1126 |
for( TInt i=0; i<count; i++ )
|
|
1127 |
{
|
|
1128 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - checking handle index: %2d", i ) );
|
|
1129 |
|
|
1130 |
// Get a handle from the process container...
|
|
1131 |
MemSpyObjectIx_HandleLookupLock();
|
|
1132 |
if (i >= processHandles->Count()) break; // Count may have changed in the meantime
|
|
1133 |
DObject* object = (*processHandles)[ i ];
|
|
1134 |
if (object && object->Open() != KErrNone) object = NULL;
|
|
1135 |
MemSpyObjectIx_HandleLookupUnlock();
|
|
1136 |
|
|
1137 |
const TObjectType objectType = ( object ? chunkAdaption.GetObjectType( *object ) : EObjectTypeAny );
|
|
1138 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - object: 0x%08x, type: %2d (%O)", object, objectType, object ) );
|
|
1139 |
|
|
1140 |
// Is it a chunk that is already mapped into our process?
|
|
1141 |
// See if we're already aware of this chunk...
|
|
1142 |
if ( object != NULL && objectType == EChunk )
|
|
1143 |
{
|
|
1144 |
TMemSpyTrackedChunk* existingEntry = TrackedChunkByHandle( object );
|
|
1145 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - found a chunk, existing lookup entry: 0x%08x", existingEntry ) );
|
|
1146 |
|
|
1147 |
if ( existingEntry != NULL )
|
|
1148 |
{
|
|
1149 |
const TInt cSize = chunkAdaption.GetSize( *existingEntry->iChunk );
|
|
1150 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - setting existing entry size to: %d", cSize ) );
|
|
1151 |
|
|
1152 |
// It must be a chunk then... Update size
|
|
1153 |
existingEntry->SetSize( cSize );
|
|
1154 |
|
|
1155 |
// This item is in use, i.e. it is not unused
|
|
1156 |
existingEntry->SetUnused( EFalse );
|
|
1157 |
}
|
|
1158 |
else
|
|
1159 |
{
|
|
1160 |
DChunk* chunk = (DChunk*) object;
|
|
1161 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - chunk not known, checking type..." ) );
|
|
1162 |
|
|
1163 |
// We have no record of this item so far. Is it really a chunk?
|
|
1164 |
const TMemSpyTrackedChunk::TType type = ChunkType( object );
|
|
1165 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - type is: %d", type ) );
|
|
1166 |
|
|
1167 |
if ( type != TMemSpyTrackedChunk::ETypeNotRelevant )
|
|
1168 |
{
|
|
1169 |
// It's a new entry
|
|
1170 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - this: 0x%08x, creating new entry for chunk: 0x%08x", this, chunk ) );
|
|
1171 |
|
|
1172 |
AddTrackedChunk( chunk, type );
|
|
1173 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - added chunk..." ));
|
|
1174 |
}
|
|
1175 |
}
|
|
1176 |
}
|
|
1177 |
if (object) object->Close(NULL);
|
|
1178 |
}
|
|
1179 |
}
|
|
1180 |
|
|
1181 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::FindChunks() - END - this: 0x%08x", this ) );
|
|
1182 |
}
|
|
1183 |
|
|
1184 |
|
|
1185 |
TInt DMemSpyInspectedProcess::StackSize( DProcess& aProcess )
|
|
1186 |
{
|
|
1187 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::StackSize() - START - this: 0x%08x", this ) );
|
|
1188 |
TInt ret = 0;
|
|
1189 |
//
|
|
1190 |
DMemSpyDriverOSAdaptionDThread& dThreadAdaption = iDevice.OSAdaption().DThread();
|
|
1191 |
|
|
1192 |
iUserThreadStackSize = 0;
|
|
1193 |
//
|
|
1194 |
SDblQueLink* pLink = aProcess.iThreadQ.First();
|
|
1195 |
while(pLink != &aProcess.iThreadQ.iA)
|
|
1196 |
{
|
|
1197 |
DThread* pT = _LOFF( pLink, DThread, iProcessLink );
|
|
1198 |
//
|
|
1199 |
const TUint32 userStackSize = dThreadAdaption.GetUserStackSize( *pT );
|
|
1200 |
const TUint32 suprStackSize = dThreadAdaption.GetSupervisorStackSize( *pT );
|
|
1201 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::StackSize() - thread: 0x%08x, userStack: %8d, suprStack: %8d, total: %8d %O", pT, userStackSize, suprStackSize, userStackSize + suprStackSize, pT ));
|
|
1202 |
//
|
|
1203 |
iUserThreadStackSize += userStackSize;
|
|
1204 |
ret += userStackSize + suprStackSize;
|
|
1205 |
//
|
|
1206 |
pLink = pLink->iNext;
|
|
1207 |
}
|
|
1208 |
//
|
|
1209 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::StackSize() - END - this: 0x%08x, total stack size for process: %8d, iUserThreadStackSize: %8d", this, ret, iUserThreadStackSize ) );
|
|
1210 |
return ret;
|
|
1211 |
}
|
|
1212 |
|
|
1213 |
|
|
1214 |
void DMemSpyInspectedProcess::ResetPendingChanges()
|
|
1215 |
{
|
|
1216 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ResetPendingChanges() - START - this: 0x%08x", this ) );
|
|
1217 |
NKern::ThreadEnterCS();
|
|
1218 |
//
|
|
1219 |
SDblQueLink* link = iPendingChanges.GetFirst();
|
|
1220 |
while( link )
|
|
1221 |
{
|
|
1222 |
TMemSpyTrackedChunkChangeInfo* cachedChange = _LOFF( link, TMemSpyTrackedChunkChangeInfo, iLink );
|
|
1223 |
delete cachedChange;
|
|
1224 |
link = iPendingChanges.GetFirst();
|
|
1225 |
}
|
|
1226 |
//
|
|
1227 |
NKern::ThreadLeaveCS();
|
|
1228 |
TRACE( Kern::Printf("DMemSpyInspectedProcess::ResetPendingChanges() - END - this: 0x%08x", this ) );
|
|
1229 |
}
|
|
1230 |
|
|
1231 |
|
|
1232 |
void DMemSpyInspectedProcess::Lock() const
|
|
1233 |
{
|
|
1234 |
NKern::ThreadEnterCS();
|
|
1235 |
Kern::MutexWait(*iLock);
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
void DMemSpyInspectedProcess::Unlock() const
|
|
1239 |
{
|
|
1240 |
Kern::MutexSignal(*iLock);
|
|
1241 |
NKern::ThreadLeaveCS();
|
|
1242 |
}
|
|
1243 |
|
|
1244 |
|
|
1245 |
|
|
1246 |
|
|
1247 |
|
|
1248 |
|
|
1249 |
|
|
1250 |
|
|
1251 |
|
|
1252 |
|
|
1253 |
TMemSpyTrackedChunk::TMemSpyTrackedChunk( DChunk* aChunk, TType aType )
|
|
1254 |
: iChunk( aChunk ), iType( aType ), iSize( 0 ), iUnused( EFalse )
|
|
1255 |
{
|
|
1256 |
}
|
|
1257 |
|
|
1258 |
|
|
1259 |
void TMemSpyTrackedChunk::SetSize( TInt aSize )
|
|
1260 |
{
|
|
1261 |
iSize = aSize;
|
|
1262 |
}
|
|
1263 |
|
|
1264 |
|
|
1265 |
void TMemSpyTrackedChunk::SetUnused( TBool aUnused )
|
|
1266 |
{
|
|
1267 |
iUnused = aUnused;
|
|
1268 |
}
|
|
1269 |
|