20
|
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 |
{
|
62
|
39 |
iCurrentLibCount = 0;
|
|
40 |
iLibsCount = 0;
|
|
41 |
iCodeSegsCount = 0;
|
|
42 |
iTimeToSample = ETrue;
|
|
43 |
iInitState = KIttHandlingLibs;
|
20
|
44 |
this->Reset();
|
|
45 |
}
|
|
46 |
|
|
47 |
/*
|
|
48 |
* destructor
|
|
49 |
*/
|
|
50 |
IttSamplerImpl::~IttSamplerImpl()
|
|
51 |
{
|
62
|
52 |
LOGSTRING("IttSamplerImpl::~IttSamplerImpl()");
|
20
|
53 |
}
|
|
54 |
|
|
55 |
/*
|
|
56 |
* IttSamplerImpl::CreateFirstSample()
|
|
57 |
*
|
|
58 |
* Function for creating the first sample to the log file
|
|
59 |
*/
|
|
60 |
TInt IttSamplerImpl::CreateFirstSample()
|
|
61 |
{
|
|
62 |
this->iVersionData.Zero();
|
|
63 |
this->iVersionData.Append(_L8("Bappea_ITT_V"));
|
|
64 |
this->iVersionData.Append(KIttVersion);
|
|
65 |
this->itt_sample = (TUint8*)iVersionData.Ptr();
|
|
66 |
return iVersionData.Length();
|
|
67 |
}
|
|
68 |
|
|
69 |
/*
|
|
70 |
* IttSamplerImpl::SampleNeeded(TUint32 sampleNum)
|
|
71 |
*
|
|
72 |
* @param TUint32 Sample number
|
|
73 |
*
|
|
74 |
*/
|
|
75 |
TBool IttSamplerImpl::SampleNeeded(TUint32 sampleNum)
|
|
76 |
{
|
62
|
77 |
iCount = sampleNum;
|
|
78 |
LOGSTRING2("IttSamplerImpl::SampleNeeded - time: %d", iCount);
|
|
79 |
|
|
80 |
if ((iCount % iIttSamplingPeriod) == 0)
|
|
81 |
{
|
20
|
82 |
return true;
|
62
|
83 |
}
|
|
84 |
return false;
|
20
|
85 |
}
|
|
86 |
|
|
87 |
/*
|
|
88 |
* IttSamplerImpl::SampleImpl(TUint32 pc, TUint32 sampleNum)
|
|
89 |
*
|
|
90 |
* @param TUint32 program counter
|
|
91 |
* @param TUint32 sample number
|
|
92 |
*/
|
|
93 |
TInt IttSamplerImpl::SampleImpl(TUint32 pc,TUint32 sampleNum)
|
62
|
94 |
{
|
|
95 |
//LOGSTRING3("IttSamplerImpl::SampleImpl pc %d samplenum %d",pc, sampleNum);
|
20
|
96 |
// in order to avoid overloading the interrupt
|
|
97 |
// only one dynamic file in each 50ms is added to the stream
|
|
98 |
// with the application of the tool in mind, this is
|
|
99 |
// a reasonable measure
|
62
|
100 |
TInt ret(0);
|
20
|
101 |
// encode a process binary
|
62
|
102 |
|
|
103 |
//sampleDescriptor.Zero();
|
|
104 |
if(iTimeToSample)
|
|
105 |
{
|
20
|
106 |
// encode a library binary
|
62
|
107 |
//sampleDescriptor.Zero();
|
|
108 |
if(iInitState == KIttHandlingLibs)
|
|
109 |
{
|
|
110 |
if(iLibsCount < 20)
|
|
111 |
{
|
|
112 |
ret = HandleLibs(sampleNum);
|
|
113 |
iLibsCount++;
|
|
114 |
while(ret == KErrAlreadyExists)
|
|
115 |
{
|
|
116 |
ret = HandleLibs(sampleNum);
|
|
117 |
iLibsCount++;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
else
|
|
121 |
{
|
|
122 |
iLibsCount = 0;
|
|
123 |
return 0;
|
|
124 |
}
|
|
125 |
}
|
|
126 |
//LOGSTRING2("IttSamplerImpl::SampleImpl HandledLibs %d", ret);
|
|
127 |
// one library has been read to sample, needs to be written to file
|
|
128 |
|
|
129 |
else if(iInitState == KIttHandlingCodeSegs)
|
|
130 |
{
|
|
131 |
if(iCodeSegsCount < 20)
|
|
132 |
{
|
|
133 |
ret = HandleSegs(sampleNum);
|
|
134 |
iCodeSegsCount++;
|
|
135 |
while(ret == KErrAlreadyExists)
|
|
136 |
{
|
|
137 |
ret = HandleSegs(sampleNum);
|
|
138 |
iCodeSegsCount++;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
else
|
|
143 |
{
|
|
144 |
iCodeSegsCount = 0;
|
|
145 |
return 0;
|
|
146 |
}
|
|
147 |
}
|
|
148 |
|
|
149 |
//LOGSTRING2("IttSamplerImpl::SampleImpl HandledSegs %d", ret);
|
|
150 |
else
|
|
151 |
{
|
|
152 |
// nothing to do
|
|
153 |
Kern::Printf("IttSamplerImpl::SampleImpl - should not be here");
|
|
154 |
return 0;
|
|
155 |
}
|
|
156 |
}
|
|
157 |
else
|
|
158 |
{
|
|
159 |
LOGSTRING("IttSamplerImpl::SampleImpl Not time to sample");
|
20
|
160 |
}
|
62
|
161 |
|
|
162 |
return ret;
|
20
|
163 |
}
|
|
164 |
|
|
165 |
/*
|
|
166 |
* IttSamplerImpl::Reset()
|
|
167 |
*/
|
|
168 |
void IttSamplerImpl::Reset()
|
62
|
169 |
{
|
|
170 |
iTimeToSample = ETrue;
|
20
|
171 |
#ifdef ITT_EVENT_HANDLER
|
62
|
172 |
iInitialLibsTaken= EFalse;
|
|
173 |
iInitialSegsTaken= EFalse;
|
20
|
174 |
#endif
|
62
|
175 |
iCurrentLibCount = 0;
|
|
176 |
iLibsCount = 0;
|
|
177 |
iCodeSegsCount = 0;
|
|
178 |
iLatestCodeseg = NULL;
|
20
|
179 |
this->itt_sample = (TUint8*)&(this->sample[0]);
|
|
180 |
sampleDescriptor.Zero();
|
|
181 |
|
|
182 |
// #ifdef ITT_TEST
|
|
183 |
SDblQue* codeSegList = Kern::CodeSegList();
|
|
184 |
// the global list
|
|
185 |
for (SDblQueLink* codeseg= codeSegList->First(); codeseg!=(SDblQueLink*) codeSegList; codeseg=codeseg->iNext)
|
62
|
186 |
{
|
20
|
187 |
DCodeSeg* seg = _LOFF(codeseg,DCodeSeg, iLink);
|
|
188 |
//if(seg != 0)
|
62
|
189 |
{
|
20
|
190 |
if( (seg->iMark & 0x80) > 0)
|
62
|
191 |
{
|
20
|
192 |
seg->iMark = (seg->iMark & ~0x80);
|
62
|
193 |
}
|
|
194 |
}
|
|
195 |
}
|
20
|
196 |
// the garbage list
|
62
|
197 |
|
|
198 |
NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex
|
20
|
199 |
DObjectCon* libs = Kern::Containers()[ELibrary];
|
62
|
200 |
libs->Wait();
|
20
|
201 |
TInt libCount = libs->Count();
|
|
202 |
for(TInt i=0;i<libCount;i++)
|
62
|
203 |
{
|
20
|
204 |
DLibrary* lib = (DLibrary*)(*libs)[i];
|
|
205 |
DCodeSeg* seg = lib->iCodeSeg;
|
|
206 |
if( (seg->iMark & 0x80) > 0)
|
62
|
207 |
{
|
20
|
208 |
seg->iMark = (seg->iMark & ~0x80);
|
62
|
209 |
}
|
|
210 |
}
|
|
211 |
libs->Signal();
|
|
212 |
NKern::ThreadLeaveCS();
|
20
|
213 |
//#endif //ITT_TEST
|
|
214 |
}
|
62
|
215 |
/*
|
|
216 |
*
|
|
217 |
*/
|
|
218 |
TInt IttSamplerImpl::HandleLibs(TUint32 sampleNum)
|
|
219 |
{
|
|
220 |
NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex
|
|
221 |
DObjectCon* libs = Kern::Containers()[ELibrary];
|
|
222 |
libs->Wait();
|
|
223 |
TInt libCount(libs->Count());
|
|
224 |
sampleDescriptor.Zero();
|
|
225 |
|
|
226 |
// go 20 binaries through at a time
|
|
227 |
//for(TInt i=0;i<libCount;i++)
|
|
228 |
if (iCurrentLibCount < libCount)
|
|
229 |
{
|
|
230 |
// get libs from
|
|
231 |
DLibrary* lib = (DLibrary*)(*libs)[iCurrentLibCount];
|
|
232 |
libs->Signal();
|
|
233 |
NKern::ThreadLeaveCS();
|
|
234 |
iCurrentLibCount++;
|
|
235 |
|
|
236 |
DCodeSeg* seg = lib->iCodeSeg;
|
|
237 |
if(seg != 0)
|
|
238 |
{
|
|
239 |
if( (seg->iMark & 0x80) == 0)
|
|
240 |
{
|
|
241 |
this->sample[0] = seg->iFileName->Length();
|
|
242 |
sampleDescriptor.Append(*(seg->iFileName));
|
|
243 |
sampleDescriptor.Append((TUint8*)&(seg->iRunAddress),4);
|
|
244 |
sampleDescriptor.Append((TUint8*)&(seg->iSize),4);
|
|
245 |
|
|
246 |
#ifdef ITT_EVENT_HANDLER
|
|
247 |
sampleDescriptor.Append((TUint8*)&(sampleNum),4);
|
|
248 |
//Kern::Printf("DLL: NM %S : RA:0x%x SZ:0x%x, SN:0x%x",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
|
|
249 |
//this->iFirstSampleTaken = ETrue;
|
|
250 |
#else
|
|
251 |
//Kern::Printf("DLL: NM %S : RA:0x%x SZ:0x%x",seg->iFileName,seg->iRunAddress,seg->iSize);
|
|
252 |
#endif
|
|
253 |
seg->iMark = (seg->iMark | 0x80);
|
|
254 |
this->sample[0] = sampleDescriptor.Size();
|
|
255 |
return sampleDescriptor.Size()+1;
|
|
256 |
}
|
|
257 |
else
|
|
258 |
{
|
|
259 |
//Kern::Printf("Already met DLL: NM %S : RA:0x%x SZ:0x%x, SN:0x%x",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
|
|
260 |
return KErrAlreadyExists;
|
|
261 |
}
|
|
262 |
}
|
|
263 |
}
|
|
264 |
else
|
|
265 |
{
|
|
266 |
// check if list gone through
|
|
267 |
iInitState = KIttHandlingCodeSegs;
|
|
268 |
iInitialLibsTaken = ETrue;
|
|
269 |
}
|
|
270 |
libs->Signal();
|
|
271 |
NKern::ThreadLeaveCS();
|
|
272 |
return 0;
|
|
273 |
}
|
|
274 |
/*
|
|
275 |
*
|
|
276 |
*/
|
|
277 |
TInt IttSamplerImpl::HandleSegs(TUint32 sampleNum)
|
|
278 |
{
|
|
279 |
SDblQue* codeSegList = Kern::CodeSegList();
|
|
280 |
//Kern::Printf("PI");
|
|
281 |
TUint count(0);
|
|
282 |
sampleDescriptor.Zero();
|
|
283 |
if(iLatestCodeseg == NULL)
|
|
284 |
{
|
|
285 |
iLatestCodeseg = codeSegList->First();
|
|
286 |
}
|
|
287 |
else
|
|
288 |
{
|
|
289 |
iLatestCodeseg = iLatestCodeseg->iNext;
|
|
290 |
}
|
|
291 |
|
|
292 |
// search the global code segment list
|
|
293 |
//for (; iLatestCodeseg!=(SDblQueLink*) codeSegList; iLatestCodeseg=iLatestCodeseg->iNext)
|
|
294 |
if (iLatestCodeseg != (SDblQueLink*) codeSegList)
|
|
295 |
{
|
|
296 |
DCodeSeg* seg = _LOFF(iLatestCodeseg, DCodeSeg, iLink);
|
|
297 |
if(seg != 0)
|
|
298 |
{
|
|
299 |
if( (seg->iMark & 0x80) == 0)
|
|
300 |
{
|
|
301 |
this->sample[0] = seg->iFileName->Length();
|
|
302 |
sampleDescriptor.Append(*(seg->iFileName));
|
|
303 |
sampleDescriptor.Append((TUint8*)&(seg->iRunAddress),4);
|
|
304 |
sampleDescriptor.Append((TUint8*)&(seg->iSize),4);
|
|
305 |
#ifdef ITT_EVENT_HANDLER
|
|
306 |
sampleDescriptor.Append((TUint8*)&(sampleNum),4);
|
|
307 |
//Kern::Printf("EXE2: NM %S : RA:0x%x SZ:0x%x, time: %d",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
|
|
308 |
#else
|
|
309 |
//Kern::Printf("EXE2: NM %S : RA:0x%x SZ:0x%x, time: %d",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
|
|
310 |
#endif
|
|
311 |
seg->iMark = (seg->iMark | 0x80);
|
|
312 |
count++;
|
|
313 |
this->sample[0] = sampleDescriptor.Size();
|
|
314 |
return sampleDescriptor.Size()+1;
|
|
315 |
}
|
|
316 |
else
|
|
317 |
{
|
|
318 |
//Kern::Printf("Already met EXE2: NM %S : RA:0x%x SZ:0x%x, time: %d",seg->iFileName,seg->iRunAddress,seg->iSize, sampleNum);
|
|
319 |
return KErrAlreadyExists;
|
|
320 |
}
|
|
321 |
}
|
|
322 |
}
|
|
323 |
// check if list gone through
|
|
324 |
else //if (count == 0)
|
|
325 |
{
|
|
326 |
iInitialSegsTaken = ETrue;
|
|
327 |
iTimeToSample = false;
|
|
328 |
LOGSTRING("ITT sampler - all initial samples generated!");
|
|
329 |
}
|
|
330 |
return 0;
|
|
331 |
}
|
|
332 |
|
20
|
333 |
// end of file
|