|
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 MEMSPYDRIVEROBJECTSSHAREDRHEAP_H |
|
19 #define MEMSPYDRIVEROBJECTSSHAREDRHEAP_H |
|
20 |
|
21 // System includes |
|
22 #include <e32cmn.h> |
|
23 #include <e32ldr.h> |
|
24 #include <e32ldr_private.h> |
|
25 #ifndef __KERNEL_MODE__ |
|
26 #include <e32debug.h> |
|
27 #endif |
|
28 |
|
29 // User includes |
|
30 #include <memspy/driver/memspydriverenumerationsshared.h> |
|
31 |
|
32 // Defines |
|
33 //#define __CHECK_CHUNK_NAME |
|
34 |
|
35 // Classes referenced |
|
36 class CActiveScheduler; |
|
37 class CTrapCleanup; |
|
38 |
|
39 |
|
40 |
|
41 class TMemSpyHeapObjectDataRHeap |
|
42 { |
|
43 public: |
|
44 inline TMemSpyHeapObjectDataRHeap() |
|
45 : iAccessCount( 0 ), |
|
46 iHandleCount( 0 ), |
|
47 iHandles( NULL ), |
|
48 iFlags( 0 ), |
|
49 iCellCount( 0 ), |
|
50 iTotalAllocSize ( 0 ), |
|
51 // |
|
52 iMinLength( 0 ), |
|
53 iMaxLength( 0 ), |
|
54 iOffset ( 0 ), |
|
55 iGrowBy( 0 ), |
|
56 iChunkHandle ( 0 ), |
|
57 iBase( NULL ), |
|
58 iTop( NULL ), |
|
59 iAlign( 0 ), |
|
60 iMinCell( 0 ), |
|
61 iPageSize( 0 ), |
|
62 iNestingLevel( 0 ), |
|
63 iAllocCount( 0 ), |
|
64 iFailRate( 0 ), |
|
65 iFailed( EFalse ), |
|
66 iFailAllocCount( 0 ), |
|
67 iRand( 0 ), |
|
68 iTestData( NULL ) |
|
69 { |
|
70 } |
|
71 |
|
72 public: // API |
|
73 inline TUint8* Base() const { return iBase; } |
|
74 inline TUint Size() const { return iTop - iBase; } |
|
75 |
|
76 public: // From RAllocator |
|
77 TInt iAccessCount; |
|
78 TInt iHandleCount; |
|
79 TInt* iHandles; |
|
80 TUint32 iFlags; |
|
81 TInt iCellCount; |
|
82 TInt iTotalAllocSize; |
|
83 |
|
84 public: // From RHeap |
|
85 TInt iMinLength; |
|
86 TInt iMaxLength; |
|
87 TInt iOffset; |
|
88 TInt iGrowBy; |
|
89 TInt iChunkHandle; |
|
90 RFastLock iLock; |
|
91 TUint8* iBase; |
|
92 TUint8* iTop; |
|
93 TInt iAlign; |
|
94 TInt iMinCell; |
|
95 TInt iPageSize; |
|
96 RHeap::SCell iFree; |
|
97 TInt iNestingLevel; |
|
98 TInt iAllocCount; |
|
99 RAllocator::TAllocFail iFailType; |
|
100 TInt iFailRate; |
|
101 TBool iFailed; |
|
102 TInt iFailAllocCount; |
|
103 TInt iRand; |
|
104 TAny* iTestData; |
|
105 }; |
|
106 |
|
107 |
|
108 |
|
109 /** |
|
110 * Base class for MemSpy RHeap statistics |
|
111 */ |
|
112 class TMemSpyHeapStatisticsRHeapBase |
|
113 { |
|
114 public: // Type |
|
115 enum TType |
|
116 { |
|
117 ETypeAllocated = 0, |
|
118 ETypeFree |
|
119 }; |
|
120 |
|
121 public: // Constructors & destructor |
|
122 inline TMemSpyHeapStatisticsRHeapBase( TType aType ) |
|
123 : iType( aType ), |
|
124 iTypeCount( 0 ), |
|
125 iTypeSize( 0 ), |
|
126 iLargestCellAddress( NULL ), |
|
127 iLargestCellSize( 0 ) |
|
128 { |
|
129 } |
|
130 |
|
131 public: // API |
|
132 inline TType Type() const { return iType; } |
|
133 // |
|
134 inline TUint TypeCount() const { return iTypeCount; } |
|
135 inline void SetTypeCount( TUint aValue ) { iTypeCount = aValue; } |
|
136 // |
|
137 inline TUint TypeSize() const { return iTypeSize; } |
|
138 inline void SetTypeSize( TUint aValue ) { iTypeSize = aValue; } |
|
139 // |
|
140 inline TAny* LargestCellAddress() const { return iLargestCellAddress; } |
|
141 inline void SetLargestCellAddress( TAny* aAddress ) { iLargestCellAddress = aAddress; } |
|
142 // |
|
143 inline TUint LargestCellSize() const { return iLargestCellSize; } |
|
144 inline void SetLargestCellSize( TUint aSize ) { iLargestCellSize = aSize; } |
|
145 |
|
146 private: // Data members |
|
147 TType iType; |
|
148 TUint iTypeCount; |
|
149 TUint iTypeSize; |
|
150 TAny* iLargestCellAddress; |
|
151 TUint iLargestCellSize; |
|
152 }; |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 /** |
|
159 * RHeap statistics for Allocated cell types |
|
160 */ |
|
161 class TMemSpyHeapStatisticsRHeapAllocated : public TMemSpyHeapStatisticsRHeapBase |
|
162 { |
|
163 public: // Constructors |
|
164 inline TMemSpyHeapStatisticsRHeapAllocated() |
|
165 : TMemSpyHeapStatisticsRHeapBase( TMemSpyHeapStatisticsRHeapBase::ETypeAllocated ) |
|
166 { |
|
167 } |
|
168 |
|
169 public: |
|
170 }; |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 /** |
|
178 * RHeap statistics for Free cell types |
|
179 */ |
|
180 class TMemSpyHeapStatisticsRHeapFree : public TMemSpyHeapStatisticsRHeapBase |
|
181 { |
|
182 public: // Constructors |
|
183 inline TMemSpyHeapStatisticsRHeapFree() |
|
184 : TMemSpyHeapStatisticsRHeapBase( TMemSpyHeapStatisticsRHeapBase::ETypeFree ), |
|
185 iSlackSpace( 0 ), iSlackSpaceCellAddress( NULL ), iChecksum( 0 ) |
|
186 { |
|
187 } |
|
188 |
|
189 public: // API |
|
190 inline TUint SlackSpaceCellSize() const { return iSlackSpace; } |
|
191 inline void SetSlackSpaceCellSize( TUint aValue ) { iSlackSpace = aValue; } |
|
192 // |
|
193 inline TAny* SlackSpaceCellAddress() const { return iSlackSpaceCellAddress; } |
|
194 inline void SetSlackSpaceCellAddress( TAny* aAddress ) { iSlackSpaceCellAddress = aAddress; } |
|
195 // |
|
196 inline TUint32 Checksum() const { return iChecksum; } |
|
197 inline void SetChecksum( TUint32 aValue ) { iChecksum = aValue; } |
|
198 |
|
199 public: |
|
200 TUint iSlackSpace; |
|
201 TAny* iSlackSpaceCellAddress; |
|
202 TUint32 iChecksum; |
|
203 }; |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 /** |
|
210 * RHeap statistics for common cell types |
|
211 */ |
|
212 class TMemSpyHeapStatisticsRHeapCommon |
|
213 { |
|
214 public: // Constructors |
|
215 inline TMemSpyHeapStatisticsRHeapCommon() |
|
216 : iTotalCellCount( 0 ) |
|
217 { |
|
218 } |
|
219 |
|
220 public: |
|
221 inline TUint TotalCellCount() const { return iTotalCellCount; } |
|
222 inline void SetTotalCellCount( TUint aValue ) { iTotalCellCount = aValue; } |
|
223 |
|
224 private: |
|
225 TUint iTotalCellCount; |
|
226 }; |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 /** |
|
233 * RHeap statistics class |
|
234 */ |
|
235 class TMemSpyHeapStatisticsRHeap |
|
236 { |
|
237 public: // Constructors |
|
238 inline TMemSpyHeapStatisticsRHeap() |
|
239 { |
|
240 } |
|
241 |
|
242 public: // API |
|
243 inline TMemSpyHeapStatisticsRHeapFree& StatsFree() { return iStatisticsFree; } |
|
244 inline const TMemSpyHeapStatisticsRHeapFree& StatsFree() const { return iStatisticsFree; } |
|
245 // |
|
246 inline TMemSpyHeapStatisticsRHeapAllocated& StatsAllocated() { return iStatisticsAllocated; } |
|
247 inline const TMemSpyHeapStatisticsRHeapAllocated& StatsAllocated() const { return iStatisticsAllocated; } |
|
248 // |
|
249 inline TMemSpyHeapStatisticsRHeapCommon& StatsCommon() { return iStatisticsCommon; } |
|
250 inline const TMemSpyHeapStatisticsRHeapCommon& StatsCommon() const { return iStatisticsCommon; } |
|
251 |
|
252 private: // Data members |
|
253 TMemSpyHeapStatisticsRHeapCommon iStatisticsCommon; |
|
254 TMemSpyHeapStatisticsRHeapFree iStatisticsFree; |
|
255 TMemSpyHeapStatisticsRHeapAllocated iStatisticsAllocated; |
|
256 }; |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 /** |
|
265 * |
|
266 */ |
|
267 class TMemSpyHeapMetaDataRHeap |
|
268 { |
|
269 public: // Constructors |
|
270 inline TMemSpyHeapMetaDataRHeap() |
|
271 : iChunkSize( 0 ), |
|
272 iChunkHandle( NULL ), |
|
273 iChunkBaseAddress( NULL ), |
|
274 iDebugAllocator( EFalse ), |
|
275 iHeaderSizeFree( 0 ), |
|
276 iHeaderSizeAllocated( 0 ), |
|
277 iIsUserThread( ETrue ), |
|
278 iSharedHeap( EFalse ) |
|
279 { |
|
280 } |
|
281 |
|
282 public: // API |
|
283 #ifndef __KERNEL_MODE__ |
|
284 inline TPtrC ChunkName() const |
|
285 { |
|
286 TBool alreadyExpanded = ETrue; |
|
287 |
|
288 #ifdef __CHECK_CHUNK_NAME |
|
289 { |
|
290 RDebug::Printf( "TMemSpyHeapMetaDataRHeap::ChunkName() - BEF - length: %d", iChunkName.Length() ); |
|
291 const TUint8* data2 = iChunkName.Ptr(); |
|
292 const TInt count = iChunkName.Length(); |
|
293 for( TInt i=0;i<count;i++) |
|
294 { |
|
295 RDebug::Printf( "TMemSpyHeapMetaDataRHeap::ChunkName() - BEF - data[%03d] = 0x%08x = %02x (%c)", i, data2, *data2, *data2 ); |
|
296 ++data2; |
|
297 } |
|
298 } |
|
299 #endif |
|
300 |
|
301 // Check if it already has been converted to unicode |
|
302 const TUint8* data = iChunkName.Ptr(); |
|
303 if ( iChunkName.Length() >= 1 ) |
|
304 { |
|
305 const TUint8 highByte = *(data + 1); |
|
306 alreadyExpanded = ( highByte == 0 ); |
|
307 } |
|
308 |
|
309 // Once expanded, the descriptor is twice the length |
|
310 TPtrC ret( (TUint16*) iChunkName.Ptr(), iChunkName.Length() / 2 ); |
|
311 // |
|
312 if ( !alreadyExpanded ) |
|
313 { |
|
314 const TInt halfLength = iChunkName.Length() / 2; |
|
315 TMemSpyHeapMetaDataRHeap* self = const_cast< TMemSpyHeapMetaDataRHeap* >( this ); |
|
316 ret.Set( self->iChunkName.Expand() ); |
|
317 } |
|
318 |
|
319 #ifdef __CHECK_CHUNK_NAME |
|
320 { |
|
321 RDebug::Printf( "TMemSpyHeapMetaDataRHeap::ChunkName() - AFT - length: %d", iChunkName.Length() ); |
|
322 const TUint8* data2 = iChunkName.Ptr(); |
|
323 const TInt count = iChunkName.Length(); |
|
324 for( TInt i=0;i<count;i++) |
|
325 { |
|
326 RDebug::Printf( "TMemSpyHeapMetaDataRHeap::ChunkName() - AFT - data[%03d] = 0x%08x = %02x (%c)", i, data2, *data2, *data2 ); |
|
327 ++data2; |
|
328 } |
|
329 const TPtrC pNextRet( (TUint16*) iChunkName.Ptr(), iChunkName.Length() / 2 ); |
|
330 RDebug::Print( _L("TMemSpyHeapMetaDataRHeap::ChunkName() - ret: [%S], nextRet: [%S]"), &ret, &pNextRet ); |
|
331 } |
|
332 #endif |
|
333 // |
|
334 return ret; |
|
335 } |
|
336 |
|
337 inline void SetChunkName( const TDesC16& aValue ) |
|
338 { |
|
339 iChunkName.Copy( aValue ); |
|
340 iChunkName.Collapse(); |
|
341 } |
|
342 #else |
|
343 inline void SetChunkName( const TDesC8& aValue ) |
|
344 { |
|
345 iChunkName.Copy( aValue ); |
|
346 } |
|
347 #endif |
|
348 // |
|
349 inline TUint ChunkSize() const { return iChunkSize; } |
|
350 inline void SetChunkSize( TUint aValue ) { iChunkSize = aValue; } |
|
351 // |
|
352 inline TAny* ChunkHandle() const { return iChunkHandle; } |
|
353 inline void SetChunkHandle( TAny* aValue ) { iChunkHandle = aValue; } |
|
354 // |
|
355 inline TAny* ChunkBaseAddress() const { return iChunkBaseAddress; } |
|
356 inline void SetChunkBaseAddress( TAny* aValue ) { iChunkBaseAddress = aValue; } |
|
357 // |
|
358 inline TUint HeaderSizeFree() const { return iHeaderSizeFree; } |
|
359 inline void SetHeaderSizeFree( TUint aValue ) { iHeaderSizeFree = aValue; } |
|
360 // |
|
361 inline TUint HeaderSizeAllocated() const { return iHeaderSizeAllocated; } |
|
362 inline void SetHeaderSizeAllocated( TUint aValue ) { iHeaderSizeAllocated = aValue; } |
|
363 // |
|
364 inline TBool IsDebugAllocator() const { return iDebugAllocator; } |
|
365 inline void SetDebugAllocator( TBool aValue ) { iDebugAllocator = aValue; } |
|
366 // |
|
367 inline TBool IsUserThread() const { return iIsUserThread; } |
|
368 inline void SetUserThread( TBool aValue ) { iIsUserThread = aValue; } |
|
369 // |
|
370 inline TBool IsSharedHeap() const { return iSharedHeap; } |
|
371 inline void SetSharedHeap( TBool aValue ) { iSharedHeap = aValue; } |
|
372 // |
|
373 inline TUint VTable() const { return iVTable; } |
|
374 inline void SetVTable( TUint aValue ) { iVTable = aValue; } |
|
375 // |
|
376 inline TUint ClassSize() const { return iClassSize; } |
|
377 inline void SetClassSize( TUint aValue ) { iClassSize = aValue; } |
|
378 |
|
379 private: // Data members |
|
380 TBuf8< KMaxFullName * 2 > iChunkName; |
|
381 TUint iChunkSize; |
|
382 TAny* iChunkHandle; |
|
383 TAny* iChunkBaseAddress; |
|
384 TBool iDebugAllocator; |
|
385 TUint iHeaderSizeFree; |
|
386 TUint iHeaderSizeAllocated; |
|
387 TBool iSharedHeap; |
|
388 TBool iIsUserThread; |
|
389 TUint iVTable; |
|
390 TUint iClassSize; |
|
391 }; |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 /** |
|
400 * |
|
401 */ |
|
402 class TMemSpyHeapInfoRHeap |
|
403 { |
|
404 public: // Constructors |
|
405 inline TMemSpyHeapInfoRHeap() |
|
406 { |
|
407 } |
|
408 |
|
409 public: // API |
|
410 inline TMemSpyHeapMetaDataRHeap& MetaData() { return iMetaData; } |
|
411 inline const TMemSpyHeapMetaDataRHeap& MetaData() const { return iMetaData; } |
|
412 // |
|
413 inline TMemSpyHeapObjectDataRHeap& ObjectData() { return iObjectData; } |
|
414 inline const TMemSpyHeapObjectDataRHeap& ObjectData() const { return iObjectData; } |
|
415 // |
|
416 inline TMemSpyHeapStatisticsRHeap& Statistics() { return iStatistics; } |
|
417 inline const TMemSpyHeapStatisticsRHeap& Statistics() const { return iStatistics; } |
|
418 |
|
419 private: // Data members |
|
420 TMemSpyHeapMetaDataRHeap iMetaData; |
|
421 TMemSpyHeapObjectDataRHeap iObjectData; |
|
422 TMemSpyHeapStatisticsRHeap iStatistics; |
|
423 }; |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 #endif |