sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
// D_FTRACE.CPP
|
sl@0
|
18 |
//
|
sl@0
|
19 |
//
|
sl@0
|
20 |
//
|
sl@0
|
21 |
#include "plat_priv.h"
|
sl@0
|
22 |
#include <kernel/kernel.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "f32trace.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
DMutex* TheTraceMutex = NULL;
|
sl@0
|
27 |
_LIT(KLitTraceMutexName, "FTRACE_MUTEX");
|
sl@0
|
28 |
|
sl@0
|
29 |
const TInt KMajorVersionNumber=1;
|
sl@0
|
30 |
const TInt KMinorVersionNumber=0;
|
sl@0
|
31 |
const TInt KBuildVersionNumber=0;
|
sl@0
|
32 |
|
sl@0
|
33 |
|
sl@0
|
34 |
class DLddFactoryFTrace : public DLogicalDevice
|
sl@0
|
35 |
{
|
sl@0
|
36 |
public:
|
sl@0
|
37 |
DLddFactoryFTrace();
|
sl@0
|
38 |
virtual ~DLddFactoryFTrace();
|
sl@0
|
39 |
virtual TInt Install();
|
sl@0
|
40 |
virtual void GetCaps(TDes8 &aDes) const;
|
sl@0
|
41 |
virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
|
sl@0
|
42 |
};
|
sl@0
|
43 |
|
sl@0
|
44 |
class DLddFTrace : public DLogicalChannelBase
|
sl@0
|
45 |
{
|
sl@0
|
46 |
public:
|
sl@0
|
47 |
DLddFTrace();
|
sl@0
|
48 |
~DLddFTrace();
|
sl@0
|
49 |
protected:
|
sl@0
|
50 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
sl@0
|
51 |
|
sl@0
|
52 |
virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
|
sl@0
|
53 |
|
sl@0
|
54 |
private:
|
sl@0
|
55 |
void DoCancel(TInt aReqNo);
|
sl@0
|
56 |
TInt DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
|
sl@0
|
57 |
TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
|
sl@0
|
58 |
|
sl@0
|
59 |
private:
|
sl@0
|
60 |
};
|
sl@0
|
61 |
|
sl@0
|
62 |
DECLARE_STANDARD_LDD()
|
sl@0
|
63 |
{
|
sl@0
|
64 |
TInt r = Kern::MutexCreate(TheTraceMutex, KLitTraceMutexName, KMutexOrdNone);
|
sl@0
|
65 |
if (r != KErrNone)
|
sl@0
|
66 |
return NULL;
|
sl@0
|
67 |
|
sl@0
|
68 |
return new DLddFactoryFTrace;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
DLddFactoryFTrace::DLddFactoryFTrace()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
|
sl@0
|
74 |
iParseMask=KDeviceAllowUnit; // Pass stack number as unit
|
sl@0
|
75 |
iUnitsMask=0xffffffff;
|
sl@0
|
76 |
iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
TInt DLddFactoryFTrace::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
aChannel=new DLddFTrace;
|
sl@0
|
82 |
return aChannel ? KErrNone : KErrNoMemory;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
TInt DLddFactoryFTrace::Install()
|
sl@0
|
86 |
{
|
sl@0
|
87 |
TPtrC name=_L("FTrace");
|
sl@0
|
88 |
return(SetName(&name));
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
void DLddFactoryFTrace::GetCaps(TDes8& /*aDes*/) const
|
sl@0
|
92 |
{
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
DLddFactoryFTrace::~DLddFactoryFTrace()
|
sl@0
|
96 |
{
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
DLddFTrace::DLddFTrace()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
DLddFTrace::~DLddFTrace()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
TInt DLddFTrace::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
|
sl@0
|
110 |
if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
|
sl@0
|
111 |
return(KErrNotSupported);
|
sl@0
|
112 |
|
sl@0
|
113 |
return(KErrNone);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
void DLddFTrace::DoCancel(TInt /*aReqNo*/)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
TInt DLddFTrace::Request(TInt aReqNo, TAny* a1, TAny* a2)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
NKern::ThreadEnterCS();
|
sl@0
|
123 |
Kern::MutexWait(*TheTraceMutex);
|
sl@0
|
124 |
TInt r = DoControl(aReqNo, a1, a2);
|
sl@0
|
125 |
Kern::MutexSignal(*TheTraceMutex);
|
sl@0
|
126 |
NKern::ThreadLeaveCS();
|
sl@0
|
127 |
|
sl@0
|
128 |
return r;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
|
sl@0
|
132 |
const TUint KTraceBufferSize = 4096;
|
sl@0
|
133 |
TUint8 gTraceBuffer[KTraceBufferSize];
|
sl@0
|
134 |
|
sl@0
|
135 |
|
sl@0
|
136 |
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
sl@0
|
137 |
|
sl@0
|
138 |
TInt DLddFTrace::DoControl(TInt aFunction, TAny* a1, TAny* a2)
|
sl@0
|
139 |
//
|
sl@0
|
140 |
// Mostly requests (but some kernel server async ones)
|
sl@0
|
141 |
//
|
sl@0
|
142 |
{
|
sl@0
|
143 |
TInt r=KErrNotSupported;
|
sl@0
|
144 |
switch (aFunction)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
case RFTrace::ETraceMultiple:
|
sl@0
|
147 |
{
|
sl@0
|
148 |
typedef struct {
|
sl@0
|
149 |
TClassification iCategory;
|
sl@0
|
150 |
TUint8 iPadding1[sizeof(TUint) - sizeof(TClassification)];
|
sl@0
|
151 |
|
sl@0
|
152 |
TFormatId iFormatId;
|
sl@0
|
153 |
TUint8 iPadding2[sizeof(TUint) - sizeof(TFormatId)];
|
sl@0
|
154 |
|
sl@0
|
155 |
TUint32 iUid;
|
sl@0
|
156 |
TInt iDescriptorCount;
|
sl@0
|
157 |
} TraceArgs;
|
sl@0
|
158 |
|
sl@0
|
159 |
TraceArgs args={0};
|
sl@0
|
160 |
|
sl@0
|
161 |
XTRAP(r, XT_DEFAULT, kumemget32(&args, a1, sizeof(args)));
|
sl@0
|
162 |
if (r != KErrNone)
|
sl@0
|
163 |
return r;
|
sl@0
|
164 |
|
sl@0
|
165 |
// current descriptor - MUST be either a TPtr8 or a TBuf8<4>
|
sl@0
|
166 |
TUint32 desc[2] = {0, 0};
|
sl@0
|
167 |
TUint32& desLength = desc[0];
|
sl@0
|
168 |
|
sl@0
|
169 |
TUint offset = 0;
|
sl@0
|
170 |
|
sl@0
|
171 |
*((TUint*) (gTraceBuffer+offset)) = args.iFormatId;
|
sl@0
|
172 |
offset+= sizeof(TUint);
|
sl@0
|
173 |
|
sl@0
|
174 |
TDesC8* des = (TDesC8*) ((TUint8*) a2);
|
sl@0
|
175 |
const TInt desSize = sizeof(TPtrC8);
|
sl@0
|
176 |
for (TInt n=0; n< args.iDescriptorCount; n++, des = (TDesC8*) (((TUint8*) des) + desSize) )
|
sl@0
|
177 |
{
|
sl@0
|
178 |
|
sl@0
|
179 |
XTRAP(r, XT_DEFAULT, kumemget32(desc, des, sizeof(desc)));
|
sl@0
|
180 |
TUint32 desType = desLength >> KShiftDesType;
|
sl@0
|
181 |
desLength &= (TUint) (KMaskDesLength);
|
sl@0
|
182 |
if (desType == EPtrC)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
*((TUint*) (gTraceBuffer+offset)) = desLength;
|
sl@0
|
185 |
desLength = (desLength+3)&~3;
|
sl@0
|
186 |
offset+= sizeof(TUint);
|
sl@0
|
187 |
}
|
sl@0
|
188 |
else if (desType == EBufC)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
*((TUint*) (gTraceBuffer+offset)) = desc[1];
|
sl@0
|
191 |
offset+= sizeof(TUint);
|
sl@0
|
192 |
if (desLength > 4)
|
sl@0
|
193 |
return KErrArgument;
|
sl@0
|
194 |
desLength = 0;
|
sl@0
|
195 |
continue;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
else
|
sl@0
|
198 |
return KErrArgument;
|
sl@0
|
199 |
|
sl@0
|
200 |
TUint len = MIN(KTraceBufferSize - offset, desLength);
|
sl@0
|
201 |
XTRAP(r, XT_DEFAULT, kumemget(gTraceBuffer+offset, (const TUint8*) desc[1], len));
|
sl@0
|
202 |
offset+= len;
|
sl@0
|
203 |
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
BTrace::OutFilteredBig
|
sl@0
|
207 |
(BTRACE_HEADER_C(8,args.iCategory, 0), args.iUid, gTraceBuffer, offset);
|
sl@0
|
208 |
|
sl@0
|
209 |
r=KErrNone;
|
sl@0
|
210 |
break;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
}
|
sl@0
|
213 |
return(r);
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|