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: Event based ITT sampler skeleton copypasted from MemoryEventHandler.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32def.h>
|
|
19 |
#include <e32cmn.h>
|
|
20 |
#include <arm.h>
|
|
21 |
#include <kernel.h>
|
|
22 |
#include <kern_priv.h>
|
|
23 |
#include <nk_trace.h>
|
|
24 |
|
|
25 |
#include "IttEventHandler.h"
|
|
26 |
|
|
27 |
/*
|
|
28 |
* Constructor
|
|
29 |
*
|
|
30 |
* @param DProfilerSampleBuffer* pointer to sample buffer
|
|
31 |
*/
|
|
32 |
DIttEventHandler::DIttEventHandler(DProfilerSampleBuffer* aSampleBuffer, TProfilerGppSamplerData* aGppSamplerDataIn)
|
|
33 |
: DKernelEventHandler(EventHandler, this),
|
|
34 |
iSampleBuffer(aSampleBuffer),
|
|
35 |
iSampleDescriptor(&(this->iSample[1]),0,KITTBufferSize),
|
|
36 |
gppSamplerData(aGppSamplerDataIn)
|
|
37 |
{
|
62
|
38 |
iSampleAvailable = false;
|
20
|
39 |
}
|
|
40 |
|
|
41 |
/*
|
|
42 |
* DIttEventHandler::Create()
|
|
43 |
*/
|
|
44 |
TInt DIttEventHandler::Create()
|
|
45 |
{
|
|
46 |
TInt err(Kern::MutexCreate(iLock, _L("IttEventHandlerLock"), KMutexOrdDebug));
|
|
47 |
if (err != KErrNone)
|
|
48 |
return err;
|
|
49 |
|
|
50 |
return Add();
|
|
51 |
}
|
|
52 |
|
|
53 |
/*
|
|
54 |
* Destructor
|
|
55 |
*/
|
|
56 |
DIttEventHandler::~DIttEventHandler()
|
|
57 |
{
|
62
|
58 |
LOGSTRING("DIttEventHandler::~DIttEventHandler()");
|
20
|
59 |
|
|
60 |
if (iLock)
|
|
61 |
iLock->Close(NULL);
|
|
62 |
}
|
|
63 |
|
|
64 |
|
|
65 |
TInt DIttEventHandler::Start()
|
|
66 |
{
|
62
|
67 |
LOGSTRING("DIttEventHandler::Start()");
|
20
|
68 |
|
|
69 |
iTracking = ETrue;
|
|
70 |
return KErrNone;
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
TInt DIttEventHandler::Stop()
|
|
75 |
{
|
62
|
76 |
LOGSTRING("DIttEventHandler::Stop()");
|
20
|
77 |
|
|
78 |
iTracking = EFalse;
|
62
|
79 |
LOGSTRING2("ITT - gpp sample counter %d", this->gppSamplerData->sampleNumber);
|
20
|
80 |
return KErrNone;
|
|
81 |
}
|
|
82 |
|
|
83 |
TBool DIttEventHandler::SampleNeeded()
|
|
84 |
{
|
62
|
85 |
//LOGSTRING("DIttEventHandler::SampleNeeded()");
|
20
|
86 |
|
|
87 |
// check if event handler was not running
|
|
88 |
if(!iTracking)
|
62
|
89 |
{
|
|
90 |
return false;
|
|
91 |
}
|
|
92 |
// check if a new sample is available
|
|
93 |
if(iSampleAvailable)
|
|
94 |
{
|
|
95 |
return true;
|
|
96 |
}
|
|
97 |
else
|
|
98 |
{
|
|
99 |
return false;
|
|
100 |
}
|
20
|
101 |
}
|
|
102 |
|
62
|
103 |
void DIttEventHandler::SampleHandled()
|
|
104 |
{
|
|
105 |
iSampleAvailable = false;
|
|
106 |
}
|
20
|
107 |
|
|
108 |
TUint DIttEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis)
|
|
109 |
{
|
62
|
110 |
//LOGSTRING("DIttEventHandler::EventHandler()");
|
20
|
111 |
return ((DIttEventHandler*)aThis)->HandleEvent(aType, a1, a2);
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
TUint DIttEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
|
|
117 |
{
|
|
118 |
|
62
|
119 |
if (iTracking)
|
20
|
120 |
{
|
|
121 |
switch (aType)
|
|
122 |
{
|
|
123 |
case EEventAddCodeSeg:
|
62
|
124 |
LOGSTRING("DIttEventHandler::HandleEvent() EEventAddCodeSeg received");
|
20
|
125 |
HandleAddCodeSeg((DCodeSeg*)a1);
|
|
126 |
break;
|
|
127 |
|
|
128 |
case EEventRemoveCodeSeg:
|
62
|
129 |
LOGSTRING("DIttEventHandler::HandleEvent() EEventRemoveCodeSeg received");
|
20
|
130 |
HandleRemoveCodeSeg((DCodeSeg*)a1);
|
|
131 |
break;
|
|
132 |
|
|
133 |
default:
|
|
134 |
break;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
return DKernelEventHandler::ERunNext;
|
|
138 |
}
|
|
139 |
|
|
140 |
/*
|
|
141 |
*
|
|
142 |
*/
|
|
143 |
TBool DIttEventHandler::HandleAddCodeSeg(DCodeSeg* aSeg)
|
|
144 |
{
|
62
|
145 |
LOGSTRING("DIttEventHandler::HandleAddCodeSeg()");
|
20
|
146 |
iSampleDescriptor.Zero();
|
|
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);
|
|
148 |
|
62
|
149 |
NKern::ThreadEnterCS();
|
|
150 |
Kern::MutexWait(*iLock);
|
20
|
151 |
iSample[0] = aSeg->iFileName->Length();
|
|
152 |
iSampleDescriptor.Append(*aSeg->iFileName);
|
|
153 |
iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4);
|
|
154 |
iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4);
|
|
155 |
iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4);
|
|
156 |
iSample[0] = iSampleDescriptor.Size();
|
62
|
157 |
|
|
158 |
iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1);
|
|
159 |
Kern::MutexSignal(*iLock);
|
|
160 |
NKern::ThreadLeaveCS();
|
20
|
161 |
|
62
|
162 |
iSampleAvailable = true;
|
20
|
163 |
return ETrue;
|
|
164 |
}
|
|
165 |
|
|
166 |
TBool DIttEventHandler::HandleRemoveCodeSeg(DCodeSeg* aSeg)
|
|
167 |
{
|
62
|
168 |
LOGSTRING("DIttEventHandler::HandleRemoveCodeSeg()");
|
20
|
169 |
iSampleDescriptor.Zero();
|
|
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);
|
|
171 |
|
62
|
172 |
NKern::ThreadEnterCS();
|
|
173 |
Kern::MutexWait(*iLock);
|
|
174 |
|
20
|
175 |
iSample[0] = aSeg->iFileName->Length();
|
|
176 |
iSampleDescriptor.Append(*aSeg->iFileName);
|
|
177 |
iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4);
|
|
178 |
iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4);
|
|
179 |
iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4);
|
|
180 |
iSample[0] = iSampleDescriptor.Size();
|
62
|
181 |
|
20
|
182 |
iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1);
|
62
|
183 |
Kern::MutexSignal(*iLock);
|
|
184 |
NKern::ThreadLeaveCS();
|
|
185 |
|
|
186 |
iSampleAvailable = true;
|
20
|
187 |
return ETrue;
|
|
188 |
}
|
|
189 |
// end of file
|