20
|
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 <e32def.h>
|
|
19 |
#include <e32cmn.h>
|
|
20 |
#include <arm.h>
|
|
21 |
#include <kernel.h>
|
|
22 |
#include <kern_priv.h>
|
|
23 |
#include <nk_trace.h>
|
|
24 |
|
|
25 |
#include "MemoryEventHandler.h"
|
|
26 |
|
|
27 |
|
62
|
28 |
DMemoryEventHandler::DMemoryEventHandler(DProfilerSampleBuffer* aSampleBuffer, TProfilerGppSamplerData* aGppSamplerDataIn)
|
20
|
29 |
: DKernelEventHandler(EventHandler, this),
|
|
30 |
iSampleBuffer(aSampleBuffer),
|
62
|
31 |
iSampleDescriptor(&(this->iSample[1]),0,256),
|
|
32 |
gppSamplerData(aGppSamplerDataIn)
|
20
|
33 |
{
|
|
34 |
iPreviousCount = 0;
|
62
|
35 |
iSampleAvailable = false;
|
20
|
36 |
}
|
|
37 |
|
|
38 |
|
|
39 |
TInt DMemoryEventHandler::Create()
|
|
40 |
{
|
62
|
41 |
TInt err(Kern::MutexCreate(iLock, _L("MemoryEventHandlerLock"), KMutexOrdResourceManager));
|
20
|
42 |
if (err != KErrNone)
|
|
43 |
return err;
|
|
44 |
|
|
45 |
return Add();
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
DMemoryEventHandler::~DMemoryEventHandler()
|
|
50 |
{
|
|
51 |
if (iLock)
|
|
52 |
iLock->Close(NULL);
|
|
53 |
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
TInt DMemoryEventHandler::Start()
|
|
58 |
{
|
|
59 |
iTracking = ETrue;
|
|
60 |
return KErrNone;
|
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
TInt DMemoryEventHandler::Stop()
|
|
65 |
{
|
|
66 |
iTracking = EFalse;
|
|
67 |
return KErrNone;
|
|
68 |
}
|
|
69 |
|
|
70 |
TBool DMemoryEventHandler::SampleNeeded()
|
|
71 |
{
|
|
72 |
LOGTEXT("DMemoryEventHandler::SampleNeeded()");
|
|
73 |
|
|
74 |
// check if event handler was not running
|
62
|
75 |
if(!iTracking)
|
|
76 |
return false; // return false
|
|
77 |
// check if a new sample is available
|
|
78 |
if(iSampleAvailable)
|
|
79 |
{
|
|
80 |
return true;
|
|
81 |
}
|
|
82 |
else
|
|
83 |
{
|
|
84 |
return false;
|
|
85 |
}
|
|
86 |
}
|
|
87 |
void DMemoryEventHandler::SampleHandled()
|
|
88 |
{
|
|
89 |
iSampleAvailable = false;
|
20
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
TUint DMemoryEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis)
|
|
94 |
{
|
|
95 |
return ((DMemoryEventHandler*)aThis)->HandleEvent(aType, a1, a2);
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
TUint DMemoryEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
|
|
101 |
{
|
|
102 |
// debug
|
62
|
103 |
// Kern::Printf("New kernel event received, %d", aType);
|
20
|
104 |
|
62
|
105 |
if (iTracking)
|
20
|
106 |
{
|
|
107 |
iCounters[aType]++;
|
|
108 |
switch (aType)
|
|
109 |
{
|
|
110 |
// capture only chunk creation, updates and destroyal
|
|
111 |
case EEventNewChunk:
|
|
112 |
{
|
|
113 |
DChunk* chunk = (DChunk*)a1;
|
|
114 |
HandleAddChunk(chunk);
|
|
115 |
break;
|
|
116 |
}
|
|
117 |
case EEventUpdateChunk:
|
|
118 |
HandleUpdateChunk((DChunk*)a1);
|
|
119 |
break;
|
|
120 |
case EEventDeleteChunk:
|
|
121 |
HandleDeleteChunk((DChunk*)a1);
|
|
122 |
break;
|
|
123 |
// case EEventAddProcess:
|
|
124 |
// Kern::Printf("Process added: 0x%08x", (DProcess*)a1);
|
|
125 |
// break;
|
|
126 |
// case EEventUpdateProcess:
|
|
127 |
// Kern::Printf("DProcess updated: 0x%08x", (DProcess*)a1);
|
|
128 |
// break;
|
|
129 |
// case EEventRemoveProcess:
|
|
130 |
// Kern::Printf("DProcess removed: 0x%08x", (DProcess*)a1);
|
|
131 |
// break;
|
|
132 |
// case EEventAddCodeSeg:
|
|
133 |
// Kern::Printf("DCodeSeg added: 0x%08x", (DCodeSeg*)a1);
|
|
134 |
// break;
|
|
135 |
// case EEventRemoveCodeSeg:
|
|
136 |
// Kern::Printf("DCodeSeg deleted: 0x%08x", (DCodeSeg*)a1);
|
|
137 |
// break;
|
|
138 |
case EEventAddThread:
|
|
139 |
HandleAddThread((DThread*)a1);
|
|
140 |
break;
|
|
141 |
case EEventUpdateThread: // thread renaming
|
|
142 |
HandleUpdateThread((DThread*)a1);
|
|
143 |
break;
|
|
144 |
// case EEventKillThread:
|
|
145 |
case EEventRemoveThread:
|
|
146 |
HandleDeleteThread((DThread*)a1);
|
|
147 |
break;
|
|
148 |
#ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS
|
|
149 |
case EEventAddLibrary:
|
|
150 |
HandleAddLibrary((DLibrary*)a1, (DThread*)a2);
|
|
151 |
break;
|
|
152 |
case EEventRemoveLibrary:
|
|
153 |
HandleDeleteLibrary((DLibrary*)a1);
|
|
154 |
break;
|
|
155 |
#endif
|
|
156 |
|
|
157 |
// ignore exception events
|
|
158 |
case EEventSwExc:
|
|
159 |
case EEventHwExc:
|
|
160 |
|
|
161 |
default:
|
|
162 |
break;
|
|
163 |
}
|
|
164 |
}
|
|
165 |
return DKernelEventHandler::ERunNext;
|
|
166 |
}
|
|
167 |
|
|
168 |
TInt DMemoryEventHandler::EncodeNameCode()
|
|
169 |
{
|
|
170 |
iSample[0] = 1;
|
|
171 |
iSample[1] = 0xaa;
|
|
172 |
return 2;
|
|
173 |
}
|
|
174 |
|
|
175 |
// encode mark for new chunk or thread
|
|
176 |
TInt DMemoryEventHandler::EncodeNewCode()
|
|
177 |
{
|
|
178 |
iSample[0] = 1;
|
|
179 |
iSample[1] = 0xda;
|
|
180 |
return 2;
|
|
181 |
}
|
|
182 |
|
|
183 |
// encode mark for update of chunk or thread
|
|
184 |
TInt DMemoryEventHandler::EncodeUpdateCode()
|
|
185 |
{
|
|
186 |
iSample[0] = 1;
|
|
187 |
iSample[1] = 0xdb;
|
|
188 |
return 2;
|
|
189 |
}
|
|
190 |
|
|
191 |
// encode mark for removal of chunk or thread
|
|
192 |
TInt DMemoryEventHandler::EncodeRemoveCode()
|
|
193 |
{
|
|
194 |
iSample[0] = 1;
|
|
195 |
iSample[1] = 0xdc;
|
|
196 |
return 2;
|
|
197 |
}
|
|
198 |
|
|
199 |
// encode the memory sample header in all memory changes
|
|
200 |
TInt DMemoryEventHandler::AddHeader()
|
|
201 |
{
|
|
202 |
TInt err(KErrNone);
|
|
203 |
|
|
204 |
TUint8 number(4); // mem sampler id
|
62
|
205 |
TUint32 sampleNum= this->gppSamplerData->sampleNumber;
|
20
|
206 |
// check if iCount bigger than previous, i.e. at least 1 ms has passed from the previous sample
|
62
|
207 |
if(sampleNum > iPreviousCount)
|
20
|
208 |
{
|
|
209 |
err = this->iSampleBuffer->AddSample(&number,1);
|
62
|
210 |
err = this->iSampleBuffer->AddSample((TUint8*)&(sampleNum),4);
|
20
|
211 |
|
|
212 |
// add data chunk header
|
|
213 |
TInt length(EncodeUpdateCode());
|
|
214 |
err = iSampleBuffer->AddSample(iSample, length);
|
|
215 |
|
|
216 |
// add total memory sample in the beginning of each sample
|
|
217 |
length = EncodeTotalMemory();
|
|
218 |
err = iSampleBuffer->AddSample(iSample, length);
|
|
219 |
AddFooter(); // end mark for total memory sample
|
|
220 |
}
|
62
|
221 |
iPreviousCount = sampleNum;
|
20
|
222 |
|
|
223 |
// add actual sample
|
|
224 |
err = this->iSampleBuffer->AddSample(&number,1);
|
62
|
225 |
err = this->iSampleBuffer->AddSample((TUint8*)&(sampleNum),4);
|
|
226 |
LOGSTRING2("handler timestamp : 0x%04x", sampleNum);
|
20
|
227 |
|
|
228 |
return err;
|
|
229 |
}
|
|
230 |
|
|
231 |
// encode the memory sample header in all memory changes
|
|
232 |
TInt DMemoryEventHandler::AddFooter()
|
|
233 |
{
|
|
234 |
TInt err(KErrNone);
|
|
235 |
|
|
236 |
TUint8 number(0); // end mark
|
|
237 |
err = this->iSampleBuffer->AddSample(&number,1);
|
|
238 |
|
|
239 |
return err;
|
|
240 |
}
|
|
241 |
|
|
242 |
TInt DMemoryEventHandler::EncodeTotalMemory()
|
|
243 |
{
|
|
244 |
|
|
245 |
TUint8* size(&iSample[0]);
|
|
246 |
*size = 0;
|
|
247 |
|
|
248 |
NKern::LockSystem();
|
|
249 |
TInt freeRam(Kern::FreeRamInBytes());
|
|
250 |
TInt totalRam(Kern::SuperPage().iTotalRamSize);
|
|
251 |
NKern::UnlockSystem();
|
|
252 |
|
|
253 |
iSampleDescriptor.Zero();
|
|
254 |
|
|
255 |
TUint32 id(0xbabbeaaa);
|
|
256 |
TInt zero(0);
|
|
257 |
|
|
258 |
iSampleDescriptor.Append((TUint8*)&(id),sizeof(TUint32));
|
|
259 |
*size += sizeof(TUint);
|
|
260 |
|
|
261 |
iSampleDescriptor.Append((TUint8*)&(totalRam),sizeof(TInt));
|
|
262 |
*size += sizeof(TInt);
|
|
263 |
|
|
264 |
// append the cell amount allocated
|
|
265 |
iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
|
|
266 |
*size += sizeof(TInt);
|
|
267 |
|
|
268 |
// append the chunk size
|
|
269 |
iSampleDescriptor.Append((TUint8*)&(freeRam),sizeof(TInt));
|
|
270 |
*size += sizeof(TInt);
|
|
271 |
|
|
272 |
// append the thread user stack size
|
|
273 |
iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
|
|
274 |
*size += sizeof(TInt);
|
|
275 |
|
|
276 |
return ((TInt)(*size))+1;
|
|
277 |
}
|
|
278 |
|
|
279 |
// handle chunk activity
|
|
280 |
TBool DMemoryEventHandler::HandleAddChunk(DChunk* aChunk)
|
|
281 |
{
|
|
282 |
NKern::ThreadEnterCS();
|
|
283 |
Kern::MutexWait(*iLock);
|
|
284 |
// add header first
|
|
285 |
TInt err(AddHeader());
|
|
286 |
|
|
287 |
if(err != KErrNone)
|
|
288 |
{
|
62
|
289 |
Kern::MutexSignal(*iLock);
|
|
290 |
NKern::ThreadLeaveCS();
|
20
|
291 |
return EFalse;
|
|
292 |
}
|
|
293 |
|
|
294 |
// new chunk, add name of it
|
|
295 |
TInt length(EncodeNameCode());
|
|
296 |
iSampleBuffer->AddSample(iSample, length);
|
|
297 |
|
|
298 |
// new chunk, add name of it
|
|
299 |
length = EncodeChunkName(*aChunk);
|
|
300 |
iSampleBuffer->AddSample(iSample, length);
|
|
301 |
|
|
302 |
// add new chunk tag
|
|
303 |
length = EncodeNewCode();
|
|
304 |
iSampleBuffer->AddSample(iSample, length);
|
|
305 |
|
|
306 |
length = EncodeChunkData(*aChunk);
|
|
307 |
iSampleBuffer->AddSample(iSample, length);
|
|
308 |
|
|
309 |
// add end mark
|
|
310 |
AddFooter();
|
|
311 |
Kern::MutexSignal(*iLock);
|
|
312 |
NKern::ThreadLeaveCS();
|
|
313 |
return ETrue;
|
|
314 |
}
|
|
315 |
|
|
316 |
TBool DMemoryEventHandler::HandleUpdateChunk(DChunk* aChunk)
|
|
317 |
{
|
|
318 |
NKern::ThreadEnterCS();
|
|
319 |
Kern::MutexWait(*iLock);
|
|
320 |
// add header first
|
|
321 |
TInt err(AddHeader());
|
|
322 |
|
|
323 |
if(err != KErrNone)
|
|
324 |
{
|
62
|
325 |
Kern::Printf("DChunk update error: %d", err);
|
|
326 |
Kern::MutexSignal(*iLock);
|
|
327 |
NKern::ThreadLeaveCS();
|
20
|
328 |
return EFalse;
|
|
329 |
}
|
|
330 |
|
|
331 |
// add new chunk tag
|
|
332 |
TInt length(EncodeUpdateCode());
|
|
333 |
iSampleBuffer->AddSample(iSample, length);
|
|
334 |
|
|
335 |
length = EncodeChunkData(*aChunk);
|
|
336 |
iSampleBuffer->AddSample(iSample, length);
|
|
337 |
|
|
338 |
// add end mark
|
|
339 |
AddFooter();
|
|
340 |
Kern::MutexSignal(*iLock);
|
|
341 |
NKern::ThreadLeaveCS();
|
|
342 |
return ETrue;
|
|
343 |
}
|
|
344 |
|
|
345 |
TBool DMemoryEventHandler::HandleDeleteChunk(DChunk* aChunk)
|
|
346 |
{
|
|
347 |
NKern::ThreadEnterCS();
|
|
348 |
Kern::MutexWait(*iLock);
|
|
349 |
// add header first
|
|
350 |
TInt err(AddHeader());
|
|
351 |
|
|
352 |
if(err != KErrNone)
|
|
353 |
{
|
62
|
354 |
Kern::MutexSignal(*iLock);
|
|
355 |
NKern::ThreadLeaveCS();
|
20
|
356 |
return EFalse;
|
|
357 |
}
|
|
358 |
|
|
359 |
// add new chunk tag
|
|
360 |
TInt length(EncodeRemoveCode());
|
|
361 |
iSampleBuffer->AddSample(iSample, length);
|
|
362 |
|
|
363 |
length = EncodeChunkData(*aChunk);
|
|
364 |
iSampleBuffer->AddSample(iSample, length);
|
|
365 |
|
|
366 |
// add end mark
|
|
367 |
AddFooter();
|
|
368 |
Kern::MutexSignal(*iLock);
|
|
369 |
NKern::ThreadLeaveCS();
|
|
370 |
return ETrue;
|
|
371 |
}
|
|
372 |
|
|
373 |
// handle process activity
|
|
374 |
TBool DMemoryEventHandler::HandleAddProcess(DProcess *aProcess)
|
|
375 |
{
|
|
376 |
return ETrue;
|
|
377 |
}
|
|
378 |
|
|
379 |
TBool DMemoryEventHandler::HandleUpdateProcess(DProcess *aProcess)
|
|
380 |
{
|
|
381 |
return ETrue;
|
|
382 |
}
|
|
383 |
|
|
384 |
TBool DMemoryEventHandler::HandleDeleteProcess(DProcess *aProcess)
|
|
385 |
{
|
|
386 |
return ETrue;
|
|
387 |
}
|
|
388 |
|
|
389 |
// handle thread activity
|
|
390 |
TBool DMemoryEventHandler::HandleAddThread(DThread* aThread)
|
|
391 |
{
|
|
392 |
NKern::ThreadEnterCS();
|
|
393 |
Kern::MutexWait(*iLock);
|
|
394 |
// add header first
|
|
395 |
TInt err(AddHeader());
|
|
396 |
|
|
397 |
if(err != KErrNone)
|
|
398 |
{
|
62
|
399 |
Kern::MutexSignal(*iLock);
|
|
400 |
NKern::ThreadLeaveCS();
|
20
|
401 |
return EFalse;
|
|
402 |
}
|
|
403 |
|
|
404 |
// new thread, add name of it
|
|
405 |
TInt length(EncodeNameCode());
|
|
406 |
iSampleBuffer->AddSample(iSample, length);
|
|
407 |
|
|
408 |
// new chunk, add name of it
|
|
409 |
length = EncodeChunkName(*aThread);
|
|
410 |
iSampleBuffer->AddSample(iSample, length);
|
|
411 |
|
|
412 |
// add new chunk tag
|
|
413 |
length = EncodeNewCode();
|
|
414 |
iSampleBuffer->AddSample(iSample, length);
|
|
415 |
|
|
416 |
length = EncodeChunkData(*aThread);
|
|
417 |
iSampleBuffer->AddSample(iSample, length);
|
|
418 |
|
|
419 |
// add end mark
|
|
420 |
AddFooter();
|
|
421 |
Kern::MutexSignal(*iLock);
|
|
422 |
NKern::ThreadLeaveCS();
|
|
423 |
return ETrue;
|
|
424 |
}
|
|
425 |
|
|
426 |
TBool DMemoryEventHandler::HandleUpdateThread(DThread* aThread)
|
|
427 |
{
|
|
428 |
NKern::ThreadEnterCS();
|
|
429 |
Kern::MutexWait(*iLock);
|
|
430 |
// add header first
|
|
431 |
TInt err(AddHeader());
|
|
432 |
|
|
433 |
if(err != KErrNone)
|
|
434 |
{
|
62
|
435 |
Kern::MutexSignal(*iLock);
|
|
436 |
NKern::ThreadLeaveCS();
|
20
|
437 |
return EFalse;
|
|
438 |
}
|
|
439 |
|
|
440 |
// add new chunk tag
|
|
441 |
TInt length(EncodeUpdateCode());
|
|
442 |
iSampleBuffer->AddSample(iSample, length);
|
|
443 |
|
|
444 |
length = EncodeChunkData(*aThread);
|
|
445 |
iSampleBuffer->AddSample(iSample, length);
|
|
446 |
|
|
447 |
// add end mark
|
|
448 |
AddFooter();
|
|
449 |
Kern::MutexSignal(*iLock);
|
|
450 |
NKern::ThreadLeaveCS();
|
|
451 |
return ETrue;
|
|
452 |
}
|
|
453 |
|
|
454 |
TBool DMemoryEventHandler::HandleDeleteThread(DThread* aThread)
|
|
455 |
{
|
|
456 |
NKern::ThreadEnterCS();
|
|
457 |
Kern::MutexWait(*iLock);
|
|
458 |
// add header first
|
|
459 |
TInt err(AddHeader());
|
|
460 |
|
|
461 |
if(err != KErrNone)
|
|
462 |
{
|
62
|
463 |
Kern::MutexSignal(*iLock);
|
|
464 |
NKern::ThreadLeaveCS();
|
20
|
465 |
return EFalse;
|
|
466 |
}
|
|
467 |
|
|
468 |
// add new chunk tag
|
|
469 |
TInt length(EncodeRemoveCode());
|
|
470 |
iSampleBuffer->AddSample(iSample, length);
|
|
471 |
|
|
472 |
length = EncodeChunkData(*aThread);
|
|
473 |
iSampleBuffer->AddSample(iSample, length);
|
|
474 |
|
|
475 |
// add end mark
|
|
476 |
AddFooter();
|
|
477 |
Kern::MutexSignal(*iLock);
|
|
478 |
NKern::ThreadLeaveCS();
|
|
479 |
return ETrue;
|
|
480 |
}
|
|
481 |
|
|
482 |
TBool DMemoryEventHandler::HandleAddLibrary(DLibrary* aLibrary, DThread* aThread)
|
|
483 |
{
|
|
484 |
LOGTEXT("DMemoryEventHandler::HandleAddLibrary");
|
|
485 |
// add header first
|
|
486 |
NKern::ThreadEnterCS();
|
|
487 |
Kern::MutexWait(*iLock);
|
|
488 |
TInt err(AddHeader());
|
|
489 |
|
|
490 |
if(err != KErrNone)
|
|
491 |
{
|
62
|
492 |
Kern::MutexSignal(*iLock);
|
|
493 |
NKern::ThreadLeaveCS();
|
20
|
494 |
return EFalse;
|
|
495 |
}
|
|
496 |
|
|
497 |
// new library, add name of it
|
|
498 |
TInt length(EncodeNameCode());
|
|
499 |
iSampleBuffer->AddSample(iSample, length);
|
|
500 |
|
|
501 |
// new chunk, add name of it
|
|
502 |
length = EncodeChunkName(*aLibrary);
|
|
503 |
iSampleBuffer->AddSample(iSample, length);
|
|
504 |
|
|
505 |
// add new chunk tag
|
|
506 |
length = EncodeNewCode();
|
|
507 |
iSampleBuffer->AddSample(iSample, length);
|
|
508 |
|
|
509 |
length = EncodeChunkData(*aLibrary, *aThread);
|
|
510 |
iSampleBuffer->AddSample(iSample, length);
|
|
511 |
|
|
512 |
// add end mark
|
|
513 |
AddFooter();
|
|
514 |
Kern::MutexSignal(*iLock);
|
|
515 |
NKern::ThreadLeaveCS();
|
|
516 |
return ETrue;
|
|
517 |
}
|
|
518 |
|
|
519 |
TBool DMemoryEventHandler::HandleDeleteLibrary(DLibrary* aLibrary)
|
|
520 |
{
|
62
|
521 |
LOGTEXT("DMemoryEventHandler::HandleDeleteLibrary");
|
20
|
522 |
NKern::ThreadEnterCS();
|
|
523 |
Kern::MutexWait(*iLock);
|
|
524 |
// add header first
|
|
525 |
TInt err(AddHeader());
|
|
526 |
|
|
527 |
if(err != KErrNone)
|
|
528 |
{
|
62
|
529 |
Kern::MutexSignal(*iLock);
|
|
530 |
NKern::ThreadLeaveCS();
|
20
|
531 |
return EFalse;
|
|
532 |
}
|
|
533 |
|
|
534 |
// add new chunk tag
|
|
535 |
TInt length(EncodeRemoveCode());
|
|
536 |
iSampleBuffer->AddSample(iSample, length);
|
|
537 |
|
|
538 |
DThread* nullPointer = NULL;
|
|
539 |
length = EncodeChunkData(*aLibrary, *nullPointer);
|
|
540 |
iSampleBuffer->AddSample(iSample, length);
|
|
541 |
|
|
542 |
// add end mark
|
|
543 |
AddFooter();
|
|
544 |
Kern::MutexSignal(*iLock);
|
|
545 |
NKern::ThreadLeaveCS();
|
|
546 |
return ETrue;
|
|
547 |
}
|
|
548 |
|
|
549 |
// encode chunk name
|
|
550 |
TInt DMemoryEventHandler::EncodeChunkName(DChunk& c)
|
|
551 |
{
|
|
552 |
// the size of the following name is in the first byte
|
|
553 |
TUint8* size(&iSample[0]);
|
|
554 |
*size = 0;
|
|
555 |
|
|
556 |
// encode chunk name
|
|
557 |
iSampleDescriptor.Zero();
|
|
558 |
iSampleDescriptor.Append(_L("C_"));
|
|
559 |
c.TraceAppendFullName(iSampleDescriptor,false);
|
|
560 |
*size += iSampleDescriptor.Size();
|
|
561 |
|
|
562 |
// add chunk object address here
|
|
563 |
TUint32 chunkAddr((TUint32)&c);
|
|
564 |
iSampleDescriptor.Append((TUint8*)&(chunkAddr),sizeof(TUint32));
|
|
565 |
*size += sizeof(TUint32);
|
|
566 |
|
|
567 |
// the size is the descriptor length + the size field
|
|
568 |
LOGSTRING2("Non-Heap Chunk Name - %d",*size);
|
|
569 |
return ((TInt)(*size))+1;
|
|
570 |
}
|
|
571 |
|
|
572 |
// encode chunk name
|
|
573 |
TInt DMemoryEventHandler::EncodeChunkName(DThread& t)
|
|
574 |
{
|
|
575 |
// the size of the following name is in the first byte
|
|
576 |
TUint8* size(&iSample[0]);
|
|
577 |
*size = 0;
|
|
578 |
iSampleDescriptor.Zero();
|
|
579 |
|
|
580 |
iSampleDescriptor.Append(_L("T_"));
|
|
581 |
t.TraceAppendFullName(iSampleDescriptor,false);
|
|
582 |
*size += iSampleDescriptor.Size();
|
|
583 |
|
|
584 |
// copy the 4 bytes from the thread id field
|
|
585 |
iSampleDescriptor.Append((TUint8*)&(t.iId),sizeof(TUint));
|
|
586 |
*size += sizeof(TUint);
|
|
587 |
|
|
588 |
// the size is the descriptor length + the size field
|
|
589 |
LOGSTRING2("Name - %d",*size);
|
|
590 |
return ((TInt)(*size))+1;
|
|
591 |
}
|
|
592 |
|
|
593 |
// encode chunk name
|
|
594 |
TInt DMemoryEventHandler::EncodeChunkName(DLibrary& l)
|
|
595 |
{
|
|
596 |
LOGTEXT("DMemoryEventHandler::EncodeChunkName (LIBRARY)");
|
|
597 |
// the size of the following name is in the first byte
|
|
598 |
TUint8* size(&iSample[0]);
|
|
599 |
*size = 0;
|
|
600 |
iSampleDescriptor.Zero();
|
|
601 |
|
|
602 |
iSampleDescriptor.Append(_L("L_"));
|
|
603 |
l.TraceAppendFullName(iSampleDescriptor,false);
|
|
604 |
*size += iSampleDescriptor.Size();
|
|
605 |
|
|
606 |
// copy the library address here
|
|
607 |
TUint32 libAddr((TUint32)&l);
|
|
608 |
iSampleDescriptor.Append((TUint8*) &libAddr,sizeof(TUint32));
|
|
609 |
*size += sizeof(TUint32);
|
|
610 |
|
|
611 |
// the size is the descriptor length + the size field
|
|
612 |
LOGSTRING2("Name - %d",*size);
|
|
613 |
return ((TInt)(*size))+1;
|
|
614 |
}
|
|
615 |
|
|
616 |
// record thread stack changes
|
|
617 |
TInt DMemoryEventHandler::EncodeChunkData(DThread& t)
|
|
618 |
{
|
|
619 |
LOGSTRING("DMemoryEventHandler::EncodeChunkDataT - entry");
|
|
620 |
|
|
621 |
// the size of the following name is in the first byte
|
|
622 |
TUint8* size(&iSample[0]);
|
|
623 |
*size = 0;
|
|
624 |
iSampleDescriptor.Zero();
|
|
625 |
|
|
626 |
iSampleDescriptor.Append((TUint8*)&(t.iId),sizeof(TUint));
|
|
627 |
*size += sizeof(TUint);
|
|
628 |
|
|
629 |
// copy the total amount of memory allocated for user side stack
|
|
630 |
iSampleDescriptor.Append((TUint8*)&(t.iUserStackSize),sizeof(TInt));
|
|
631 |
*size += sizeof(TInt);
|
|
632 |
|
|
633 |
TInt zero(0);
|
|
634 |
// append the cell amount allocated (zero, not in use here)
|
|
635 |
iSampleDescriptor.Append((TUint8*)&zero,sizeof(TInt));
|
|
636 |
*size += sizeof(TInt);
|
|
637 |
|
|
638 |
// append the chunk size (this is not a chunk)
|
|
639 |
iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TUint));
|
|
640 |
*size += sizeof(TUint);
|
|
641 |
|
|
642 |
// append user stack (max) size
|
|
643 |
iSampleDescriptor.Append((TUint8*)&(t.iUserStackSize),sizeof(TInt));
|
|
644 |
*size += sizeof(TInt);
|
|
645 |
|
62
|
646 |
LOGSTRING2("TData -> %d",*size);
|
20
|
647 |
return ((TInt)(*size))+1;
|
|
648 |
}
|
|
649 |
|
|
650 |
// record chunk changes
|
|
651 |
TInt DMemoryEventHandler::EncodeChunkData(DChunk& c)
|
|
652 |
{
|
|
653 |
LOGSTRING("DMemoryEventHandler::EncodeChunkDataC - entry");
|
|
654 |
|
|
655 |
// the size of the following name is in the first byte
|
|
656 |
TUint8* size(&iSample[0]);
|
|
657 |
*size = 0;
|
|
658 |
iSampleDescriptor.Zero();
|
|
659 |
TInt zero(0);
|
|
660 |
|
|
661 |
TUint32 address((TUint32)&c);
|
62
|
662 |
LOGSTRING2("DMemoryEventHandler::EncodeChunkDataC - address 0x%x", *&address);
|
20
|
663 |
iSampleDescriptor.Append((TUint8*)&address,sizeof(TUint32));
|
|
664 |
*size += sizeof(TUint);
|
|
665 |
|
|
666 |
// copy the total amount of memory allocated
|
|
667 |
iSampleDescriptor.Append((TUint8*)&(c.iSize),sizeof(TInt));
|
|
668 |
*size += sizeof(TInt);
|
|
669 |
|
|
670 |
// append the cell amount allocated
|
|
671 |
iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
|
|
672 |
*size += sizeof(TInt);
|
|
673 |
|
|
674 |
// append the chunk size
|
|
675 |
iSampleDescriptor.Append((TUint8*)&(c.iSize),sizeof(TUint));
|
|
676 |
*size += sizeof(TUint);
|
|
677 |
|
|
678 |
// append the thread user stack size
|
|
679 |
iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
|
|
680 |
*size += sizeof(TInt);
|
|
681 |
|
62
|
682 |
LOGSTRING2("CData - %d",*size);
|
20
|
683 |
return ((TInt)(*size))+1;
|
|
684 |
}
|
|
685 |
|
|
686 |
// record loaded libraries changes
|
|
687 |
TInt DMemoryEventHandler::EncodeChunkData(DLibrary& l, DThread& t)
|
|
688 |
{
|
|
689 |
LOGSTRING("DMemoryEventHandler::EncodeChunkDataL - entry");
|
|
690 |
|
|
691 |
// the size of the following name is in the first byte
|
|
692 |
TUint8* size(&iSample[0]);
|
|
693 |
*size = 0;
|
|
694 |
iSampleDescriptor.Zero();
|
|
695 |
TInt zero(0);
|
|
696 |
|
|
697 |
TUint32 address((TUint32)&l);
|
|
698 |
|
|
699 |
iSampleDescriptor.Append((TUint8*)&address,sizeof(TUint32));
|
|
700 |
*size += sizeof(TUint);
|
|
701 |
|
|
702 |
// append amount of memory that library is allocated
|
|
703 |
iSampleDescriptor.Append((TUint8*)&(l.iCodeSeg->iSize),sizeof(TUint32));
|
|
704 |
*size += sizeof(TInt);
|
|
705 |
|
|
706 |
// append count of how many times librarys is allocated
|
|
707 |
iSampleDescriptor.Append((TUint8*)&(l.iMapCount),sizeof(TInt));
|
|
708 |
*size += sizeof(TInt);
|
|
709 |
|
|
710 |
if(&t != NULL)
|
|
711 |
{
|
|
712 |
// created by thread
|
|
713 |
iSampleDescriptor.Append((TUint8*)&(t),sizeof(TUint32));
|
|
714 |
}
|
|
715 |
else
|
|
716 |
{
|
|
717 |
// removed
|
|
718 |
iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TUint32));
|
|
719 |
}
|
|
720 |
*size += sizeof(TUint);
|
|
721 |
|
|
722 |
// append the thread user stack size
|
|
723 |
iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
|
|
724 |
*size += sizeof(TInt);
|
|
725 |
return ((TInt)(*size))+1;
|
|
726 |
}
|
|
727 |
|