kerneltest/e32test/misc/d_testkerncorestats.cpp
changeset 90 947f0dc9f7a8
child 102 ef2a444a7410
equal deleted inserted replaced
52:2d65c2f76d7b 90:947f0dc9f7a8
       
     1 // Copyright (c) 2007-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 "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\misc\d_kerncorestas.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "d_TestKernCoreStats.h"
       
    19 
       
    20 #include <kernel/kernel.h>
       
    21 #include <kernel/kerncorestats.h>
       
    22 
       
    23 
       
    24 class DTestKernCoreStatsFactory : public DLogicalDevice
       
    25         {
       
    26 public:
       
    27         DTestKernCoreStatsFactory();
       
    28         ~DTestKernCoreStatsFactory();
       
    29         virtual TInt Install();
       
    30         virtual void GetCaps(TDes8& aDes) const;
       
    31         virtual TInt Create(DLogicalChannelBase*& aChannel);
       
    32         };
       
    33 
       
    34 class DTestKernCoreStatsChannel : public DLogicalChannelBase
       
    35         {
       
    36 public:
       
    37         DTestKernCoreStatsChannel();
       
    38         virtual ~DTestKernCoreStatsChannel();
       
    39         TInt Request(TInt aFunction, TAny* a1, TAny* a2);
       
    40         virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion&
       
    41 aVer);
       
    42 private:
       
    43 	TInt GetStats(TAny* aBuffer);
       
    44 	TInt Configure(TInt aMode);
       
    45 	TInt DumpInfo();
       
    46 private:
       
    47 	TInt iLength;
       
    48         };
       
    49 
       
    50 
       
    51 DECLARE_STANDARD_LDD()
       
    52         {
       
    53         return new DTestKernCoreStatsFactory;
       
    54         }
       
    55 
       
    56 DTestKernCoreStatsFactory::DTestKernCoreStatsFactory()
       
    57         {
       
    58         }
       
    59 
       
    60 DTestKernCoreStatsFactory::~DTestKernCoreStatsFactory()
       
    61         {
       
    62         }
       
    63 
       
    64 TInt DTestKernCoreStatsFactory::Install()
       
    65         {
       
    66         return SetName(&KTestKernCoreStatsName);
       
    67         }
       
    68 
       
    69 
       
    70 void DTestKernCoreStatsFactory::GetCaps(TDes8&) const
       
    71         {
       
    72         }
       
    73 
       
    74 
       
    75 TInt DTestKernCoreStatsFactory::Create(DLogicalChannelBase*& aChannel)
       
    76         {
       
    77         aChannel=new DTestKernCoreStatsChannel();
       
    78         if(!aChannel)
       
    79                 return KErrNoMemory;
       
    80 
       
    81         return KErrNone;
       
    82         }
       
    83 
       
    84 DTestKernCoreStatsChannel::DTestKernCoreStatsChannel()
       
    85 	{
       
    86 	}
       
    87 
       
    88 
       
    89 DTestKernCoreStatsChannel::~DTestKernCoreStatsChannel()
       
    90 	{
       
    91 	}
       
    92 
       
    93 TInt DTestKernCoreStatsChannel::DoCreate(TInt, const TDesC8*, const TVersion&)
       
    94         {
       
    95         return KErrNone;
       
    96         }
       
    97 
       
    98 TInt DTestKernCoreStatsChannel::Request(TInt aFunction, TAny* a1, TAny*)
       
    99         {
       
   100         switch (aFunction)
       
   101                 {
       
   102                 case RTestKernCoreStats::ERequestGetStats:
       
   103                         return GetStats( (TAny*) a1);
       
   104                 case RTestKernCoreStats::ERequestConfigure:
       
   105                         return Configure( (TInt) a1);
       
   106                 case RTestKernCoreStats::ERequestDumpInfo:
       
   107                         return DumpInfo();
       
   108                 default:
       
   109                         return KErrNotSupported;
       
   110                 }
       
   111         }
       
   112 
       
   113 
       
   114 TInt DTestKernCoreStatsChannel::GetStats(TAny* aBuffer)
       
   115 	{
       
   116 	NKern::ThreadEnterCS();
       
   117 	
       
   118 	if (iLength==0)
       
   119 		return KErrNone;
       
   120 	
       
   121 	TAny* tempBuff = Kern::Alloc(iLength);
       
   122 	if (!tempBuff)
       
   123 		{
       
   124 		NKern::ThreadLeaveCS();
       
   125 		return KErrNoMemory;
       
   126 		}
       
   127 
       
   128 	TInt r = KernCoreStats::Stats(tempBuff);
       
   129 
       
   130 
       
   131 	if (r==KErrNone)
       
   132 		kumemput(aBuffer, tempBuff, iLength);
       
   133 
       
   134 	Kern::Free(tempBuff);
       
   135 	NKern::ThreadLeaveCS();
       
   136 
       
   137 	return r;
       
   138 	}
       
   139 
       
   140 TInt DTestKernCoreStatsChannel::Configure(TInt aMode)
       
   141 	{
       
   142 
       
   143 	NKern::ThreadEnterCS();
       
   144 	TInt cores = NKern::NumberOfCpus();
       
   145 
       
   146 	TInt len = 0;
       
   147 	len+= (aMode & KStatsCoreTotalTimeInIdle)?		sizeof(TUint)*cores :0;
       
   148 	len+= (aMode & KStatsTimeCrossIdleAndActive)?		sizeof(TUint)*(cores+1) :0;
       
   149 	len+= (aMode & KStatsCoreNumTimesInIdle)?		sizeof(TUint)*cores :0;
       
   150 	len+= (aMode & KStatsNumEvents)?			sizeof(TUint) :0;
       
   151 	len+= (aMode & KStatsReadyStateChanges)?		sizeof(TUint)*2:0;
       
   152 	len+= (aMode & KStatsNumTimeSliceExpire)?		sizeof(TUint):0;
       
   153 
       
   154 	iLength=len;
       
   155 	Kern::Printf("KernCoreStats packet length = %d", len);
       
   156 	TInt r =  KernCoreStats::Configure(aMode);
       
   157 	NKern::ThreadLeaveCS();
       
   158 	return r;
       
   159 	}
       
   160 
       
   161 
       
   162 TInt DTestKernCoreStatsChannel::DumpInfo()
       
   163 	{
       
   164 
       
   165 	//KernCoreStats::Engage(0);
       
   166 
       
   167 	return iLength;
       
   168 	}