perfsrv/piprofiler/plugins/GeneralsPlugin/src/PriSamplerImpl.cpp
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    97 	    {
    97 	    {
    98 	    if((iCountti % iPriSamplingPeriod) != 0 ) return 0;
    98 	    if((iCountti % iPriSamplingPeriod) != 0 ) return 0;
    99 	    
    99 	    
   100         LOGTEXT("Processing threads...");
   100         LOGTEXT("Processing threads...");
   101 
   101 
   102         DObjectCon& threads = *Kern::Containers()[EThread];
   102         DObjectCon* threads = Kern::Containers()[EThread];
       
   103         NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex
       
   104         threads->Wait();
   103 
   105 
   104         // PRI trace variables
   106         // PRI trace variables
   105         this->iThreadCount = 0; 
   107         this->iThreadCount = 0; 
   106         this->iNewThreadCount = 0;
   108         this->iNewThreadCount = 0;
   107         TInt totalThreadCount = threads.Count();
   109         TInt totalThreadCount = threads->Count();
   108 
   110 
   109         for(TInt i=0;i<totalThreadCount;i++)
   111         for(TInt i=0;i<totalThreadCount;i++)
   110             {
   112             {
   111             DThread* t = (DThread*)(threads)[i];
   113             //DThread* t = (DThread*)(threads)[i];
       
   114             DObject* pO=(*threads)[i];
       
   115             DThread* t = (DThread*)pO;
       
   116             
   112             LOGSTRING3("Processing thread %d, tag: 0x%x",i,TAG(t));
   117             LOGSTRING3("Processing thread %d, tag: 0x%x",i,TAG(t));
   113 
   118 
   114             if( (TAG(t) & PROFILER_THREAD_MARK) == 0)
   119             if( (TAG(t) & PROFILER_THREAD_MARK) == 0)
   115                 {
   120                 {
   116                 LOGSTRING2("Marking thread %d",i);
   121                 LOGSTRING2("Marking thread %d",i);
   130             this->threadsToSample[this->iThreadCount] = t;
   135             this->threadsToSample[this->iThreadCount] = t;
   131             this->iThreadCount++;
   136             this->iThreadCount++;
   132             LOGSTRING2("Added thread %d to threads to sample",i);
   137             LOGSTRING2("Added thread %d to threads to sample",i);
   133             }
   138             }
   134 
   139 
       
   140         threads->Signal();
       
   141         NKern::ThreadLeaveCS();  // End of critical section
       
   142 
   135         if(this->iThreadCount > 0 || this->iNewThreadCount > 0)
   143         if(this->iThreadCount > 0 || this->iNewThreadCount > 0)
   136             {
   144             {
   137             this->iProcessing = EStartingToProcess;
   145             this->iProcessing = EStartingToProcess;
   138             
   146             
   139             // process the first sample
   147             // process the first sample
   141             
   149             
   142             if(length == 0)
   150             if(length == 0)
   143                 {
   151                 {
   144                 this->iProcessing = ENothingToProcess;
   152                 this->iProcessing = ENothingToProcess;
   145                 }
   153                 }
   146         
       
   147             return length;
   154             return length;
   148             }
   155             }
   149         else
   156         else
   150             {
   157             {
   151             // there were no threads, should not take place
   158             // there were no threads, should not take place
   299 	this->iProcessing = ENothingToProcess;
   306 	this->iProcessing = ENothingToProcess;
   300 	this->sampleDescriptor.Zero();
   307 	this->sampleDescriptor.Zero();
   301 
   308 
   302 
   309 
   303 	// clear all thread tags
   310 	// clear all thread tags
       
   311 	NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex
   304 	DObjectCon* threads = Kern::Containers()[EThread];
   312 	DObjectCon* threads = Kern::Containers()[EThread];
       
   313 	threads->Wait(); // Obtain the container mutex so the list does get changed under us
       
   314 
   305 	TInt totalThreadCount = threads->Count();
   315 	TInt totalThreadCount = threads->Count();
   306 	for(TInt i=0;i<totalThreadCount;i++)
   316 	for(TInt i=0;i<totalThreadCount;i++)
   307 	    {
   317 	    {
   308 		DThread* t = (DThread*)(*threads)[i];
   318 		DThread* t = (DThread*)(*threads)[i];
   309 		TAG(t) = (TAG(t) & 0xfffffffd);
   319 		TAG(t) = (TAG(t) & 0xfffffffd);
   310 	    }
   320 	    }
   311     }
   321 	threads->Signal();
   312 
   322 	NKern::ThreadLeaveCS();  // End of critical section
       
   323 	}
       
   324