perfsrv/piprofiler/plugins/GeneralsPlugin/inc/MemSamplerImpl.h
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    38 const TInt KProfilerMaxChunksAmount = 1024;
    38 const TInt KProfilerMaxChunksAmount = 1024;
    39 const TInt KProfilerMaxLibrariesAmount = 1024;
    39 const TInt KProfilerMaxLibrariesAmount = 1024;
    40 const TInt KProfilerTotalMemorySamplePeriod = 100;
    40 const TInt KProfilerTotalMemorySamplePeriod = 100;
    41 
    41 
    42 // flags
    42 // flags
       
    43 //#ifndef __SMP__
    43 #define MEM_EVENT_HANDLER
    44 #define MEM_EVENT_HANDLER
    44 //#define MEM_EVENT_HANDLER_LIBRARY_EVENTS
    45 //#define MEM_EVENT_HANDLER_LIBRARY_EVENTS
       
    46 //#endif
    45 
    47 
    46 /*
    48 /*
    47  *	
    49  *	
    48  *	MEM sampler definition
    50  *	MEM sampler definition
    49  *	
    51  *	
    59 		EStartingToProcess,
    61 		EStartingToProcess,
    60 		EProcessingNames,
    62 		EProcessingNames,
    61 		EProcessingData,
    63 		EProcessingData,
    62 		ENothingToProcess
    64 		ENothingToProcess
    63 	};
    65 	};
    64 #ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS
    66 
    65 	enum ESampleType
    67 	enum ESampleType
    66 	{
    68 	{
    67 	    ESampleChunks,
    69 	    ESampleChunks,
    68 	    ESampleThreads,
    70 	    ESampleThreads,
    69 	    ESampleLibraries
    71 	    ESampleLibraries
    70 	};
    72 	};
    71 #endif
       
    72 
    73 
    73 	DMemSamplerImpl();
    74 	DMemSamplerImpl();
    74 	~DMemSamplerImpl();
    75 	~DMemSamplerImpl();
    75 
    76 
    76 	TInt	CreateFirstSample();
    77 	TInt	CreateFirstSample();
    77 	TInt	SampleImpl();
    78 	TInt	SampleImpl(TUint32 sampleNum);
    78 	TBool	SampleNeeded();
    79 	TBool	SampleNeeded(TUint32 sampleNum);
    79 	void	Reset();
    80 	void	Reset();
    80 	TInt	ProcessChunks();
    81 	TInt	ProcessChunks();
    81 	TInt    ProcessThreads();
    82 	TInt    ProcessThreads();
    82     TInt    GatherChunks();
    83     TInt    GatherChunks();
    83     TInt    GatherThreads();
    84     TInt    GatherThreads();
   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
   157 {
   158 {
   158 public:
   159 public:
   159 	DProfilerMemSampler(struct TProfilerGppSamplerData*, TInt id);
   160 	DProfilerMemSampler(struct TProfilerGppSamplerData*, TInt id);
   160 	~DProfilerMemSampler();
   161 	~DProfilerMemSampler();
   161 
   162 
   162 	void	Sample();
   163 	void	Sample(TAny* aPtr);
   163 	TInt	Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
   164 	TInt	Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
   164 	TInt	PostSample();
   165 	TInt	PostSample();
   165 	TBool	PostSampleNeeded();
   166 	TBool	PostSampleNeeded();
   166 	
   167 	
   167 private:
   168 private:
   169     DMemoryEventHandler*               iEventHandler;
   170     DMemoryEventHandler*               iEventHandler;
   170 #endif
   171 #endif
   171 	DMemSamplerImpl			           memSamplerImpl;
   172 	DMemSamplerImpl			           memSamplerImpl;
   172 	struct TProfilerGppSamplerData*    gppSamplerData;
   173 	struct TProfilerGppSamplerData*    gppSamplerData;
   173 	TBool                              sampleNeeded;
   174 	TBool                              sampleNeeded;
       
   175     TUint32                         iSyncOffset;
   174 };
   176 };
   175 
   177 
   176 /*
   178 /*
   177  *	
   179  *	
   178  *	MEM sampler implementation
   180  *	MEM sampler implementation
   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
   211         
   213         
   212         // memory event handler
   214         // memory event handler
   213         if(iEventHandler)
   215         if(iEventHandler)
   214             {
   216             {
   215             // stop previous sampling if still running
   217             // stop previous sampling if still running
   216 //            Kern::Printf("Stopping DMemoryEventHandler");
       
   217             iEventHandler->Stop();
   218             iEventHandler->Stop();
   218             iEventHandler->Close();
   219             }
   219             iEventHandler = NULL;
   220         else
   220             }
   221             {
   221     
   222             iEventHandler = new DMemoryEventHandler(this->iSampleBuffer, this->gppSamplerData);
   222 //        Kern::Printf("Initiating DMemoryEventHandler");
   223             }
   223         iEventHandler = new DMemoryEventHandler(this->iSampleBuffer);
   224         
   224         if(iEventHandler)
   225         if(iEventHandler)
   225             {
   226             {
   226 //            Kern::Printf("Creating DMemoryEventHandler");
       
   227             TInt err(iEventHandler->Create());
   227             TInt err(iEventHandler->Create());
   228             if(err != KErrNone)
   228             if(err != KErrNone)
   229                 {
   229                 {
   230                 Kern::Printf("Error in creation of DMemoryEventHandler, error %d", err);
   230                 Kern::Printf("Error in creation of DMemoryEventHandler, error %d", err);
   231                 return err;
   231                 return err;
   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()
   415 #ifdef MEM_EVENT_HANDLER
   441 #ifdef MEM_EVENT_HANDLER
   416     // memory event handler
   442     // memory event handler
   417      if(iEventHandler)
   443      if(iEventHandler)
   418          {
   444          {
   419          // stop previous sampling if still running
   445          // stop previous sampling if still running
   420 //         Kern::Printf("Stopping DMemoryEventHandler");
   446          LOGSTRING("Stopping DMemoryEventHandler");
   421          iEventHandler->Stop();
   447          iEventHandler->Stop();
   422          iEventHandler->Close();
   448          iEventHandler->Close();
   423          iEventHandler = NULL;
   449          iEventHandler = NULL;
   424          }
   450          }
   425 #endif
   451 #endif