Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\drivers\trace\btrace.cpp
18 #include <kernel/kern_priv.h>
23 class DBTraceTestFactory : public DLogicalDevice
26 virtual TInt Install();
27 virtual void GetCaps(TDes8& aDes) const;
28 virtual TInt Create(DLogicalChannelBase*& aChannel);
32 class DBTraceTestChannel : public DLogicalChannelBase
36 virtual ~DBTraceTestChannel();
37 // Inherited from DObject
38 virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
39 // Inherited from DLogicalChannelBase
40 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
41 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
45 static void TestTrace(DBTraceTestChannel* aSelf);
46 static void TestUTrace(DBTraceTestChannel* aSelf);
50 TUint32 iTestData[KMaxBTraceRecordSize*2/4];
51 volatile TBool iTimerExpired;
61 TInt DBTraceTestFactory::Install()
63 return SetName(&RBTraceTest::Name());
66 void DBTraceTestFactory::GetCaps(TDes8& aDes) const
68 Kern::InfoCopy(aDes,0,0);
71 TInt DBTraceTestFactory::Create(DLogicalChannelBase*& aChannel)
73 aChannel=new DBTraceTestChannel();
84 DBTraceTestChannel::DBTraceTestChannel()
85 : iTraceTimer((NTimerFn)TestTrace,this),
86 iTraceIDFC((NTimerFn)TestTrace,this)
90 DBTraceTestChannel::~DBTraceTestChannel()
95 TInt DBTraceTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
97 iClient = &Kern::CurrentThread();
102 TInt DBTraceTestChannel::RequestUserHandle(DThread* aThread, TOwnerType aType)
104 if (aType!=EOwnerThread || aThread!=iClient)
105 return KErrAccessDenied;
109 TInt DBTraceTestChannel::Request(TInt aReqNo, TAny* a1, TAny* a2)
114 case RBTraceTest::ETestSpecialTrace:
115 case RBTraceTest::ETestTrace:
117 TPtr8 data((TUint8*)&iTestData,sizeof(iTestData));
118 Kern::KUDesGet(data,*(TDesC8*)a2);
119 iTestDataSize = data.Size()-4;
120 if(aReqNo==RBTraceTest::ETestSpecialTrace)
122 iTestType = (TUint)a1;
123 iTimerExpired = EFalse;
124 if(iTestType&RBTraceTest::EContextIsr)
125 iTraceTimer.OneShot(1);
126 else if(iTestType&RBTraceTest::EContextIDFC)
132 else if(iTestType&RBTraceTest::EContextIntsOff)
134 TInt irq = NKern::DisableAllInterrupts();
136 NKern::RestoreInterrupts(irq);
140 while(!__e32_atomic_load_acq32(&iTimerExpired)) {};
141 return (TInt)NKern::CurrentThread();
145 TInt delay = (TInt)a1/NKern::TickPeriod();
151 iTraceTimer.Cancel();
152 iTraceTimer.OneShot(delay+1);
158 case RBTraceTest::ETestBenchmark:
160 TInt delay = (TInt)a2/NKern::TickPeriod();
161 TInt size = (TInt)a1;
164 // wait for next tick...
165 iTraceTimer.Cancel();
166 iTimerExpired = EFalse;
167 iTraceTimer.OneShot(1);
168 while(!__e32_atomic_load_acq32(&iTimerExpired)) {};
171 iTimerExpired = EFalse;
172 iTraceTimer.OneShot(delay+1);
177 TBool finished = __e32_atomic_load_acq32(&iTimerExpired);
178 BTraceContextN(BTrace::ETest1,0,0,0,&iTestData,size);
187 TBool finished = __e32_atomic_load_acq32(&iTimerExpired);
188 BTrace0(BTrace::ETest1,0);
197 case RBTraceTest::ETestBenchmark2:
199 TInt delay = (TInt)a2/NKern::TickPeriod();
200 TInt size = (TInt)a1;
203 // wait for next tick...
204 iTraceTimer.Cancel();
205 iTimerExpired = EFalse;
206 iTraceTimer.OneShot(1);
207 while(!__e32_atomic_load_acq32(&iTimerExpired)) {};
210 iTimerExpired = EFalse;
211 iTraceTimer.OneShot(delay+1);
216 TBool finished = __e32_atomic_load_acq32(&iTimerExpired);
217 BTraceFilteredContextN(BTrace::ETest1,0,KBTraceFilterTestUid1,0,&iTestData,size);
226 TBool finished = __e32_atomic_load_acq32(&iTimerExpired);
227 BTraceFiltered4(BTrace::ETest1,0,KBTraceFilterTestUid1);
236 case RBTraceTest::ETestBenchmarkCheckFilter:
238 TInt delay = (TInt)a2/NKern::TickPeriod();
240 // wait for next tick...
241 iTraceTimer.Cancel();
242 iTimerExpired = EFalse;
243 iTraceTimer.OneShot(1);
244 while(!__e32_atomic_load_acq32(&iTimerExpired)) {};
247 iTimerExpired = EFalse;
248 iTraceTimer.OneShot(delay+1);
253 TBool finished = __e32_atomic_load_acq32(&iTimerExpired);
254 BTrace::CheckFilter2(BTrace::ETest1,KBTraceFilterTestUid1);
263 TBool finished = __e32_atomic_load_acq32(&iTimerExpired);
264 BTrace::CheckFilter(BTrace::ETest1);
272 case RBTraceTest::ETestUTrace:
274 TPtr8 data((TUint8*)&iTestData,sizeof(iTestData));
275 Kern::KUDesGet(data,*(TDesC8*)a2);
276 iTestDataSize = data.Size()-4;
277 TInt delay = (TInt)a1/NKern::TickPeriod();
283 iTraceTimer.Cancel();
284 iTraceTimer.OneShot(delay+1);
292 return KErrNotSupported;
296 void DBTraceTestChannel::TestTrace(DBTraceTestChannel* aSelf)
298 TInt size = aSelf->iTestDataSize;
301 __e32_atomic_store_rel32(&aSelf->iTimerExpired, 1);
304 TUint32* data = aSelf->iTestData;
305 BTrace::TCategory category = (BTrace::TCategory)((TUint8*)data)[0];
306 TUint subCategory = (BTrace::TCategory)((TUint8*)data)[1];
307 TUint type = aSelf->iTestType&0xff;
308 TBool bigTrace = aSelf->iTestType&RBTraceTest::EBigTrace;
309 TBool filter2Trace = aSelf->iTestType&RBTraceTest::EFilter2Trace;
313 if(type==BTrace::EPcPresent)
317 BTracePcBig(category,subCategory,data[1],data+2,size-4);
318 BTracePcBig(category,subCategory,data[1],data+2,size-4);
322 BTracePc0(category,subCategory);
323 BTracePc0(category,subCategory);
327 BTracePc4(category,subCategory,data[1]);
328 BTracePc4(category,subCategory,data[1]);
332 BTracePc8(category,subCategory,data[1],data[2]);
333 BTracePc8(category,subCategory,data[1],data[2]);
337 BTracePcN(category,subCategory,data[1],data[2],data+3,size-8);
338 BTracePcN(category,subCategory,data[1],data[2],data+3,size-8);
341 else if(type==BTrace::EContextIdPresent)
345 BTraceContextBig(category,subCategory,data[1],data+2,size-4);
346 BTraceContextBig(category,subCategory,data[1],data+2,size-4);
350 BTraceContext0(category,subCategory);
351 BTraceContext0(category,subCategory);
355 BTraceContext4(category,subCategory,data[1]);
356 BTraceContext4(category,subCategory,data[1]);
360 BTraceContext8(category,subCategory,data[1],data[2]);
361 BTraceContext8(category,subCategory,data[1],data[2]);
365 BTraceContextN(category,subCategory,data[1],data[2],data+3,size-8);
366 BTraceContextN(category,subCategory,data[1],data[2],data+3,size-8);
369 else if(type==BTrace::EContextIdPresent+BTrace::EPcPresent)
373 BTraceContextPcBig(category,subCategory,data[1],data+2,size-4);
374 BTraceContextPcBig(category,subCategory,data[1],data+2,size-4);
378 BTraceContextPc0(category,subCategory);
379 BTraceContextPc0(category,subCategory);
383 BTraceContextPc4(category,subCategory,data[1]);
384 BTraceContextPc4(category,subCategory,data[1]);
388 BTraceContextPc8(category,subCategory,data[1],data[2]);
389 BTraceContextPc8(category,subCategory,data[1],data[2]);
393 BTraceContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
394 BTraceContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
400 BTraceBig(category,subCategory,data[1],data+2,size-4);
402 BTrace0(category,subCategory);
404 BTrace4(category,subCategory,data[1]);
406 BTrace8(category,subCategory,data[1],data[2]);
408 BTraceN(category,subCategory,data[1],data[2],data+3,size-8);
413 if(type==BTrace::EPcPresent)
417 BTraceFilteredPcBig(category,subCategory,data[1],data+2,size-4);
418 BTraceFilteredPcBig(category,subCategory,data[1],data+2,size-4);
426 BTraceFilteredPc4(category,subCategory,data[1]);
427 BTraceFilteredPc4(category,subCategory,data[1]);
431 BTraceFilteredPc8(category,subCategory,data[1],data[2]);
432 BTraceFilteredPc8(category,subCategory,data[1],data[2]);
436 BTraceFilteredPcN(category,subCategory,data[1],data[2],data+3,size-8);
437 BTraceFilteredPcN(category,subCategory,data[1],data[2],data+3,size-8);
440 else if(type==BTrace::EContextIdPresent)
444 BTraceFilteredContextBig(category,subCategory,data[1],data+2,size-4);
445 BTraceFilteredContextBig(category,subCategory,data[1],data+2,size-4);
453 BTraceFilteredContext4(category,subCategory,data[1]);
454 BTraceFilteredContext4(category,subCategory,data[1]);
458 BTraceFilteredContext8(category,subCategory,data[1],data[2]);
459 BTraceFilteredContext8(category,subCategory,data[1],data[2]);
463 BTraceFilteredContextN(category,subCategory,data[1],data[2],data+3,size-8);
464 BTraceFilteredContextN(category,subCategory,data[1],data[2],data+3,size-8);
467 else if(type==BTrace::EContextIdPresent+BTrace::EPcPresent)
471 BTraceFilteredContextPcBig(category,subCategory,data[1],data+2,size-4);
472 BTraceFilteredContextPcBig(category,subCategory,data[1],data+2,size-4);
480 BTraceFilteredContextPc4(category,subCategory,data[1]);
481 BTraceFilteredContextPc4(category,subCategory,data[1]);
485 BTraceFilteredContextPc8(category,subCategory,data[1],data[2]);
486 BTraceFilteredContextPc8(category,subCategory,data[1],data[2]);
490 BTraceFilteredContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
491 BTraceFilteredContextPcN(category,subCategory,data[1],data[2],data+3,size-8);
497 BTraceFilteredBig(category,subCategory,data[1],data+2,size-4);
503 BTraceFiltered4(category,subCategory,data[1]);
505 BTraceFiltered8(category,subCategory,data[1],data[2]);
507 BTraceFilteredN(category,subCategory,data[1],data[2],data+3,size-8);
510 __e32_atomic_store_rel32(&aSelf->iTimerExpired, 1);
513 void DBTraceTestChannel::TestUTrace(DBTraceTestChannel* aSelf)
515 aSelf->iTimerExpired = ETrue;
516 TInt size = aSelf->iTestDataSize;
519 TUint32* data = aSelf->iTestData;
520 BTrace::TCategory category = (BTrace::TCategory)((TUint8*)data)[0];
521 TUint subCategory = (BTrace::TCategory)((TUint8*)data)[1];
523 #define T_UTRACE_HEADER(aSize,aClassification,aContext,aPc) \
524 ((((aSize) + (aContext?4:0) + (aPc?4:0)) << BTrace::ESizeIndex*8) \
525 +(((aContext?BTrace::EContextIdPresent:0) | (aPc?BTrace::EPcPresent:0)) << BTrace::EFlagsIndex*8) \
526 +((aClassification) << BTrace::ECategoryIndex*8) \
527 +((subCategory) << BTrace::ESubCategoryIndex*8))
529 #define UTRACE_SECONDARY(aClassification,aModuleUid,aThreadIdPresent,aPcPresent,aPc,aFormatId) \
530 BTrace::OutFilteredPcFormatBig(T_UTRACE_HEADER(8,aClassification,aThreadIdPresent,aPcPresent),(TUint32)(aModuleUid),aPc,aFormatId,0,0)
532 #define UTRACE_SECONDARY_4(aClassification,aModuleUid,aThreadIdPresent,aPcPresent,aPc,aFormatId, aData1) \
533 BTrace::OutFilteredPcFormatBig(T_UTRACE_HEADER(8,aClassification,aThreadIdPresent,aPcPresent),(TUint32)(aModuleUid),aPc,aFormatId,&aData1,4)
535 #define UTRACE_SECONDARY_ANY(aClassification, aModuleUid, aThreadIdPresent, aPcPresent, aPc, aFormatId, aData, aDataSize) \
536 BTrace::OutFilteredPcFormatBig(T_UTRACE_HEADER(8,aClassification,aThreadIdPresent,aPcPresent),(TUint32)(aModuleUid),aPc,aFormatId,aData,(TInt)(aDataSize))
539 TUint32 KUtracePcValues[3]={0, 0x123456, 0x987654};
540 TUint16 formatId = (TUint16)data[2];
541 TUint type = aSelf->iTestType&0xff;
542 if(type == BTrace::EPcPresent)
546 UTRACE_SECONDARY(category, data[1], EFalse, ETrue, KUtracePcValues[1], formatId);
547 UTRACE_SECONDARY(category, data[1], EFalse, ETrue, KUtracePcValues[2], formatId);
551 UTRACE_SECONDARY_4(category, data[1], EFalse, ETrue, KUtracePcValues[1], formatId, data[3]);
552 UTRACE_SECONDARY_4(category, data[1], EFalse, ETrue, KUtracePcValues[2], formatId, data[3]);
556 UTRACE_SECONDARY_ANY(category, data[1], EFalse, ETrue, KUtracePcValues[1], formatId, data+3, size);
557 UTRACE_SECONDARY_ANY(category, data[1], EFalse, ETrue, KUtracePcValues[2], formatId, data+3, size);
560 else if(type==BTrace::EContextIdPresent)
564 UTRACE_SECONDARY(category, data[1], ETrue, EFalse, KUtracePcValues[1], formatId);
565 UTRACE_SECONDARY(category, data[1], ETrue, EFalse, KUtracePcValues[2], formatId);
569 UTRACE_SECONDARY_4(category, data[1], ETrue, EFalse, KUtracePcValues[1], formatId, data[3]);
570 UTRACE_SECONDARY_4(category, data[1], ETrue, EFalse, KUtracePcValues[2], formatId, data[3]);
574 UTRACE_SECONDARY_ANY(category, data[1], ETrue, EFalse, KUtracePcValues[1], formatId, data+3, size);
575 UTRACE_SECONDARY_ANY(category, data[1], ETrue, EFalse, KUtracePcValues[2], formatId, data+3, size);
578 else if(type==BTrace::EContextIdPresent+BTrace::EPcPresent)
582 UTRACE_SECONDARY(category, data[1], ETrue, ETrue, KUtracePcValues[1], formatId);
583 UTRACE_SECONDARY(category, data[1], ETrue, ETrue, KUtracePcValues[2], formatId);
587 UTRACE_SECONDARY_4(category, data[1], ETrue, ETrue, KUtracePcValues[1], formatId, data[3]);
588 UTRACE_SECONDARY_4(category, data[1], ETrue, ETrue, KUtracePcValues[2], formatId, data[3]);
592 UTRACE_SECONDARY_ANY(category, data[1], ETrue, ETrue, KUtracePcValues[1], formatId, data+3, size);
593 UTRACE_SECONDARY_ANY(category, data[1], ETrue, ETrue, KUtracePcValues[2], formatId, data+3, size);
600 UTRACE_SECONDARY(category, data[1], EFalse, EFalse, KUtracePcValues[1], formatId);
601 UTRACE_SECONDARY(category, data[1], EFalse, EFalse, KUtracePcValues[2], formatId);
605 UTRACE_SECONDARY_4(category, data[1], EFalse, EFalse, KUtracePcValues[1], formatId, data[3]);
606 UTRACE_SECONDARY_4(category, data[1], EFalse, EFalse, KUtracePcValues[2], formatId, data[3]);
610 UTRACE_SECONDARY_ANY(category, data[1], EFalse, EFalse, KUtracePcValues[1], formatId, data+3, size);
611 UTRACE_SECONDARY_ANY(category, data[1], EFalse, EFalse, KUtracePcValues[2], formatId, data+3, size);
617 DECLARE_STANDARD_LDD()
619 return new DBTraceTestFactory;