kerneltest/e32test/bench/d_prof.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\bench\d_prof.cpp
       
    15 // LDD for thread time profiling
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #ifndef __WINS__
       
    21 #include "platform.h"
       
    22 #else
       
    23 #include <kernel/kernel.h>
       
    24 #endif
       
    25 #include "d_prof.h"
       
    26 
       
    27 const TInt KMajorVersionNumber=0;
       
    28 const TInt KMinorVersionNumber=1;
       
    29 const TInt KBuildVersionNumber=1;
       
    30 
       
    31 class DProfile;
       
    32 
       
    33 class DProfileFactory : public DLogicalDevice
       
    34 //
       
    35 // Profile LDD factory
       
    36 //
       
    37 	{
       
    38 public:
       
    39 	DProfileFactory();
       
    40 	virtual TInt Install();						//overriding pure virtual
       
    41 	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
       
    42 	virtual DLogicalChannel* CreateL();			//overriding pure virtual
       
    43 	};
       
    44 
       
    45 class DProfile : public DLogicalChannel
       
    46 //
       
    47 // Profile logical channel
       
    48 //
       
    49 	{
       
    50 public:
       
    51 	DProfile(DLogicalDevice* aLogicalDevice);
       
    52 	~DProfile();
       
    53 protected:
       
    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);
       
    58 	};
       
    59 
       
    60 DECLARE_STANDARD_LDD()
       
    61 	{
       
    62     return new DProfileFactory;
       
    63     }
       
    64 
       
    65 DProfileFactory::DProfileFactory()
       
    66 //
       
    67 // Constructor
       
    68 //
       
    69     {
       
    70     iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
       
    71     //iParseMask=0;//No units, no info, no PDD
       
    72     //iUnitsMask=0;//Only one thing
       
    73     }
       
    74 
       
    75 DLogicalChannel* DProfileFactory::CreateL()
       
    76 //
       
    77 // Create a new DProfile on this logical device
       
    78 //
       
    79     {
       
    80     return(new(ELeave) DProfile(this));
       
    81     }
       
    82 
       
    83 TInt DProfileFactory::Install()
       
    84 //
       
    85 // Install the LDD - overriding pure virtual
       
    86 //
       
    87     {
       
    88     TPtrC name=_L("Profile");
       
    89     return(SetName(&name));
       
    90     }
       
    91 
       
    92 void DProfileFactory::GetCaps(TDes8& aDes) const
       
    93 //
       
    94 // Get capabilities - overriding pure virtual
       
    95 //
       
    96     {
       
    97     TCapsProfileV01 b;
       
    98     b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
       
    99     Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
       
   100     }
       
   101 
       
   102 DProfile::DProfile(DLogicalDevice* aLogicalDevice)
       
   103 //
       
   104 // Constructor
       
   105 //
       
   106     : DLogicalChannel(aLogicalDevice)
       
   107     {
       
   108     }
       
   109 
       
   110 void DProfile::DoCreateL(TInt /*aUnit*/,CBase* /*aPdd*/,const TDesC* /*anInfo*/,const TVersion& aVer)
       
   111 //
       
   112 // Create channel
       
   113 //
       
   114     {
       
   115 
       
   116     if (!User::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
       
   117     	User::Leave(KErrNotSupported);
       
   118 	}
       
   119 
       
   120 DProfile::~DProfile()
       
   121 //
       
   122 // Destructor
       
   123 //
       
   124     {
       
   125     }
       
   126 
       
   127 void DProfile::DoCancel(TInt /*aReqNo*/)
       
   128 //
       
   129 // Cancel an outstanding request - overriding pure virtual
       
   130 //
       
   131     {
       
   132 	// not used
       
   133 	}
       
   134 
       
   135 void DProfile::DoRequest(TInt /*aReqNo*/, TAny* /*a1*/, TAny* /*a2*/)
       
   136 //
       
   137 // Asynchronous requests - overriding pure virtual
       
   138 //
       
   139     {
       
   140 	// not used
       
   141     }
       
   142 
       
   143 LOCAL_C void Reset()
       
   144 	{
       
   145 	CObjectCon& threads=*Kern::Threads();
       
   146 	TInt i;
       
   147 	TInt c=threads.Count();
       
   148 	for (i=0; i<c; i++)
       
   149 		{
       
   150 		DPlatThread *pT=(DPlatThread*)threads[i];
       
   151 		pT->iTotalCpuTime=0;
       
   152 		pT->iMaxContinuousCpuTime=0;
       
   153 		pT->iLastYieldTotal=0;
       
   154 		pT->iMaxTimeBeforeYield=0;
       
   155 		}
       
   156 	}
       
   157 
       
   158 LOCAL_C TInt Read(TInt aHandle, TProfileData& aData)
       
   159 	{
       
   160 	DPlatThread *pT=(DPlatThread*)Kern::ThreadFromHandle(aHandle);
       
   161 	if (!pT)
       
   162 		return KErrArgument;
       
   163 	aData.iTotalCpuTime=(pT->iTotalCpuTime * 125)>>6;
       
   164 	aData.iMaxContinuousCpuTime=(pT->iMaxContinuousCpuTime * 125)>>6;
       
   165 	aData.iMaxTimeBeforeYield=(pT->iMaxTimeBeforeYield * 125)>>6;
       
   166 	return KErrNone;
       
   167 	}
       
   168 
       
   169 #if defined(__MARM__)
       
   170 TInt DProfile::DoControl(TInt aFunction, TAny* a1, TAny* a2)
       
   171 	{
       
   172 	TInt r=KErrNone;
       
   173 	switch (aFunction)
       
   174 		{
       
   175 		case RProfile::EControlResetProfile:
       
   176 			Reset();
       
   177 			break;
       
   178 		case RProfile::EControlReadProfile:
       
   179 			r=Read(TInt(a1),*(TProfileData*)a2);
       
   180 			break;
       
   181 		default:
       
   182 			r=KErrNotSupported;
       
   183 			break;
       
   184 		}
       
   185 	return r;
       
   186 	}
       
   187 #else
       
   188 TInt DProfile::DoControl(TInt /*aFunction*/, TAny* /*a1*/, TAny* /*a2*/)
       
   189 	{
       
   190 
       
   191 	return KErrNotSupported;
       
   192 	}
       
   193 #endif
       
   194