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 "MemSpyViewKernelHeap.h" |
|
19 |
|
20 // Engine includes |
|
21 #include <memspy/engine/memspyengine.h> |
|
22 #include <memspy/engine/memspyengineobjectprocess.h> |
|
23 #include <memspy/engine/memspyengineobjectthread.h> |
|
24 #include <memspy/engine/memspyengineobjectcontainer.h> |
|
25 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h> |
|
26 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h> |
|
27 #include <memspy/engine/memspyenginehelperheap.h> |
|
28 #include <memspy/engine/memspyengineoutputlist.h> |
|
29 |
|
30 #include <memspysession.h> |
|
31 #include <memspy/api/memspyapiheap.h> |
|
32 |
|
33 // User includes |
|
34 #include "MemSpyUiUtils.h" |
|
35 #include "MemSpyViewKernel.h" |
|
36 #include "MemSpyContainerObserver.h" |
|
37 |
|
38 // Constants |
|
39 const TInt KMemSpyBufferSize = 20; |
|
40 |
|
41 // Literal constants |
|
42 _LIT(KMemSpyHexFormat, "0x%08x"); |
|
43 _LIT(KMemSpyUnsignedFormat, "%u"); |
|
44 _LIT(KMemSpyDecFormat, "%d"); |
|
45 _LIT(KMemSpyLongFormat, "%Ld"); |
|
46 _LIT(KMemSpyCaptionYes, "Yes"); |
|
47 _LIT(KMemSpyCaptionNo, "No"); |
|
48 |
|
49 |
|
50 CMemSpyViewKernelHeap::CMemSpyViewKernelHeap( RMemSpySession& aSession, MMemSpyViewObserver& aObserver ) //cigasto: remember to uncomment from MMP! |
|
51 : CMemSpyViewBase( aSession, aObserver ) |
|
52 { |
|
53 } |
|
54 |
|
55 CMemSpyViewKernelHeap::~CMemSpyViewKernelHeap() |
|
56 { |
|
57 } |
|
58 |
|
59 |
|
60 void CMemSpyViewKernelHeap::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune ) |
|
61 { |
|
62 _LIT( KTitle, "Kernel Heap" ); |
|
63 SetTitleL( KTitle ); |
|
64 // |
|
65 CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune ); |
|
66 } |
|
67 |
|
68 |
|
69 void CMemSpyViewKernelHeap::RefreshL() |
|
70 { |
|
71 SetListBoxModelL(); |
|
72 CMemSpyViewBase::RefreshL(); |
|
73 } |
|
74 |
|
75 |
|
76 TMemSpyViewType CMemSpyViewKernelHeap::ViewType() const |
|
77 { |
|
78 return EMemSpyViewTypeKernelHeap; |
|
79 } |
|
80 |
|
81 |
|
82 CMemSpyViewBase* CMemSpyViewKernelHeap::PrepareParentViewL() |
|
83 { |
|
84 CMemSpyViewKernel* parent = new(ELeave) CMemSpyViewKernel( iMemSpySession, iObserver ); |
|
85 CleanupStack::PushL( parent ); |
|
86 parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() ); |
|
87 CleanupStack::Pop( parent ); |
|
88 return parent; |
|
89 } |
|
90 |
|
91 |
|
92 CMemSpyViewBase* CMemSpyViewKernelHeap::PrepareChildViewL() |
|
93 { |
|
94 CMemSpyViewBase* child = NULL; |
|
95 return child; |
|
96 } |
|
97 |
|
98 |
|
99 void CMemSpyViewKernelHeap::SetListBoxModelL() |
|
100 { |
|
101 CMemSpyApiHeap* iHeap; |
|
102 iHeap = iMemSpySession.GetHeap( ); |
|
103 |
|
104 CDesCArrayFlat* model = new (ELeave) CDesC16ArrayFlat( 22 ); |
|
105 |
|
106 model = FormatModel( iHeap ); |
|
107 |
|
108 CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox ); |
|
109 listbox->Model()->SetItemTextArray( model ); |
|
110 listbox->Model()->SetOwnershipType( ELbmOwnsItemArray ); |
|
111 } |
|
112 |
|
113 |
|
114 TBool CMemSpyViewKernelHeap::HandleCommandL( TInt aCommand ) |
|
115 { |
|
116 TBool handled = ETrue; |
|
117 // |
|
118 switch ( aCommand ) |
|
119 { |
|
120 case EMemSpyCmdKernelHeapDump: |
|
121 OnCmdDumpKernelHeapL(); |
|
122 break; |
|
123 |
|
124 default: |
|
125 handled = CMemSpyViewBase::HandleCommandL( aCommand ); |
|
126 break; |
|
127 } |
|
128 // |
|
129 return handled; |
|
130 } |
|
131 |
|
132 |
|
133 void CMemSpyViewKernelHeap::OnCmdDumpKernelHeapL() |
|
134 { |
|
135 iMemSpySession.DumpKernelHeap(); |
|
136 } |
|
137 |
|
138 |
|
139 //CDesCArrayFlat* CMemSpyViewKernelHeap::FormatModel( RArray<CMemSpyApiHeap*> &aHeap ) |
|
140 CDesCArrayFlat* CMemSpyViewKernelHeap::FormatModel( CMemSpyApiHeap* aHeap ) |
|
141 { |
|
142 CDesCArrayFlat* model = new (ELeave) CDesC16ArrayFlat( 2 ); |
|
143 |
|
144 if (aHeap) |
|
145 { |
|
146 _LIT( KItem0, "Heap type" ); |
|
147 _LIT( KItem1, "Heap size" ); |
|
148 _LIT( KItem8b, "Heap base address" ); |
|
149 _LIT( KItem1b, "Shared" ); |
|
150 _LIT( KItem2, "Chunk size" ); |
|
151 _LIT( KItem3, "Alloc. count" ); |
|
152 _LIT( KItem4, "Free. count" ); |
|
153 _LIT( KItem5, "Biggest alloc." ); |
|
154 _LIT( KItem6, "Biggest free" ); |
|
155 _LIT( KItem6a, "Total alloc." ); |
|
156 _LIT( KItem6b, "Total free" ); |
|
157 _LIT( KItem7, "Slack free space" ); |
|
158 _LIT( KItem8a, "Fragmentation" ); |
|
159 _LIT( KItem13, "Header size (A)" ); |
|
160 _LIT( KItem14, "Header size (F)" ); |
|
161 _LIT( KItem9a, "Overhead (alloc)" ); |
|
162 _LIT( KItem9b, "Overhead (free)" ); |
|
163 _LIT( KItem9c, "Overhead (total)" ); |
|
164 _LIT( KItem9d, "Overhead" ); |
|
165 _LIT( KItem10, "Min. length" ); |
|
166 _LIT( KItem11, "Max. length" ); |
|
167 _LIT( KItem12, "Debug Allocator Library" ); |
|
168 |
|
169 HBufC* hItem = FormatItem( KItem0, aHeap->Type() ); |
|
170 TPtr pItem(hItem->Des()); |
|
171 model->AppendL( pItem ); |
|
172 pItem.Zero(); |
|
173 |
|
174 hItem = FormatItem( KItem1, aHeap->Size() ); |
|
175 pItem = hItem->Des(); |
|
176 model->AppendL( pItem ); |
|
177 pItem.Zero(); |
|
178 |
|
179 TUint address( aHeap->BaseAddress() ); |
|
180 hItem = FormatItem( KItem8b, address ); |
|
181 pItem = hItem->Des(); |
|
182 model->AppendL( pItem ); |
|
183 pItem.Zero(); |
|
184 |
|
185 if(aHeap->Shared()) //Yes / No value formatting |
|
186 hItem = FormatItem( KItem1b, KMemSpyCaptionYes ); |
|
187 else |
|
188 hItem = FormatItem( KItem1b, KMemSpyCaptionNo ); |
|
189 pItem = hItem->Des(); |
|
190 model->AppendL( pItem ); |
|
191 pItem.Zero(); |
|
192 |
|
193 hItem = FormatItem( KItem2, aHeap->ChunkSize() ); |
|
194 pItem = hItem->Des(); |
|
195 model->AppendL( pItem ); |
|
196 pItem.Zero(); |
|
197 |
|
198 hItem = FormatItem( KItem3, aHeap->AllocationsCount() ); |
|
199 pItem = hItem->Des(); |
|
200 model->AppendL( pItem ); |
|
201 pItem.Zero(); |
|
202 |
|
203 hItem = FormatItem( KItem4, aHeap->FreeCount() ); |
|
204 pItem = hItem->Des(); |
|
205 model->AppendL( pItem ); |
|
206 pItem.Zero(); |
|
207 |
|
208 hItem = FormatItem( KItem5, aHeap->BiggestAllocation() ); |
|
209 pItem = hItem->Des(); |
|
210 model->AppendL( pItem ); |
|
211 pItem.Zero(); |
|
212 |
|
213 hItem = FormatItem( KItem6, aHeap->BiggestFree() ); |
|
214 pItem = hItem->Des(); |
|
215 model->AppendL( pItem ); |
|
216 pItem.Zero(); |
|
217 |
|
218 hItem = FormatItem( KItem6a, aHeap->TotalAllocations() ); |
|
219 pItem = hItem->Des(); |
|
220 model->AppendL( pItem ); |
|
221 pItem.Zero(); |
|
222 |
|
223 hItem = FormatItem( KItem6b, aHeap->TotalFree() ); |
|
224 pItem = hItem->Des(); |
|
225 model->AppendL( pItem ); |
|
226 pItem.Zero(); |
|
227 |
|
228 hItem = FormatItem( KItem7, aHeap->SlackFreeSpace() ); |
|
229 pItem = hItem->Des(); |
|
230 model->AppendL( pItem ); |
|
231 pItem.Zero(); |
|
232 |
|
233 TReal iOneHundred( aHeap->Size() ); |
|
234 TReal iValue( aHeap->Fragmentation() ); |
|
235 hItem = FormatPercentageItem( KItem8a, iOneHundred, iValue ); |
|
236 pItem = hItem->Des(); |
|
237 model->AppendL( pItem ); |
|
238 pItem.Zero(); |
|
239 |
|
240 hItem = FormatItem( KItem13, aHeap->HeaderSizeA() ); |
|
241 pItem = hItem->Des(); |
|
242 model->AppendL( pItem ); |
|
243 pItem.Zero(); |
|
244 |
|
245 hItem = FormatItem( KItem14, aHeap->HeaderSizeF() ); |
|
246 pItem = hItem->Des(); |
|
247 model->AppendL( pItem ); |
|
248 pItem.Zero(); |
|
249 |
|
250 hItem = FormatItem( KItem9a, aHeap->AllocationOverhead() ); |
|
251 pItem = hItem->Des(); |
|
252 model->AppendL( pItem ); |
|
253 pItem.Zero(); |
|
254 |
|
255 hItem = FormatItem( KItem9b, aHeap->FreeOverhead() ); |
|
256 pItem = hItem->Des(); |
|
257 model->AppendL( pItem ); |
|
258 pItem.Zero(); |
|
259 |
|
260 hItem = FormatItem( KItem9c, aHeap->TotalOverhead() ); |
|
261 pItem = hItem->Des(); |
|
262 model->AppendL( pItem ); |
|
263 pItem.Zero(); |
|
264 |
|
265 TReal iOverhead( aHeap->Overhead() ); |
|
266 hItem = FormatPercentageItem( KItem9d, iOneHundred, iOverhead ); |
|
267 pItem = hItem->Des(); |
|
268 model->AppendL( pItem ); |
|
269 pItem.Zero(); |
|
270 |
|
271 hItem = FormatItem( KItem10, aHeap->MinLength() ); |
|
272 pItem = hItem->Des(); |
|
273 model->AppendL( pItem ); |
|
274 pItem.Zero(); |
|
275 |
|
276 hItem = FormatItem( KItem11, aHeap->MaxLength() ); |
|
277 pItem = hItem->Des(); |
|
278 model->AppendL( pItem ); |
|
279 pItem.Zero(); |
|
280 |
|
281 if( aHeap->DebugAllocatorLibrary() ) |
|
282 hItem = FormatItem( KItem12, KMemSpyCaptionYes ); |
|
283 else |
|
284 hItem = FormatItem( KItem12, KMemSpyCaptionNo ); |
|
285 pItem = hItem->Des(); |
|
286 model->AppendL( pItem ); |
|
287 pItem.Zero(); |
|
288 } |
|
289 else |
|
290 { |
|
291 HBufC* hItem = FormatItem( _L("Not Found"), _L("") ); |
|
292 TPtr pItem(hItem->Des()); |
|
293 model->AppendL( pItem ); |
|
294 pItem.Zero(); |
|
295 } |
|
296 |
|
297 return model; |
|
298 } |
|
299 |
|
300 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, const TDesC& aValue ) |
|
301 { |
|
302 HBufC* retBuf = HBufC::NewL( KMaxName ); |
|
303 TPtr pRetBuf( retBuf->Des() ); |
|
304 pRetBuf.Zero(); |
|
305 pRetBuf.Append( _L("\t") ); |
|
306 pRetBuf.Append( aCaption ); |
|
307 pRetBuf.Append( _L("\t\t") ); |
|
308 pRetBuf.Append( aValue ); |
|
309 return retBuf; |
|
310 } |
|
311 |
|
312 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TInt aValue ) |
|
313 { |
|
314 HBufC* retBuf = HBufC::NewL( KMaxName ); |
|
315 TPtr pRetBuf( retBuf->Des() ); |
|
316 pRetBuf.Zero(); |
|
317 |
|
318 TBuf<KMemSpyBufferSize> val; |
|
319 val.Format( KMemSpyDecFormat, aValue ); |
|
320 |
|
321 pRetBuf.Append( _L("\t") ); |
|
322 pRetBuf.Append( aCaption ); |
|
323 pRetBuf.Append( _L("\t\t") ); |
|
324 pRetBuf.Append( val ); |
|
325 |
|
326 return retBuf; |
|
327 } |
|
328 |
|
329 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint aValue ) |
|
330 { |
|
331 HBufC* retBuf = HBufC::NewL( KMaxName ); |
|
332 TPtr pRetBuf( retBuf->Des() ); |
|
333 pRetBuf.Zero(); |
|
334 |
|
335 TBuf<KMemSpyBufferSize> val; |
|
336 //val.Format( KMemSpyDecFormat, aValue ); |
|
337 val.Format( KMemSpyHexFormat, aValue ); |
|
338 |
|
339 pRetBuf.Append( _L("\t") ); |
|
340 pRetBuf.Append( aCaption ); |
|
341 pRetBuf.Append( _L("\t\t") ); |
|
342 pRetBuf.Append( val ); |
|
343 |
|
344 return retBuf; |
|
345 } |
|
346 |
|
347 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, const TInt64& aValue ) |
|
348 { |
|
349 HBufC* retBuf = HBufC::NewL( KMaxName ); |
|
350 TPtr pRetBuf( retBuf->Des() ); |
|
351 pRetBuf.Zero(); |
|
352 |
|
353 TBuf<KMemSpyBufferSize> val; |
|
354 val.Format( KMemSpyLongFormat, aValue ); |
|
355 |
|
356 pRetBuf.Append( _L("\t") ); |
|
357 pRetBuf.Append( aCaption ); |
|
358 pRetBuf.Append( _L("\t\t") ); |
|
359 pRetBuf.Append( val ); |
|
360 |
|
361 return retBuf; |
|
362 } |
|
363 |
|
364 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TAny* aValue ) |
|
365 { |
|
366 HBufC* retBuf = HBufC::NewL( KMaxName ); |
|
367 TPtr pRetBuf( retBuf->Des() ); |
|
368 pRetBuf.Zero(); |
|
369 |
|
370 TBuf<KMemSpyBufferSize> val; |
|
371 val.Format( KMemSpyHexFormat, aValue ); |
|
372 |
|
373 pRetBuf.Append( _L("\t") ); |
|
374 pRetBuf.Append( aCaption ); |
|
375 pRetBuf.Append( _L("\t\t") ); |
|
376 pRetBuf.Append( val ); |
|
377 |
|
378 return retBuf; |
|
379 } |
|
380 |
|
381 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint* aValue ) |
|
382 { |
|
383 HBufC* retBuf = HBufC::NewL( KMaxName ); |
|
384 TPtr pRetBuf( retBuf->Des() ); |
|
385 pRetBuf.Zero(); |
|
386 |
|
387 TBuf<KMemSpyBufferSize> val; |
|
388 val.Format( KMemSpyHexFormat, aValue ); |
|
389 |
|
390 pRetBuf.Append( _L("\t") ); |
|
391 pRetBuf.Append( aCaption ); |
|
392 pRetBuf.Append( _L("\t\t") ); |
|
393 pRetBuf.Append( val ); |
|
394 |
|
395 return retBuf; |
|
396 } |
|
397 |
|
398 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint8* aValue ) |
|
399 { |
|
400 HBufC* retBuf = HBufC::NewL( KMaxName ); |
|
401 TPtr pRetBuf( retBuf->Des() ); |
|
402 pRetBuf.Zero(); |
|
403 |
|
404 TBuf<KMemSpyBufferSize> val; |
|
405 val.Format( KMemSpyHexFormat, aValue ); |
|
406 |
|
407 pRetBuf.Append( _L("\t") ); |
|
408 pRetBuf.Append( aCaption ); |
|
409 pRetBuf.Append( _L("\t\t") ); |
|
410 pRetBuf.Append( val ); |
|
411 |
|
412 return retBuf; |
|
413 } |
|
414 |
|
415 HBufC* CMemSpyViewKernelHeap::FormatPercentageItem( const TDesC& aCaption, TReal aOneHundredPercentValue, TReal aValue ) |
|
416 { |
|
417 HBufC* retBuf = HBufC::NewL( KMaxName ); //buffer for formatted item |
|
418 TPtr pRetBuf( retBuf->Des() ); |
|
419 pRetBuf.Zero(); |
|
420 |
|
421 const TReal value = (TInt) (( aValue / aOneHundredPercentValue) * 100.0); // percentage value calculation |
|
422 _LIT(KPercentFormat, "%3.2f %%"); |
|
423 TMemSpyPercentText val; |
|
424 val.Format( KPercentFormat, value ); |
|
425 |
|
426 pRetBuf.Append( _L("\t") ); |
|
427 pRetBuf.Append( aCaption ); |
|
428 pRetBuf.Append( _L("\t\t") ); |
|
429 pRetBuf.Append( val ); |
|
430 |
|
431 return retBuf; |
|
432 } |
|