|
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 { |
|
38 //Kern::Printf("DIttEventHandler::DIttEventHandler()"); |
|
39 |
|
40 } |
|
41 |
|
42 /* |
|
43 * DIttEventHandler::Create() |
|
44 */ |
|
45 TInt DIttEventHandler::Create() |
|
46 { |
|
47 Kern::Printf("DIttEventHandler::Create()"); |
|
48 |
|
49 TInt err(Kern::MutexCreate(iLock, _L("IttEventHandlerLock"), KMutexOrdDebug)); |
|
50 if (err != KErrNone) |
|
51 return err; |
|
52 |
|
53 return Add(); |
|
54 } |
|
55 |
|
56 /* |
|
57 * Destructor |
|
58 */ |
|
59 DIttEventHandler::~DIttEventHandler() |
|
60 { |
|
61 //Kern::Printf("DIttEventHandler::~DIttEventHandler()"); |
|
62 |
|
63 if (iLock) |
|
64 iLock->Close(NULL); |
|
65 } |
|
66 |
|
67 |
|
68 TInt DIttEventHandler::Start() |
|
69 { |
|
70 //Kern::Printf("DIttEventHandler::Start()"); |
|
71 |
|
72 iTracking = ETrue; |
|
73 return KErrNone; |
|
74 } |
|
75 |
|
76 |
|
77 TInt DIttEventHandler::Stop() |
|
78 { |
|
79 //Kern::Printf("DIttEventHandler::Stop()"); |
|
80 |
|
81 iTracking = EFalse; |
|
82 return KErrNone; |
|
83 } |
|
84 |
|
85 TBool DIttEventHandler::SampleNeeded() |
|
86 { |
|
87 LOGTEXT("DIttEventHandler::SampleNeeded()"); |
|
88 |
|
89 // increase the counter by one on each round |
|
90 iCount++; |
|
91 |
|
92 // check if event handler was not running |
|
93 if(!iTracking) |
|
94 return false; |
|
95 |
|
96 return true; |
|
97 } |
|
98 |
|
99 |
|
100 TUint DIttEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis) |
|
101 { |
|
102 //Kern::Printf("DIttEventHandler::EventHandler()"); |
|
103 return ((DIttEventHandler*)aThis)->HandleEvent(aType, a1, a2); |
|
104 } |
|
105 |
|
106 |
|
107 |
|
108 TUint DIttEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2) |
|
109 { |
|
110 //Kern::Printf("DIttEventHandler::HandleEvent()"); |
|
111 //Kern::Printf("New kernel event received, %d", aType); |
|
112 |
|
113 if (iTracking/* && iCount != iPreviousCount*/) |
|
114 { |
|
115 switch (aType) |
|
116 { |
|
117 |
|
118 case EEventAddCodeSeg: |
|
119 //Kern::Printf("DCodeSeg added: 0x%08x", (DCodeSeg*)a1); |
|
120 HandleAddCodeSeg((DCodeSeg*)a1); |
|
121 break; |
|
122 |
|
123 case EEventRemoveCodeSeg: |
|
124 //Kern::Printf("DCodeSeg deleted: 0x%08x", (DCodeSeg*)a1); |
|
125 HandleRemoveCodeSeg((DCodeSeg*)a1); |
|
126 break; |
|
127 |
|
128 default: |
|
129 break; |
|
130 } |
|
131 } |
|
132 // else if(iTracking && iCount == iPreviousCount) |
|
133 // { |
|
134 // // if time stamp is not updated profiling has stopped |
|
135 // Stop(); |
|
136 // } |
|
137 return DKernelEventHandler::ERunNext; |
|
138 } |
|
139 |
|
140 /* |
|
141 * |
|
142 */ |
|
143 TBool DIttEventHandler::HandleAddCodeSeg(DCodeSeg* aSeg) |
|
144 { |
|
145 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 |
|
148 iSample[0] = aSeg->iFileName->Length(); |
|
149 iSampleDescriptor.Append(*aSeg->iFileName); |
|
150 iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4); |
|
151 iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4); |
|
152 iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4); |
|
153 iSample[0] = iSampleDescriptor.Size(); |
|
154 |
|
155 iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1); |
|
156 return ETrue; |
|
157 } |
|
158 |
|
159 TBool DIttEventHandler::HandleRemoveCodeSeg(DCodeSeg* aSeg) |
|
160 { |
|
161 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); |
|
163 |
|
164 iSample[0] = aSeg->iFileName->Length(); |
|
165 iSampleDescriptor.Append(*aSeg->iFileName); |
|
166 iSampleDescriptor.Append((TUint8*)&(aSeg->iRunAddress),4); |
|
167 iSampleDescriptor.Append((TUint8*)&(aSeg->iSize),4); |
|
168 iSampleDescriptor.Append((TUint8*)&(this->gppSamplerData->sampleNumber),4); |
|
169 iSample[0] = iSampleDescriptor.Size(); |
|
170 |
|
171 iSampleBuffer->AddSample(iSample,iSampleDescriptor.Size()+1); |
|
172 return ETrue; |
|
173 } |
|
174 // end of file |