os/kernelhwsrv/kerneltest/e32test/bench/d_prof.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/bench/d_prof.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,194 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\bench\d_prof.cpp
    1.18 +// LDD for thread time profiling
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +
    1.23 +#ifndef __WINS__
    1.24 +#include "platform.h"
    1.25 +#else
    1.26 +#include <kernel/kernel.h>
    1.27 +#endif
    1.28 +#include "d_prof.h"
    1.29 +
    1.30 +const TInt KMajorVersionNumber=0;
    1.31 +const TInt KMinorVersionNumber=1;
    1.32 +const TInt KBuildVersionNumber=1;
    1.33 +
    1.34 +class DProfile;
    1.35 +
    1.36 +class DProfileFactory : public DLogicalDevice
    1.37 +//
    1.38 +// Profile LDD factory
    1.39 +//
    1.40 +	{
    1.41 +public:
    1.42 +	DProfileFactory();
    1.43 +	virtual TInt Install();						//overriding pure virtual
    1.44 +	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
    1.45 +	virtual DLogicalChannel* CreateL();			//overriding pure virtual
    1.46 +	};
    1.47 +
    1.48 +class DProfile : public DLogicalChannel
    1.49 +//
    1.50 +// Profile logical channel
    1.51 +//
    1.52 +	{
    1.53 +public:
    1.54 +	DProfile(DLogicalDevice* aLogicalDevice);
    1.55 +	~DProfile();
    1.56 +protected:
    1.57 +	virtual void DoCancel(TInt aReqNo);						//overriding pure virtual
    1.58 +	virtual void DoRequest(TInt aReqNo,TAny* a1,TAny* a2);	//overriding pure virtual
    1.59 +	virtual void DoCreateL(TInt aUnit,CBase* aPdd,const TDesC* anInfo,const TVersion& aVer);
    1.60 +	virtual TInt DoControl(TInt aFunction,TAny *a1,TAny *a2);
    1.61 +	};
    1.62 +
    1.63 +DECLARE_STANDARD_LDD()
    1.64 +	{
    1.65 +    return new DProfileFactory;
    1.66 +    }
    1.67 +
    1.68 +DProfileFactory::DProfileFactory()
    1.69 +//
    1.70 +// Constructor
    1.71 +//
    1.72 +    {
    1.73 +    iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
    1.74 +    //iParseMask=0;//No units, no info, no PDD
    1.75 +    //iUnitsMask=0;//Only one thing
    1.76 +    }
    1.77 +
    1.78 +DLogicalChannel* DProfileFactory::CreateL()
    1.79 +//
    1.80 +// Create a new DProfile on this logical device
    1.81 +//
    1.82 +    {
    1.83 +    return(new(ELeave) DProfile(this));
    1.84 +    }
    1.85 +
    1.86 +TInt DProfileFactory::Install()
    1.87 +//
    1.88 +// Install the LDD - overriding pure virtual
    1.89 +//
    1.90 +    {
    1.91 +    TPtrC name=_L("Profile");
    1.92 +    return(SetName(&name));
    1.93 +    }
    1.94 +
    1.95 +void DProfileFactory::GetCaps(TDes8& aDes) const
    1.96 +//
    1.97 +// Get capabilities - overriding pure virtual
    1.98 +//
    1.99 +    {
   1.100 +    TCapsProfileV01 b;
   1.101 +    b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
   1.102 +    Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
   1.103 +    }
   1.104 +
   1.105 +DProfile::DProfile(DLogicalDevice* aLogicalDevice)
   1.106 +//
   1.107 +// Constructor
   1.108 +//
   1.109 +    : DLogicalChannel(aLogicalDevice)
   1.110 +    {
   1.111 +    }
   1.112 +
   1.113 +void DProfile::DoCreateL(TInt /*aUnit*/,CBase* /*aPdd*/,const TDesC* /*anInfo*/,const TVersion& aVer)
   1.114 +//
   1.115 +// Create channel
   1.116 +//
   1.117 +    {
   1.118 +
   1.119 +    if (!User::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
   1.120 +    	User::Leave(KErrNotSupported);
   1.121 +	}
   1.122 +
   1.123 +DProfile::~DProfile()
   1.124 +//
   1.125 +// Destructor
   1.126 +//
   1.127 +    {
   1.128 +    }
   1.129 +
   1.130 +void DProfile::DoCancel(TInt /*aReqNo*/)
   1.131 +//
   1.132 +// Cancel an outstanding request - overriding pure virtual
   1.133 +//
   1.134 +    {
   1.135 +	// not used
   1.136 +	}
   1.137 +
   1.138 +void DProfile::DoRequest(TInt /*aReqNo*/, TAny* /*a1*/, TAny* /*a2*/)
   1.139 +//
   1.140 +// Asynchronous requests - overriding pure virtual
   1.141 +//
   1.142 +    {
   1.143 +	// not used
   1.144 +    }
   1.145 +
   1.146 +LOCAL_C void Reset()
   1.147 +	{
   1.148 +	CObjectCon& threads=*Kern::Threads();
   1.149 +	TInt i;
   1.150 +	TInt c=threads.Count();
   1.151 +	for (i=0; i<c; i++)
   1.152 +		{
   1.153 +		DPlatThread *pT=(DPlatThread*)threads[i];
   1.154 +		pT->iTotalCpuTime=0;
   1.155 +		pT->iMaxContinuousCpuTime=0;
   1.156 +		pT->iLastYieldTotal=0;
   1.157 +		pT->iMaxTimeBeforeYield=0;
   1.158 +		}
   1.159 +	}
   1.160 +
   1.161 +LOCAL_C TInt Read(TInt aHandle, TProfileData& aData)
   1.162 +	{
   1.163 +	DPlatThread *pT=(DPlatThread*)Kern::ThreadFromHandle(aHandle);
   1.164 +	if (!pT)
   1.165 +		return KErrArgument;
   1.166 +	aData.iTotalCpuTime=(pT->iTotalCpuTime * 125)>>6;
   1.167 +	aData.iMaxContinuousCpuTime=(pT->iMaxContinuousCpuTime * 125)>>6;
   1.168 +	aData.iMaxTimeBeforeYield=(pT->iMaxTimeBeforeYield * 125)>>6;
   1.169 +	return KErrNone;
   1.170 +	}
   1.171 +
   1.172 +#if defined(__MARM__)
   1.173 +TInt DProfile::DoControl(TInt aFunction, TAny* a1, TAny* a2)
   1.174 +	{
   1.175 +	TInt r=KErrNone;
   1.176 +	switch (aFunction)
   1.177 +		{
   1.178 +		case RProfile::EControlResetProfile:
   1.179 +			Reset();
   1.180 +			break;
   1.181 +		case RProfile::EControlReadProfile:
   1.182 +			r=Read(TInt(a1),*(TProfileData*)a2);
   1.183 +			break;
   1.184 +		default:
   1.185 +			r=KErrNotSupported;
   1.186 +			break;
   1.187 +		}
   1.188 +	return r;
   1.189 +	}
   1.190 +#else
   1.191 +TInt DProfile::DoControl(TInt /*aFunction*/, TAny* /*a1*/, TAny* /*a2*/)
   1.192 +	{
   1.193 +
   1.194 +	return KErrNotSupported;
   1.195 +	}
   1.196 +#endif
   1.197 +