102 TInt EncodeNameCode(); |
103 TInt EncodeNameCode(); |
103 TInt EncodeDataCode(); |
104 TInt EncodeDataCode(); |
104 |
105 |
105 DChunk* heapChunksToSample[KProfilerMaxChunksAmount]; |
106 DChunk* heapChunksToSample[KProfilerMaxChunksAmount]; |
106 DChunk* heapChunkNamesToReport[KProfilerMaxChunksAmount]; |
107 DChunk* heapChunkNamesToReport[KProfilerMaxChunksAmount]; |
107 TInt iCount; |
108 TUint32 iCount; |
108 TInt iChunkCount; |
109 TInt iChunkCount; |
109 TInt iNewChunkCount; |
110 TInt iNewChunkCount; |
110 TBuf8<0x50> name; |
111 TBuf8<0x50> name; |
111 DThread* threadsToSample[KProfilerMaxThreadsAmount]; |
112 DThread* threadsToSample[KProfilerMaxThreadsAmount]; |
112 DThread* threadNamesToReport[KProfilerMaxThreadsAmount]; |
113 DThread* threadNamesToReport[KProfilerMaxThreadsAmount]; |
113 TInt iThreadCount; |
114 TInt iThreadCount; |
114 TInt iNewThreadCount; |
115 TInt iNewThreadCount; |
|
116 |
|
117 TInt iHandledThreads; |
|
118 TInt iHandledChunks; |
|
119 TInt iHandledLibs; |
|
120 |
115 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
121 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
116 DLibrary* librariesToSample[KProfilerMaxLibrariesAmount]; |
122 DLibrary* librariesToSample[KProfilerMaxLibrariesAmount]; |
117 DLibrary* libraryNamesToReport[KProfilerMaxLibrariesAmount]; |
123 DLibrary* libraryNamesToReport[KProfilerMaxLibrariesAmount]; |
118 TInt iLibraryCount; |
124 TInt iLibraryCount; |
119 TInt iNewLibraryCount; |
125 TInt iNewLibraryCount; |
121 #endif |
127 #endif |
122 |
128 |
123 TInt iChunksProcessing; |
129 TInt iChunksProcessing; |
124 TInt iThreadsProcessing; |
130 TInt iThreadsProcessing; |
125 TInt iMemSamplingPeriod; |
131 TInt iMemSamplingPeriod; |
126 TInt iMemSamplingPeriodDiv2; |
132 //TInt iMemSamplingPeriodDiv2; |
127 TInt iMemSamplingPeriodDiv3; |
133 //TInt iMemSamplingPeriodDiv3; |
128 |
134 |
129 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
135 |
130 ESampleType iSampleType; |
136 ESampleType iSampleType; |
131 #else |
137 |
132 TBool iSampleThreads; |
|
133 #endif |
|
134 |
|
135 TBool iTimeToSample; |
138 TBool iTimeToSample; |
136 |
|
137 TBool iTotalMemoryOk; |
139 TBool iTotalMemoryOk; |
138 TBool iTotalMemoryNameOk; |
140 TBool iTotalMemoryNameOk; |
139 |
141 |
140 TUint8 sample[KSampleBufferSize]; |
142 TUint8 sample[KSampleBufferSize]; |
141 TPtr8 sampleDescriptor; |
143 TPtr8 sampleDescriptor; |
142 |
144 TInt iThreadsHandled; |
143 // test |
145 TInt iChunksHandled; |
144 #ifdef MEM_EVENT_HANDLER |
146 #ifdef MEM_EVENT_HANDLER |
145 // DMemoryEventHandler* iEventHandler; |
|
146 TBool iChunksGathered; |
147 TBool iChunksGathered; |
147 TBool iThreadsGathered; |
148 TBool iThreadsGathered; |
148 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
149 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
149 TBool iLibrariesGathered; |
150 TBool iLibrariesGathered; |
150 #endif |
151 #endif |
183 DProfilerMemSampler<BufferSize>::DProfilerMemSampler(struct TProfilerGppSamplerData* gppSamplerDataIn, TInt id) : |
185 DProfilerMemSampler<BufferSize>::DProfilerMemSampler(struct TProfilerGppSamplerData* gppSamplerDataIn, TInt id) : |
184 DProfilerGenericSampler<BufferSize>(PROFILER_MEM_SAMPLER_ID) |
186 DProfilerGenericSampler<BufferSize>(PROFILER_MEM_SAMPLER_ID) |
185 { |
187 { |
186 LOGSTRING2("DProfilerMemSampler<%d>::CProfilerMemSampler",BufferSize); |
188 LOGSTRING2("DProfilerMemSampler<%d>::CProfilerMemSampler",BufferSize); |
187 this->gppSamplerData = gppSamplerDataIn; |
189 this->gppSamplerData = gppSamplerDataIn; |
|
190 #ifndef MEM_EVENT_HANDLER |
188 this->iSamplingPeriod = 3000; // set default setting |
191 this->iSamplingPeriod = 3000; // set default setting |
|
192 #endif |
|
193 iSyncOffset = 0; |
189 } |
194 } |
190 |
195 |
191 template <int BufferSize> |
196 template <int BufferSize> |
192 TInt DProfilerMemSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset) |
197 TInt DProfilerMemSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset) |
193 { |
198 { |
194 //#ifdef MEM_EVENT_HANDLER |
199 iSyncOffset = aSyncOffset; |
195 // Kern::Printf("DProfilerMemSampler<%d>::Reset - calling superclass reset",BufferSize); |
|
196 |
|
197 //#endif |
|
198 // check if reset called in stop (by driver) |
200 // check if reset called in stop (by driver) |
199 if(aSyncOffset != 999999) |
201 if(iSyncOffset != KStateSamplingEnding) |
200 { |
202 { |
201 DProfilerGenericSampler<BufferSize>::Reset(aStream); |
203 DProfilerGenericSampler<BufferSize>::Reset(aStream); |
202 memSamplerImpl.Reset(); |
204 memSamplerImpl.Reset(); |
203 |
205 |
204 #ifdef MEM_EVENT_HANDLER |
206 #ifdef MEM_EVENT_HANDLER |
237 return KErrGeneral; |
237 return KErrGeneral; |
238 } |
238 } |
239 |
239 |
240 // set first chunk&thread memory lookup at the 5 ms, should be enough |
240 // set first chunk&thread memory lookup at the 5 ms, should be enough |
241 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
241 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
242 this->memSamplerImpl.iMemSamplingPeriod = 45; |
242 this->memSamplerImpl.iMemSamplingPeriod = 10; |
243 #else |
243 #else |
244 this->memSamplerImpl.iMemSamplingPeriod = 10; |
244 this->memSamplerImpl.iMemSamplingPeriod = 10; |
245 #endif |
245 #endif |
246 |
246 |
247 #else |
247 #else // ifdef mem event handler |
248 this->memSamplerImpl.iMemSamplingPeriod = this->iSamplingPeriod; |
248 this->memSamplerImpl.iMemSamplingPeriod = this->iSamplingPeriod; |
249 #endif |
249 #endif |
250 this->memSamplerImpl.iMemSamplingPeriodDiv2 = (TInt)(this->memSamplerImpl.iMemSamplingPeriod / 2); |
250 // this->memSamplerImpl.iMemSamplingPeriodDiv2 = (TInt)(this->memSamplerImpl.iMemSamplingPeriod / 2); |
251 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
251 //#ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
252 this->memSamplerImpl.iMemSamplingPeriodDiv3 = (TInt)(this->memSamplerImpl.iMemSamplingPeriod / 3); |
252 // this->memSamplerImpl.iMemSamplingPeriodDiv3 = (TInt)(this->memSamplerImpl.iMemSamplingPeriod / 3); |
253 #endif |
253 //#endif |
254 |
254 |
255 LOGSTRING3("CProfilerMemSampler<%d>::Reset - set mem sampling period to %d", |
255 LOGSTRING3("CProfilerMemSampler<%d>::Reset - set mem sampling period to %d", |
256 BufferSize,this->memSamplerImpl.iMemSamplingPeriod); |
256 BufferSize,this->memSamplerImpl.iMemSamplingPeriod); |
257 } |
257 } |
258 else |
258 else // iSyncOffset == KStateSamplingEnding |
259 { |
259 { |
260 LOGSTRING2("DProfilerMemSampler<%d>::Reset - reset in stop", BufferSize); |
260 LOGSTRING2("DProfilerMemSampler<%d>::Reset - reset in stop", BufferSize); |
261 #ifdef MEM_EVENT_HANDLER |
261 #ifdef MEM_EVENT_HANDLER |
262 // destroy memory event handler |
262 // destroy memory event handler |
263 if(iEventHandler) |
263 if(iEventHandler) |
264 { |
264 { |
265 // stop previous sampling if still running |
265 // stop previous sampling if still running |
266 // Kern::Printf("Stopping DMemoryEventHandler"); |
266 LOGSTRING("Stopping DMemoryEventHandler"); |
267 iEventHandler->Stop(); |
267 iEventHandler->Stop(); |
268 iEventHandler->Close(); |
|
269 iEventHandler = NULL; |
|
270 } |
268 } |
271 #endif |
269 #endif |
272 return KErrNone; // return if reset called in stop |
270 return KErrNone; // return if reset called in stop |
273 } |
271 } |
274 |
272 |
275 // add MEM sample header |
273 // add MEM sample header |
276 TInt length(memSamplerImpl.CreateFirstSample()); |
274 TInt length(memSamplerImpl.CreateFirstSample()); |
277 this->iSampleBuffer->AddSample(memSamplerImpl.sample,length); |
275 this->iSampleBuffer->AddSample(memSamplerImpl.sample,length); |
278 |
276 |
|
277 TUint8 memSamplerId(4); // mem sampler id |
|
278 this->iSampleBuffer->AddSample(&memSamplerId,1); |
|
279 this->iSampleBuffer->AddSample((TUint8*)&(gppSamplerData->sampleNumber),4); |
279 this->sampleNeeded = false; |
280 this->sampleNeeded = false; |
280 LOGSTRING("DProfilerMemSampler::Reset - exit"); |
281 LOGSTRING("DProfilerMemSampler::Reset - exit"); |
281 return KErrNone; |
282 return KErrNone; |
282 } |
283 } |
283 |
284 |
297 #endif |
298 #endif |
298 { |
299 { |
299 #endif |
300 #endif |
300 // disable interrupts for checking the kernel containers (EChunk, EThread) |
301 // disable interrupts for checking the kernel containers (EChunk, EThread) |
301 // TInt interruptLevel(NKern::DisableInterrupts(0)); |
302 // TInt interruptLevel(NKern::DisableInterrupts(0)); |
302 |
|
303 // first collect chunk data |
303 // first collect chunk data |
304 TInt length(this->memSamplerImpl.SampleImpl()); |
304 TInt length(this->memSamplerImpl.SampleImpl(this->gppSamplerData->sampleNumber)); |
|
305 LOGSTRING2("DProfilerMemSampler<>::PostSample - in post sample, clock %d", this->memSamplerImpl.iCount ); |
305 if(length != 0) |
306 if(length != 0) |
306 { |
307 { |
307 // then, encode the sample to the buffer until no further data available |
308 // then, encode the sample to the buffer until no further data available |
308 while(length > 0) |
309 while(length > 0) |
309 { |
310 { |
310 this->iSampleBuffer->AddSample(memSamplerImpl.sample,length); |
311 TInt ret =this->iSampleBuffer->AddSample(memSamplerImpl.sample,length); |
311 length = this->memSamplerImpl.SampleImpl(); |
312 if (ret != 0) |
|
313 { |
|
314 Kern::Printf(("DProfilerMemSampler<>::PostSample() - add to sample buffer failed, loosing data, error = %d"),ret); } |
|
315 length = this->memSamplerImpl.SampleImpl(this->gppSamplerData->sampleNumber); |
|
316 LOGSTRING("DProfilerMemSampler<>::PostSample - in post sample again"); |
312 |
317 |
313 // indicate that the whole MEM sample ends by having a 0x00 in the end |
318 // indicate that the whole MEM sample ends by having a 0x00 in the end |
314 if(length == 0) |
319 if(length == 0) |
315 { |
320 { |
316 TUint8 number(0); |
321 TUint8 endMark(0); |
317 LOGSTRING("MEM sampler PostSample - all samples generated!"); |
322 LOGSTRING("MEM sampler PostSample - all samples generated!"); |
318 |
323 |
319 this->iSampleBuffer->AddSample(&number,1); |
324 this->iSampleBuffer->AddSample(&endMark,1); |
320 LOGSTRING2("MEM sampler PostSample - end mark added, time: %d", gppSamplerData->sampleNumber); |
325 LOGSTRING2("MEM sampler PostSample - end mark added, time: %d", gppSamplerData->sampleNumber); |
|
326 |
|
327 if (memSamplerImpl.iThreadsGathered && !memSamplerImpl.iChunksGathered) |
|
328 { |
|
329 LOGSTRING("MEM sampler PostSample - creating timestamp for chunks!"); |
|
330 // add start marker for chunks |
|
331 TUint8 memSamplerId(4); // mem sampler id |
|
332 this->iSampleBuffer->AddSample(&memSamplerId,1); |
|
333 this->iSampleBuffer->AddSample((TUint8*)&(gppSamplerData->sampleNumber),4); |
|
334 } |
|
335 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS |
|
336 if (memSamplerImpl.iThreadsGathered && memSamplerImpl.iChunksGathered) |
|
337 { |
|
338 // add start marker for chunks |
|
339 TUint8 memSamplerId(4); // mem sampler id |
|
340 this->iSampleBuffer->AddSample(&memSamplerId,1); |
|
341 this->iSampleBuffer->AddSample((TUint8*)&(gppSamplerData->sampleNumber),4); |
|
342 } |
|
343 #endif |
321 } |
344 } |
322 } |
345 } |
323 } |
346 } |
324 // restore interrupts and continue normal execution |
347 // restore interrupts and continue normal execution |
325 // NKern::RestoreInterrupts(interruptLevel); |
348 // NKern::RestoreInterrupts(interruptLevel); |
330 if(memSamplerImpl.iThreadsGathered && memSamplerImpl.iChunksGathered && memSamplerImpl.iLibrariesGathered) |
353 if(memSamplerImpl.iThreadsGathered && memSamplerImpl.iChunksGathered && memSamplerImpl.iLibrariesGathered) |
331 #else |
354 #else |
332 if(memSamplerImpl.iThreadsGathered && memSamplerImpl.iChunksGathered) |
355 if(memSamplerImpl.iThreadsGathered && memSamplerImpl.iChunksGathered) |
333 #endif |
356 #endif |
334 { |
357 { |
335 // start memory event tracking after checking the current memory status |
358 if(iSyncOffset != KStateSamplingEnding) |
336 if(!iEventHandler->Tracking()) |
359 { |
337 { |
360 // start memory event tracking after checking the current memory status |
338 iEventHandler->Start(); |
361 if(!iEventHandler->Tracking()) |
339 // Kern::Printf("DProfilerMemSampler<%d>::PostSample - memory event handler started",BufferSize); |
362 { |
340 } |
363 LOGSTRING2("MEM sampler PostSample - Starting event handler timestamp : %x", gppSamplerData->sampleNumber); |
341 |
364 memSamplerImpl.iTimeToSample = false; |
|
365 iEventHandler->Start(); |
|
366 LOGSTRING2("DProfilerMemSampler<%d>::PostSample - memory event handler started",BufferSize); |
|
367 } |
|
368 } |
342 } |
369 } |
343 #endif |
370 #endif |
344 |
371 |
345 LOGSTRING2("MEM sampler PostSample - finished sampling, time: %d", gppSamplerData->sampleNumber); |
372 LOGSTRING2("MEM sampler PostSample - finished sampling, time: %d", gppSamplerData->sampleNumber); |
346 |
373 |
347 // finally perform superclass postsample |
374 // finally perform superclass postsample |
348 TInt i(this->DProfilerGenericSampler<BufferSize>::PostSample()); |
375 TInt i(this->DProfilerGenericSampler<BufferSize>::PostSample()); |
|
376 // notify event handler |
|
377 //iEventHandler->SampleHandled(); |
349 return i; |
378 return i; |
350 } |
379 } |
351 |
380 |
352 template <int BufferSize> |
381 template <int BufferSize> |
353 TBool DProfilerMemSampler<BufferSize>::PostSampleNeeded() |
382 TBool DProfilerMemSampler<BufferSize>::PostSampleNeeded() |
354 { |
383 { |
355 LOGSTRING3("DProfilerMemSampler<%d>::PostSampleNeeded - state %d",BufferSize,this->iSampleBuffer->GetBufferStatus()); |
384 LOGSTRING3("DProfilerMemSampler<%d>::PostSampleNeeded - state %d",BufferSize,this->iSampleBuffer->GetBufferStatus()); |
356 |
385 |
357 TUint32 status(this->iSampleBuffer->iBufferStatus); |
386 TUint32 status(this->iSampleBuffer->GetBufferStatus()); |
358 |
387 if(iEventHandler) |
359 if(status == DProfilerSampleBuffer::BufferCopyAsap || status == DProfilerSampleBuffer::BufferFull || this->sampleNeeded == true) |
388 { |
360 { |
389 if(iEventHandler->Tracking()) |
361 return true; |
390 { |
362 } |
391 this->sampleNeeded = iEventHandler->SampleNeeded(); |
363 |
392 } |
364 return false; |
393 } |
|
394 if(status == DProfilerSampleBuffer::BufferCopyAsap || status == DProfilerSampleBuffer::BufferFull || this->sampleNeeded == true) |
|
395 { |
|
396 return true; |
|
397 } |
|
398 |
|
399 return false; |
365 } |
400 } |
366 |
401 |
367 template <int BufferSize> |
402 template <int BufferSize> |
368 void DProfilerMemSampler<BufferSize>::Sample() |
403 void DProfilerMemSampler<BufferSize>::Sample(TAny* aPtr) |
369 { |
404 { |
370 LOGSTRING2("DProfilerMemSampler<%d>::Sample",BufferSize); |
405 LOGSTRING3("DProfilerMemSampler<%d>::Sample, time %d",BufferSize, this->memSamplerImpl.iCount); |
371 |
406 if(iEventHandler) |
372 // check if sample is needed, i.e. the sampling interval is met |
407 { |
373 if(memSamplerImpl.SampleNeeded()) |
408 if(!iEventHandler->Tracking()) |
374 { |
409 { |
375 // set the flag for post sampling |
410 // check if sample is needed, i.e. the sampling interval is met |
376 this->sampleNeeded = true; |
411 if(memSamplerImpl.SampleNeeded(gppSamplerData->sampleNumber)) |
377 |
412 { |
378 // start the MEM sample with the sample time |
413 // set the flag for post sampling |
379 TUint8 number(4); // mem sampler id |
414 this->sampleNeeded = true; |
380 this->iSampleBuffer->AddSample(&number,1); |
415 /* |
381 this->iSampleBuffer->AddSample((TUint8*)&(gppSamplerData->sampleNumber),4); |
416 LOGSTRING2("timestamp : 0x%04x", gppSamplerData->sampleNumber); |
382 |
417 // start the MEM sample with the sample time |
383 // leave the rest of the processing for PostSample() |
418 TUint8 memSamplerId(4); // mem sampler id |
384 } |
419 this->iSampleBuffer->AddSample(&memSamplerId,1); |
385 |
420 this->iSampleBuffer->AddSample((TUint8*)&(gppSamplerData->sampleNumber),4); |
386 #ifdef MEM_EVENT_HANDLER |
421 */ |
387 // call this to increase the time stamp |
422 // leave the rest of the processing for PostSample() |
388 else if(iEventHandler->SampleNeeded()) |
423 } |
389 { |
424 } |
390 // set the flag for post sampling |
425 //#ifdef MEM_EVENT_HANDLER |
391 this->sampleNeeded = true; |
426 // // call this to increase the time stamp |
392 } |
427 // if(iEventHandler->SampleNeeded()) |
393 |
|
394 // // check if time stamp is divibable with |
|
395 // if((memSamplerImpl.iCount % KProfilerTotalMemorySamplePeriod) == 0 && |
|
396 // memSamplerImpl.iCount > 0) |
|
397 // { |
428 // { |
398 // // sample total memory once per 100 ms |
429 // // set the flag for post sampling |
399 // memSamplerImpl.EncodeTotalMemory(); |
430 // this->sampleNeeded = true; |
400 // |
|
401 // // add end mark |
|
402 // TUint8 number(0); |
|
403 // this->iSampleBuffer->AddSample(&number,1); |
|
404 // } |
431 // } |
405 #endif |
432 //#endif |
406 |
433 } |
407 LOGSTRING2("CProfilerMemSampler<%d>::Sample",BufferSize); |
|
408 return; |
434 return; |
409 } |
435 } |
410 |
436 |
411 template <int BufferSize> |
437 template <int BufferSize> |
412 DProfilerMemSampler<BufferSize>::~DProfilerMemSampler() |
438 DProfilerMemSampler<BufferSize>::~DProfilerMemSampler() |