Update contrib.
1 // Copyright (c) 1997-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 // e32test\bench\d_prof.cpp
15 // LDD for thread time profiling
23 #include <kernel/kernel.h>
27 const TInt KMajorVersionNumber=0;
28 const TInt KMinorVersionNumber=1;
29 const TInt KBuildVersionNumber=1;
33 class DProfileFactory : public DLogicalDevice
35 // Profile LDD factory
40 virtual TInt Install(); //overriding pure virtual
41 virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
42 virtual DLogicalChannel* CreateL(); //overriding pure virtual
45 class DProfile : public DLogicalChannel
47 // Profile logical channel
51 DProfile(DLogicalDevice* aLogicalDevice);
54 virtual void DoCancel(TInt aReqNo); //overriding pure virtual
55 virtual void DoRequest(TInt aReqNo,TAny* a1,TAny* a2); //overriding pure virtual
56 virtual void DoCreateL(TInt aUnit,CBase* aPdd,const TDesC* anInfo,const TVersion& aVer);
57 virtual TInt DoControl(TInt aFunction,TAny *a1,TAny *a2);
60 DECLARE_STANDARD_LDD()
62 return new DProfileFactory;
65 DProfileFactory::DProfileFactory()
70 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
71 //iParseMask=0;//No units, no info, no PDD
72 //iUnitsMask=0;//Only one thing
75 DLogicalChannel* DProfileFactory::CreateL()
77 // Create a new DProfile on this logical device
80 return(new(ELeave) DProfile(this));
83 TInt DProfileFactory::Install()
85 // Install the LDD - overriding pure virtual
88 TPtrC name=_L("Profile");
89 return(SetName(&name));
92 void DProfileFactory::GetCaps(TDes8& aDes) const
94 // Get capabilities - overriding pure virtual
98 b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
99 Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
102 DProfile::DProfile(DLogicalDevice* aLogicalDevice)
106 : DLogicalChannel(aLogicalDevice)
110 void DProfile::DoCreateL(TInt /*aUnit*/,CBase* /*aPdd*/,const TDesC* /*anInfo*/,const TVersion& aVer)
116 if (!User::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
117 User::Leave(KErrNotSupported);
120 DProfile::~DProfile()
127 void DProfile::DoCancel(TInt /*aReqNo*/)
129 // Cancel an outstanding request - overriding pure virtual
135 void DProfile::DoRequest(TInt /*aReqNo*/, TAny* /*a1*/, TAny* /*a2*/)
137 // Asynchronous requests - overriding pure virtual
145 CObjectCon& threads=*Kern::Threads();
147 TInt c=threads.Count();
150 DPlatThread *pT=(DPlatThread*)threads[i];
152 pT->iMaxContinuousCpuTime=0;
153 pT->iLastYieldTotal=0;
154 pT->iMaxTimeBeforeYield=0;
158 LOCAL_C TInt Read(TInt aHandle, TProfileData& aData)
160 DPlatThread *pT=(DPlatThread*)Kern::ThreadFromHandle(aHandle);
163 aData.iTotalCpuTime=(pT->iTotalCpuTime * 125)>>6;
164 aData.iMaxContinuousCpuTime=(pT->iMaxContinuousCpuTime * 125)>>6;
165 aData.iMaxTimeBeforeYield=(pT->iMaxTimeBeforeYield * 125)>>6;
169 #if defined(__MARM__)
170 TInt DProfile::DoControl(TInt aFunction, TAny* a1, TAny* a2)
175 case RProfile::EControlResetProfile:
178 case RProfile::EControlReadProfile:
179 r=Read(TInt(a1),*(TProfileData*)a2);
188 TInt DProfile::DoControl(TInt /*aFunction*/, TAny* /*a1*/, TAny* /*a2*/)
191 return KErrNotSupported;