piprofiler/plugins/GeneralsPlugin/src/IttSamplerImpl.cpp
branchRCL_3
changeset 19 da2cedce4920
equal deleted inserted replaced
18:d27dfa8884ad 19:da2cedce4920
       
     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 
       
    19 #include <piprofiler/ProfilerVersion.h>
       
    20 
       
    21 #include <kern_priv.h>
       
    22 #include <plat_priv.h>
       
    23 
       
    24 #include "IttSamplerImpl.h"
       
    25 
       
    26 #ifdef ITT_EVENT_HANDLER
       
    27 _LIT8(KIttVersion, "2.00");
       
    28 #else
       
    29 _LIT8(KIttVersion, "1.22");
       
    30 #endif
       
    31 
       
    32 /*
       
    33  *	ITT sampler definition
       
    34  *  	
       
    35  */
       
    36 IttSamplerImpl::IttSamplerImpl():
       
    37         sampleDescriptor(&(this->sample[1]),0,KITTSampleBufferSize)
       
    38 {
       
    39 	this->currentLibCount = 0;
       
    40 	iTimeToSample = EFalse;
       
    41 	this->Reset();
       
    42 }
       
    43 
       
    44 /*
       
    45  * destructor
       
    46  */
       
    47 IttSamplerImpl::~IttSamplerImpl()
       
    48 {
       
    49 
       
    50 }
       
    51 
       
    52 /*
       
    53  * IttSamplerImpl::CreateFirstSample()
       
    54  * 
       
    55  * Function for creating the first sample to the log file
       
    56  */
       
    57 TInt IttSamplerImpl::CreateFirstSample() 
       
    58 {	
       
    59     Kern::Printf("ittSamplerImpl::createFirstSample\n");
       
    60 	this->iVersionData.Zero();
       
    61 	this->iVersionData.Append(_L8("Bappea_ITT_V"));
       
    62 	this->iVersionData.Append(KIttVersion);
       
    63 	this->itt_sample = (TUint8*)iVersionData.Ptr();
       
    64 	return iVersionData.Length();
       
    65 }
       
    66 
       
    67 /*
       
    68  * IttSamplerImpl::SampleNeeded(TUint32 sampleNum)
       
    69  * 
       
    70  * @param TUint32 Sample number
       
    71  * 
       
    72  */
       
    73 TBool IttSamplerImpl::SampleNeeded(TUint32 sampleNum)
       
    74 {
       
    75 #ifdef ITT_EVENT_HANDLER
       
    76     iCount++;
       
    77     if (iCount <= iIttSamplingPeriod && ((iCount % iIttSamplingPeriod) == 0 || (iCount % iIttSamplingPeriodDiv2) == 0))
       
    78     {
       
    79         LOGSTRING2("IttSamplerImpl::SampleNeeded - time: %d", iCount);
       
    80         iTimeToSample = true;
       
    81 #else
       
    82     // no need to do anything, always a good time to sample.
       
    83     // Sample time filtering is done in IttSamplerImpl:SampleImpl() function
       
    84 #endif
       
    85         return true;
       
    86 #ifdef ITT_EVENT_HANDLER    
       
    87     }
       
    88     else 
       
    89     {
       
    90         return false;
       
    91     }
       
    92 #endif
       
    93 }
       
    94 
       
    95 /*
       
    96  * IttSamplerImpl::SampleImpl(TUint32 pc, TUint32 sampleNum)
       
    97  * 
       
    98  * @param TUint32 program counter
       
    99  * @param TUint32 sample number
       
   100  */
       
   101 TInt IttSamplerImpl::SampleImpl(TUint32 pc,TUint32 sampleNum)
       
   102 {	
       
   103     // in order to avoid overloading the interrupt
       
   104 	// only one dynamic file in each 50ms is added to the stream
       
   105 	// with the application of the tool in mind, this is
       
   106 	// a reasonable measure
       
   107 
       
   108     // encode a process binary
       
   109     sampleDescriptor.Zero();
       
   110 	// original 
       
   111 	if((sampleNum % 20) != 0) return 0;
       
   112 	if((sampleNum % 40) == 0)
       
   113 	{
       
   114 		// encode a library binary
       
   115 		sampleDescriptor.Zero();
       
   116 		DObjectCon* libs = Kern::Containers()[ELibrary];
       
   117 		TInt libCount = libs->Count();
       
   118 		
       
   119 		// go 20 binaries through at a time
       
   120 		for(TInt i=0;i<20;i++)
       
   121 		{
       
   122 			if(currentLibCount >= libCount)
       
   123 			{
       
   124 				currentLibCount = 0;
       
   125 			}
       
   126 			
       
   127 			DLibrary* lib = (DLibrary*)(*libs)[currentLibCount];
       
   128 			currentLibCount++;
       
   129 			
       
   130 			DCodeSeg* seg = lib->iCodeSeg;
       
   131 			if(seg != 0)
       
   132 			{
       
   133 				if( (seg->iMark & 0x80) == 0)
       
   134 				{
       
   135 					this->sample[0] = seg->iFileName->Length();
       
   136 					sampleDescriptor.Append(*(seg->iFileName));
       
   137 					sampleDescriptor.Append((TUint8*)&(seg->iRunAddress),4);
       
   138 					sampleDescriptor.Append((TUint8*)&(seg->iSize),4);
       
   139 #ifdef ITT_EVENT_HANDLER
       
   140 					sampleDescriptor.Append((TUint8*)&(sampleNum),4);
       
   141 					//Kern::Printf("DLL: NM %S : RA:0x%x SZ:0x%x, SN:0x%x",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
       
   142 					this->iFirstSampleTaken = ETrue;
       
   143 #else
       
   144 		            //Kern::Printf("DLL: NM %S : RA:0x%x SZ:0x%x",seg->iFileName,seg->iRunAddress,seg->iSize);
       
   145 #endif
       
   146 					seg->iMark = (seg->iMark | 0x80);
       
   147 					
       
   148 					this->sample[0] = sampleDescriptor.Size();
       
   149 					return sampleDescriptor.Size()+1;
       
   150 				}
       
   151 			}
       
   152 		}
       
   153 	} else
       
   154 	{
       
   155 		SDblQue* codeSegList = Kern::CodeSegList();
       
   156 		//Kern::Printf("PI");
       
   157 		//TUint c = 0;
       
   158 		// the global list
       
   159 		for (SDblQueLink* codeseg= codeSegList->First(); codeseg!=(SDblQueLink*) codeSegList; codeseg=codeseg->iNext)
       
   160 		{				
       
   161 			DCodeSeg* seg = _LOFF(codeseg, DCodeSeg, iLink);
       
   162 			if(seg != 0)
       
   163 			{
       
   164 				if( (seg->iMark & 0x80) == 0)
       
   165 				{
       
   166 					this->sample[0] = seg->iFileName->Length();
       
   167 					sampleDescriptor.Append(*(seg->iFileName));
       
   168 					sampleDescriptor.Append((TUint8*)&(seg->iRunAddress),4);
       
   169 					sampleDescriptor.Append((TUint8*)&(seg->iSize),4);
       
   170 #ifdef ITT_EVENT_HANDLER
       
   171                     sampleDescriptor.Append((TUint8*)&(sampleNum),4);
       
   172                     //Kern::Printf("EXE2: NM %S : RA:0x%x SZ:0x%x, time: %d",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
       
   173                     this->iFirstSampleTaken = ETrue;                    
       
   174 #else
       
   175 					//Kern::Printf("EXE2: NM %S : RA:0x%x SZ:0x%x, time: %d",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
       
   176 #endif					
       
   177 					seg->iMark = (seg->iMark | 0x80);
       
   178 					
       
   179 					this->sample[0] = sampleDescriptor.Size();
       
   180 					return sampleDescriptor.Size()+1;
       
   181 				}
       
   182 			}
       
   183 		}	
       
   184 	}
       
   185 	return 0;
       
   186 }
       
   187 
       
   188 /*
       
   189  * IttSamplerImpl::Reset()
       
   190  */
       
   191 void IttSamplerImpl::Reset()
       
   192 {
       
   193     iTimeToSample = EFalse;
       
   194 #ifdef ITT_EVENT_HANDLER
       
   195     iFirstSampleTaken = EFalse;
       
   196 #endif
       
   197 	this->currentLibCount = 0;
       
   198 	this->itt_sample = (TUint8*)&(this->sample[0]);
       
   199 	sampleDescriptor.Zero();
       
   200 
       
   201 //	#ifdef ITT_TEST	
       
   202 	SDblQue* codeSegList = Kern::CodeSegList();
       
   203 	// the global list
       
   204 	for (SDblQueLink* codeseg= codeSegList->First(); codeseg!=(SDblQueLink*) codeSegList; codeseg=codeseg->iNext)
       
   205 	{				
       
   206 		DCodeSeg* seg = _LOFF(codeseg,DCodeSeg, iLink);
       
   207 		//if(seg != 0)
       
   208 		{
       
   209 			if( (seg->iMark & 0x80) > 0)
       
   210 			{
       
   211 				seg->iMark = (seg->iMark & ~0x80);
       
   212 			}
       
   213 		}
       
   214 	}	
       
   215 	// the garbage list
       
   216 	DObjectCon* libs = Kern::Containers()[ELibrary];
       
   217 	TInt libCount = libs->Count();
       
   218 	for(TInt i=0;i<libCount;i++)
       
   219 	{
       
   220 		DLibrary* lib = (DLibrary*)(*libs)[i];
       
   221 		DCodeSeg* seg = lib->iCodeSeg;
       
   222 		if( (seg->iMark & 0x80) > 0)
       
   223 		{
       
   224 			seg->iMark = (seg->iMark & ~0x80);
       
   225 		}
       
   226 	}
       
   227 	
       
   228 	DObjectCon* procs = Kern::Containers()[EProcess];
       
   229 	TInt procCount = procs->Count();
       
   230 	for(TInt i=0;i<procCount;i++)
       
   231 	{
       
   232 		DProcess* pro = (DProcess*)(*procs)[i];
       
   233 		DCodeSeg* seg = pro->iCodeSeg;
       
   234 		if(seg != 0)
       
   235 		{
       
   236 			if( (seg->iMark & 0x80) > 0)
       
   237 			{
       
   238 				seg->iMark = (seg->iMark & ~0x80);
       
   239 			}
       
   240 		}
       
   241 	}
       
   242 	//#endif   //ITT_TEST
       
   243 }
       
   244 // end of file