perfsrv/piprofiler/plugins/GeneralsPlugin/src/IttEventHandler.cpp
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    33     :   DKernelEventHandler(EventHandler, this),
    33     :   DKernelEventHandler(EventHandler, this),
    34         iSampleBuffer(aSampleBuffer),
    34         iSampleBuffer(aSampleBuffer),
    35         iSampleDescriptor(&(this->iSample[1]),0,KITTBufferSize),
    35         iSampleDescriptor(&(this->iSample[1]),0,KITTBufferSize),
    36         gppSamplerData(aGppSamplerDataIn)
    36         gppSamplerData(aGppSamplerDataIn)
    37     {
    37     {
    38     //Kern::Printf("DIttEventHandler::DIttEventHandler()");
    38     iSampleAvailable = false;
    39 
       
    40     }
    39     }
    41 
    40 
    42 /*
    41 /*
    43  * DIttEventHandler::Create()
    42  * DIttEventHandler::Create()
    44  */
    43  */
    45 TInt DIttEventHandler::Create()
    44 TInt DIttEventHandler::Create()
    46     {
    45     {
    47     Kern::Printf("DIttEventHandler::Create()");
       
    48 
       
    49     TInt err(Kern::MutexCreate(iLock, _L("IttEventHandlerLock"), KMutexOrdDebug));
    46     TInt err(Kern::MutexCreate(iLock, _L("IttEventHandlerLock"), KMutexOrdDebug));
    50     if (err != KErrNone)
    47     if (err != KErrNone)
    51         return err;
    48         return err;
    52     
    49     
    53     return Add();
    50     return Add();
    56 /*
    53 /*
    57  * Destructor
    54  * Destructor
    58  */
    55  */
    59 DIttEventHandler::~DIttEventHandler()
    56 DIttEventHandler::~DIttEventHandler()
    60     {
    57     {
    61     //Kern::Printf("DIttEventHandler::~DIttEventHandler()");
    58     LOGSTRING("DIttEventHandler::~DIttEventHandler()");
    62 
    59 
    63     if (iLock)
    60     if (iLock)
    64         iLock->Close(NULL);
    61         iLock->Close(NULL);
    65     }
    62     }
    66 
    63 
    67 
    64 
    68 TInt DIttEventHandler::Start()
    65 TInt DIttEventHandler::Start()
    69     {
    66     {
    70     //Kern::Printf("DIttEventHandler::Start()");
    67     LOGSTRING("DIttEventHandler::Start()");
    71 
    68 
    72     iTracking = ETrue;
    69     iTracking = ETrue;
    73     return KErrNone;
    70     return KErrNone;
    74     }
    71     }
    75 
    72 
    76 
    73 
    77 TInt DIttEventHandler::Stop()
    74 TInt DIttEventHandler::Stop()
    78     {
    75     {
    79     //Kern::Printf("DIttEventHandler::Stop()");
    76     LOGSTRING("DIttEventHandler::Stop()");
    80 
    77 
    81     iTracking = EFalse;
    78     iTracking = EFalse;
       
    79     LOGSTRING2("ITT - gpp sample counter %d", this->gppSamplerData->sampleNumber);
    82     return KErrNone;
    80     return KErrNone;
    83     }
    81     }
    84 
    82 
    85 TBool DIttEventHandler::SampleNeeded()
    83 TBool DIttEventHandler::SampleNeeded()
    86     {
    84     {
    87     LOGTEXT("DIttEventHandler::SampleNeeded()");
    85     //LOGSTRING("DIttEventHandler::SampleNeeded()");
    88     
       
    89     // increase the counter by one on each round
       
    90     iCount++;
       
    91     
    86     
    92     // check if event handler was not running
    87     // check if event handler was not running
    93     if(!iTracking)
    88     if(!iTracking)
    94        return false;
    89         {
    95     
    90         return false;
    96     return true;
    91         }
       
    92     // check if a new sample is available
       
    93     if(iSampleAvailable)
       
    94         {
       
    95         return true;
       
    96         }
       
    97     else
       
    98         {
       
    99         return false;
       
   100         }
    97     }
   101     }
    98 
   102 
       
   103 void DIttEventHandler::SampleHandled()
       
   104     {
       
   105     iSampleAvailable = false;
       
   106     }
    99 
   107 
   100 TUint DIttEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis)
   108 TUint DIttEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis)
   101     {
   109     {
   102     //Kern::Printf("DIttEventHandler::EventHandler()");
   110     //LOGSTRING("DIttEventHandler::EventHandler()");
   103     return ((DIttEventHandler*)aThis)->HandleEvent(aType, a1, a2);
   111     return ((DIttEventHandler*)aThis)->HandleEvent(aType, a1, a2);
   104     }
   112     }
   105 
   113 
   106 
   114 
   107 
   115 
   108 TUint DIttEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
   116 TUint DIttEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
   109     {
   117     {
   110     //Kern::Printf("DIttEventHandler::HandleEvent()");
       
   111     //Kern::Printf("New kernel event received, %d", aType);
       
   112     
   118     
   113     if (iTracking/* && iCount != iPreviousCount*/)
   119     if (iTracking)
   114         {
   120         {
   115         switch (aType)
   121         switch (aType)
   116             {
   122             {
   117             
       
   118             case EEventAddCodeSeg:
   123             case EEventAddCodeSeg:
   119                 //Kern::Printf("DCodeSeg added: 0x%08x", (DCodeSeg*)a1);
   124                 LOGSTRING("DIttEventHandler::HandleEvent() EEventAddCodeSeg received");
   120                 HandleAddCodeSeg((DCodeSeg*)a1);
   125                 HandleAddCodeSeg((DCodeSeg*)a1);
   121                 break;
   126                 break;
   122                 
   127                 
   123             case EEventRemoveCodeSeg:
   128             case EEventRemoveCodeSeg:
   124                 //Kern::Printf("DCodeSeg deleted: 0x%08x", (DCodeSeg*)a1);
   129                 LOGSTRING("DIttEventHandler::HandleEvent() EEventRemoveCodeSeg received");
   125                 HandleRemoveCodeSeg((DCodeSeg*)a1);
   130                 HandleRemoveCodeSeg((DCodeSeg*)a1);
   126                 break;
   131                 break;
   127    
   132    
   128             default:
   133             default:
   129                 break;
   134                 break;
   130             }
   135             }
   131         }
   136         }
   132 //    else if(iTracking && iCount == iPreviousCount)
       
   133 //        {
       
   134 //        // if time stamp is not updated profiling has stopped
       
   135 //        Stop();
       
   136 //        }
       
   137     return DKernelEventHandler::ERunNext;
   137     return DKernelEventHandler::ERunNext;
   138     }
   138     }
   139 
   139 
   140 /*
   140 /*
   141  * 
   141  * 
   142  */
   142  */
   143 TBool DIttEventHandler::HandleAddCodeSeg(DCodeSeg* aSeg)
   143 TBool DIttEventHandler::HandleAddCodeSeg(DCodeSeg* aSeg)
   144     {    
   144     {    
       
   145     LOGSTRING("DIttEventHandler::HandleAddCodeSeg()");
   145     iSampleDescriptor.Zero();
   146     iSampleDescriptor.Zero();
   146     //Kern::Printf("DLL ADD: NM %S : RA:0x%x SZ:0x%x SN:0x%x",aSeg->iFileName,aSeg->iRunAddress,aSeg->iSize, this->gppSamplerData->sampleNumber);
   147     //Kern::Printf("DLL ADD: NM %S : RA:0x%x SZ:0x%x SN:0x%x",aSeg->iFileName,aSeg->iRunAddress,aSeg->iSize, this->gppSamplerData->sampleNumber);
   147 
   148 
       
   149     NKern::ThreadEnterCS();
       
   150     Kern::MutexWait(*iLock);
   148     iSample[0] = aSeg->iFileName->Length();
   151     iSample[0] = aSeg->iFileName->Length();
   149     iSampleDescriptor.Append(*aSeg->iFileName);
   152     iSampleDescriptor.Append(*aSeg->iFileName);
   150     iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4);
   153     iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4);
   151     iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4);
   154     iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4);
   152     iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4);
   155     iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4);
   153     iSample[0] = iSampleDescriptor.Size();
   156     iSample[0] = iSampleDescriptor.Size();
       
   157    
       
   158     iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1);
       
   159     Kern::MutexSignal(*iLock);
       
   160     NKern::ThreadLeaveCS();
   154     
   161     
   155     iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1);
   162     iSampleAvailable = true;
   156     return ETrue;
   163     return ETrue;
   157     }
   164     }
   158 
   165 
   159 TBool DIttEventHandler::HandleRemoveCodeSeg(DCodeSeg* aSeg)
   166 TBool DIttEventHandler::HandleRemoveCodeSeg(DCodeSeg* aSeg)
   160     {
   167     {
       
   168     LOGSTRING("DIttEventHandler::HandleRemoveCodeSeg()");
   161     iSampleDescriptor.Zero();
   169     iSampleDescriptor.Zero();
   162     //Kern::Printf("DLL REM: NM %S : RA:0x%x SZ:0x%x SN:0x%x",aSeg->iFileName,aSeg->iRunAddress,aSeg->iSize, this->gppSamplerData->sampleNumber);
   170     //Kern::Printf("DLL REM: NM %S : RA:0x%x SZ:0x%x SN:0x%x",aSeg->iFileName,aSeg->iRunAddress,aSeg->iSize, this->gppSamplerData->sampleNumber);
   163 
   171 
       
   172     NKern::ThreadEnterCS();
       
   173     Kern::MutexWait(*iLock);
       
   174     
   164     iSample[0] = aSeg->iFileName->Length();
   175     iSample[0] = aSeg->iFileName->Length();
   165     iSampleDescriptor.Append(*aSeg->iFileName);
   176     iSampleDescriptor.Append(*aSeg->iFileName);
   166     iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4);
   177     iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4);
   167     iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4);
   178     iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4);
   168     iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4);
   179     iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4);
   169     iSample[0] = iSampleDescriptor.Size();
   180     iSample[0] = iSampleDescriptor.Size();
   170     
   181 
   171     iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1);
   182     iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1);
       
   183     Kern::MutexSignal(*iLock);
       
   184     NKern::ThreadLeaveCS();
       
   185 
       
   186     iSampleAvailable = true;
   172     return ETrue;
   187     return ETrue;
   173     }
   188     }
   174 // end of file
   189 // end of file