kerneltest/e32test/misc/cpumeter.cpp
branchRCL_3
changeset 44 3e88ff8f41d5
parent 43 c1f20ce4abcf
equal deleted inserted replaced
43:c1f20ce4abcf 44:3e88ff8f41d5
    46 	~CCpuMeter();
    46 	~CCpuMeter();
    47 	static CCpuMeter* New();
    47 	static CCpuMeter* New();
    48 	TInt Construct();
    48 	TInt Construct();
    49 	void Measure();
    49 	void Measure();
    50 	void Display(TInt aInterval);
    50 	void Display(TInt aInterval);
    51 	void DisplayCoreControlInfo();
       
    52 	void ChangeNumberOfCores(TInt aNum);
       
    53 public:
    51 public:
    54 	TInt iNumCpus;
    52 	TInt iNumCpus;
    55 	TInt iNextMeas;
    53 	TInt iNextMeas;
    56 	RThread* iNullThreads;
    54 	RThread* iNullThreads;
    57 	TTimeIntervalMicroSeconds* iMeas[2];
    55 	TTimeIntervalMicroSeconds* iMeas[2];
   152 		}
   150 		}
   153 	buf.Append(TChar('\n'));
   151 	buf.Append(TChar('\n'));
   154 	test.Printf(buf);
   152 	test.Printf(buf);
   155 	}
   153 	}
   156 
   154 
   157 void CCpuMeter::DisplayCoreControlInfo()
       
   158 	{
       
   159 	SCpuStates s;
       
   160 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalCpuStates, &s, 0);
       
   161 	if (r != KErrNone)
       
   162 		{
       
   163 		test.Printf(_L("Error %d\n"), r);
       
   164 		return;
       
   165 		}
       
   166 	test.SetLogged(ETrue);
       
   167 	test.Printf(_L("  TA=%08x IA=%08x CU=%08x GD=%08x DC=%08x\n"), s.iTA, s.iIA, s.iCU, s.iGD, s.iDC);
       
   168 	test.Printf(_L("  SC=%08x RC=%08x PO=%02x      CCS=%08x PODC=%08x\n"), s.iSC, s.iRC, s.iPO, s.iCCS, s.iPODC);
       
   169 	TInt i;
       
   170 	for (i=0; i<iNumCpus; ++i)
       
   171 		{
       
   172 		test.Printf(_L("%1d:DS=%08x UDC=%08x UAC=%08x OP=%08x F=%08x\n"), i, s.iDS[i], s.iUDC[i], s.iUAC[i], s.iOP[i], s.iF[i]);
       
   173 		}
       
   174 	test.SetLogged(EFalse);
       
   175 	}
       
   176 
       
   177 void CCpuMeter::ChangeNumberOfCores(TInt aNum)
       
   178 	{
       
   179 	test.SetLogged(ETrue);
       
   180 	test.Printf(_L("#CORES->%d\n"), aNum);
       
   181 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalSetNumberOfCpus, (TAny*)aNum, 0);
       
   182 	if (r != KErrNone)
       
   183 		{
       
   184 		test.Printf(_L("Error %d\n"), r);
       
   185 		}
       
   186 	test.SetLogged(EFalse);
       
   187 	}
       
   188 
       
   189 void UseKernelCpuTime()
   155 void UseKernelCpuTime()
   190 	{
   156 	{
   191 	test.Start(_L("Create CCpuMeter"));
   157 	test.Start(_L("Create CCpuMeter"));
   192 	CCpuMeter* m = CCpuMeter::New();
   158 	CCpuMeter* m = CCpuMeter::New();
   193 	test_NotNull(m);
   159 	test_NotNull(m);
   206 			TKeyCode k = console->KeyCode();
   172 			TKeyCode k = console->KeyCode();
   207 			if (k == EKeyEscape)
   173 			if (k == EKeyEscape)
   208 				{
   174 				{
   209 				delete m;
   175 				delete m;
   210 				return;
   176 				return;
   211 				}
       
   212 			if (m->iNumCpus > 1)
       
   213 				{
       
   214 				// SMP only options
       
   215 				if (k == EKeySpace)
       
   216 					m->DisplayCoreControlInfo();
       
   217 				else if (k>='1' && k<=('0'+m->iNumCpus))
       
   218 					m->ChangeNumberOfCores(k - '0');
       
   219 				}
   177 				}
   220 			console->Read(s);
   178 			console->Read(s);
   221 			}
   179 			}
   222 		}
   180 		}
   223 	}
   181 	}