persistentstorage/centralrepository/test/testexecute/performance/src/TE_PerfTestStep.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 0 08ec8eefde2f
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
       
     1 // Copyright (c) 2005-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 //
       
    15 
       
    16 
       
    17 #include <e32std.h>
       
    18 #include <centralrepository.h>
       
    19 #include "t_cenrep_helper.h"
       
    20 #include <hal.h>
       
    21 #include <hal_data.h>
       
    22 #include "srvPerf.h"
       
    23 #include "srvreqs.h"
       
    24 #include "TE_PerfTestStep.h"
       
    25 
       
    26 #ifdef __CENTREP_SERVER_PERFTEST__
       
    27 
       
    28 // Function DecodeEventAndData
       
    29 // Extract the high 8-bit event Id and the low 24-bit data
       
    30 // from the 32 bit integer.
       
    31 //
       
    32 // param aEntry - the 32 bit integer to decode
       
    33 // param aEventId - return the EventId Id.
       
    34 // param aData - return the 24-bit data value
       
    35 inline
       
    36 void DecodeEventAndData(TUint32 aEntry, TUint& aEventId, TUint32& aData)
       
    37 	{
       
    38 	aEventId = (aEntry >> KEventIdShiftBits) & KEventIdMask;
       
    39 	aData = aEntry & KDataMask;
       
    40 	}
       
    41 
       
    42 // Function FindRepUid
       
    43 // Search for the given Repository UID in aArray.
       
    44 //
       
    45 // param aArray - the RArray containing a number of repositories.
       
    46 // param aRepUid - the rep UID to search for.
       
    47 // Return - if aRepUid is in the array, return its index in array,
       
    48 //          else return KErrNotFound.
       
    49 TInt FindRepUid(const RArray<TRepStatistics>& aArray, TUint32 aRepUid)
       
    50 	{
       
    51 	for (TInt i = 0; i < aArray.Count(); i++)
       
    52 		{
       
    53 		if (aArray[i].MatchUid(aRepUid))
       
    54 			return i;
       
    55 		}
       
    56 	return KErrNotFound;
       
    57 	}
       
    58 
       
    59 // Function GetFuncCodeName
       
    60 // Map CentRep function code to string.
       
    61 //
       
    62 // param aFunc - the function code to map to string.
       
    63 // Return - textual representation of the function code.
       
    64 _LIT(KEInitialise, "Open");
       
    65 _LIT(KECreateInt, "ECreateInt");
       
    66 _LIT(KECreateReal, "ECreateReal");
       
    67 _LIT(KECreateString, "ECreateString");
       
    68 _LIT(KEDelete, "EDelete");
       
    69 _LIT(KEGetInt, "EGetInt");
       
    70 _LIT(KESetInt, "ESetInt");
       
    71 _LIT(KEGetReal, "EGetReal");
       
    72 _LIT(KESetReal, "ESetReal");
       
    73 _LIT(KEGetString, "EGetString");
       
    74 _LIT(KESetString, "ESetString");
       
    75 _LIT(KEFind, "EFind");
       
    76 _LIT(KEFindEqInt, "EFindEqInt");
       
    77 _LIT(KEFindEqReal, "EFindEqReal");
       
    78 _LIT(KEFindEqString, "EFindEqString");
       
    79 _LIT(KEFindNeqInt, "EFindNeqInt");
       
    80 _LIT(KEFindNeqReal, "EFindNeqReal");
       
    81 _LIT(KEFindNeqString, "EFindNeqString");
       
    82 _LIT(KEGetFindResult, "EGetFindResult");
       
    83 _LIT(KENotifyRequestCheck, "ENotifyRequestCheck");
       
    84 _LIT(KENotifyRequest, "ENotifyRequest");
       
    85 _LIT(KENotifyCancel, "ENotifyCancel");
       
    86 _LIT(KENotifyCancelAll, "ENotifyCancelAll");
       
    87 _LIT(KEGroupNotifyRequest, "EGroupNotifyRequest");
       
    88 _LIT(KEGroupNotifyCancel, "EGroupNotifyCancel");
       
    89 _LIT(KEReset, "EReset");
       
    90 _LIT(KEResetAll, "EResetAll");
       
    91 _LIT(KETransactionStart, "ETransactionStart");
       
    92 _LIT(KETransactionCommit, "ETransactionCommit");
       
    93 _LIT(KETransactionCancel, "ETransactionCancel");
       
    94 _LIT(KEMove, "EMove");
       
    95 _LIT(KETransactionState, "ETransactionState");
       
    96 _LIT(KETransactionFail, "ETransactionFail");
       
    97 _LIT(KEDeleteRange, "EDeleteRange");
       
    98 _LIT(KEGetSetParameters, "EGetSetParameters");
       
    99 _LIT(KEClose, "EClose");
       
   100 _LIT(KEEvict, "Evict");
       
   101 _LIT(KUnknownFunction, "UnknownCode");
       
   102 
       
   103 const TDesC* GetFuncCodeName(TUint aFunc)
       
   104 	{
       
   105 	switch (aFunc)
       
   106 		{
       
   107 		case EInitialise: return(&KEInitialise);
       
   108 		case ECreateInt: return(&KECreateInt);
       
   109 		case ECreateReal: return(&KECreateReal);
       
   110 		case ECreateString: return(&KECreateString);
       
   111 		case EDelete: return(&KEDelete);
       
   112 		case EGetInt: return(&KEGetInt);
       
   113 		case ESetInt: return(&KESetInt);
       
   114 		case EGetReal: return(&KEGetReal);
       
   115 		case ESetReal: return(&KESetReal);
       
   116 		case EGetString: return(&KEGetString);
       
   117 		case ESetString: return(&KESetString);
       
   118 		case EFind: return(&KEFind);
       
   119 		case EFindEqInt: return(&KEFindEqInt);
       
   120 		case EFindEqReal: return(&KEFindEqReal);
       
   121 		case EFindEqString: return(&KEFindEqString);
       
   122 		case EFindNeqInt: return(&KEFindNeqInt);
       
   123 		case EFindNeqReal: return(&KEFindNeqReal);
       
   124 		case EFindNeqString: return(&KEFindNeqString);
       
   125 		case EGetFindResult: return(&KEGetFindResult);
       
   126 		case ENotifyRequestCheck: return(&KENotifyRequestCheck);
       
   127 		case ENotifyRequest: return(&KENotifyRequest);
       
   128 		case ENotifyCancel: return(&KENotifyCancel);
       
   129 		case ENotifyCancelAll: return(&KENotifyCancelAll);
       
   130 		case EGroupNotifyRequest: return(&KEGroupNotifyRequest);
       
   131 		case EGroupNotifyCancel: return(&KEGroupNotifyCancel);
       
   132 		case EReset: return(&KEReset);
       
   133 		case EResetAll: return(&KEResetAll);
       
   134 		case ETransactionStart: return(&KETransactionStart);
       
   135 		case ETransactionCommit: return(&KETransactionCommit);
       
   136 		case ETransactionCancel: return(&KETransactionCancel);
       
   137 		case EMove: return(&KEMove);
       
   138 		case ETransactionState: return(&KETransactionState);
       
   139 		case ETransactionFail: return(&KETransactionFail);
       
   140 		case EDeleteRange: return(&KEDeleteRange);
       
   141 		case EGetSetParameters: return (&KEGetSetParameters);
       
   142 		case EClose: return(&KEClose);
       
   143 		case EEvict: return (&KEEvict);
       
   144 		}
       
   145 		return &KUnknownFunction;
       
   146 	}
       
   147 #endif //__CENTREP_SERVER_PERFTEST__
       
   148 
       
   149 //--------------------
       
   150 // class CPerfTestStep
       
   151 //--------------------
       
   152 
       
   153 // doTestStepL
       
   154 // Implement the pure virtual function.
       
   155 // This test fetches the performance data collected by
       
   156 // CentRep server, sums the CPU time spent in servicing
       
   157 // each type of request and time spent in opening each
       
   158 // repository, and prints out the total.
       
   159 TVerdict CPerfTestStep::doTestStepL()
       
   160 	{
       
   161 #ifdef __CENTREP_SERVER_PERFTEST__
       
   162 
       
   163 	TBuf<KMaxFileName> sharedString; 
       
   164 
       
   165 	TPtrC resultSection;
       
   166 	TInt testMode;
       
   167 	TInt bRet;
       
   168 	// get test mode from ini file
       
   169 	bRet = GetIntFromConfig(ConfigSection(), KIniTestMode, testMode);
       
   170 	TESTL(bRet==1);
       
   171 
       
   172 	_LIT(KBlankLine, "\n");
       
   173 	Logger().WriteFormat(KBlankLine);	 	
       
   174 	
       
   175 	if (testMode == ETiming)
       
   176 		{
       
   177 		bRet = GetStringFromConfig(ConfigSection(), KResultsSection, resultSection);
       
   178 		TESTL(bRet==1);
       
   179 		}
       
   180 	
       
   181 	if (testMode == EBoot)
       
   182 		{
       
   183 		_LIT(KDoTestStepDisclaimer1, "For this test boot-up is considered to be finished when CommsDat repository is loaded 9 times.");
       
   184 		Logger().WriteFormat(KDoTestStepDisclaimer1);
       
   185 		_LIT(KDoTestStepDisclaimer2, "This is when the watcher thread is used to make re-attempts to connect to the network.");
       
   186 		Logger().WriteFormat(KDoTestStepDisclaimer2);
       
   187 		}
       
   188 	
       
   189 	// Setup IPC args to retreive performance data from server.
       
   190 	TUint bufSize = KCentRepPerfTestArraySize * sizeof(TUint32);
       
   191 	TAny* buf = User::AllocL(bufSize);
       
   192 	TPtr8 bufDesc(static_cast<TUint8*>(buf), bufSize);
       
   193 
       
   194 	TUint numValidEntries;
       
   195 	TPckg<TUint> pckg(numValidEntries);
       
   196 
       
   197 	TInt ret = SetGetParameters(TIpcArgs(EGetPerfResults, &bufDesc, &pckg));
       
   198 	if (ret != KErrNone)
       
   199 		{
       
   200 		_LIT(KSetGetParamFailFmt, "Send msg err %d");
       
   201 		ERR_PRINTF2(KSetGetParamFailFmt, ret);
       
   202 		User::Free(buf);
       
   203 		return EFail;
       
   204 		}
       
   205 
       
   206 	if (testMode == EBoot)
       
   207 		{
       
   208 		_LIT(KNumValidEntriesFmt, "Num Valid entries = %d");
       
   209 		Logger().WriteFormat(KNumValidEntriesFmt, numValidEntries);
       
   210 		}
       
   211 
       
   212 	RArray<TUint32> perfData(sizeof(TUint32),static_cast<TUint32*>(buf),KCentRepPerfTestArraySize);
       
   213 	CleanupClosePushL(perfData);
       
   214 
       
   215 	// Need to find the tick frequency before using ConvertTickToSecAndMilli.
       
   216 	HAL::Get(HALData::EFastCounterFrequency, iTickFreq);
       
   217 
       
   218 	TUint sec;
       
   219 	TUint milliSec;
       
   220 
       
   221 	const TUint KNumIpcs = EEvict + 1; 
       
   222 	TIpcStatistics ipcStats[KNumIpcs];
       
   223 	RArray<TRepStatistics> repStats;
       
   224 	CleanupClosePushL(repStats);
       
   225     TUint32 totalElapsedTicks = 0;
       
   226 	const TDesC* eventName;
       
   227 
       
   228 	// Process the data
       
   229 
       
   230 	// Performance data has 3 parts. First event ID and CPU tick
       
   231 	// to service the request. 2nd & 3rd, if event is open/close/evict
       
   232 	// the time of the event and repository UID.
       
   233 	TInt i;
       
   234 	for (i=0; i<numValidEntries && i<KCentRepPerfTestArraySize;)
       
   235 		{
       
   236 		TUint eventId;
       
   237 		TUint32 ticksToServiceIpc;
       
   238 		TUint32 repositoryUid;
       
   239 
       
   240 		// This entry is elapsed ticks to service the request
       
   241 		DecodeEventAndData(perfData[i++], eventId, ticksToServiceIpc);
       
   242 		totalElapsedTicks += ticksToServiceIpc;
       
   243 		ipcStats[eventId].AddData(ticksToServiceIpc);
       
   244 
       
   245 		TBool repOpenCloseEvict = eventId == EInitialise || eventId == EClose || eventId == EEvict;
       
   246 
       
   247 		if (repOpenCloseEvict)
       
   248 			{
       
   249 			TESTL(i < numValidEntries);
       
   250 			TUint32 eventTime = perfData[i++];
       
   251 
       
   252 			TESTL(i < numValidEntries);
       
   253 			repositoryUid = perfData[i++];
       
   254 
       
   255 			// Only rep open is stored in repStats array.
       
   256 			// Close and evict go into the ipcStats.
       
   257 			if (eventId == EInitialise)
       
   258 				{
       
   259 				TInt idx = FindRepUid(repStats, repositoryUid);
       
   260 				if (idx == KErrNotFound)
       
   261 					{
       
   262 					repStats.Append(TRepStatistics(repositoryUid, ticksToServiceIpc));
       
   263 					}
       
   264 				else
       
   265 					{
       
   266 					repStats[idx].AddData(ticksToServiceIpc);
       
   267 					}
       
   268 				} // if eventId == EInitialise
       
   269 
       
   270 			if (testMode == EBoot)
       
   271 				{
       
   272 				// Display the time that this event occur.
       
   273 				eventName = GetFuncCodeName(eventId);
       
   274 				ConvertTickToSecAndMilli(eventTime, sec, milliSec);
       
   275 				_LIT(KRepOpenCloseFmt, "REP %X %S at %d.%03d");
       
   276 				Logger().WriteFormat(KRepOpenCloseFmt, repositoryUid, eventName, sec, milliSec);
       
   277 				}
       
   278 			} // if repOpenCloseEvict
       
   279 		} // for i
       
   280 
       
   281 
       
   282 	// Display the IPC statistics
       
   283 	Logger().WriteFormat(KBlankLine);
       
   284 	Logger().WriteFormat(KBlankLine);
       
   285 	_LIT(KIpcStatsFmt, "IPC Statistics:");
       
   286 	Logger().WriteFormat(KIpcStatsFmt);
       
   287 
       
   288 	TInt numIpcMsgs = 0;
       
   289 	TInt numLogItems = 0;
       
   290 	TBuf<50> keyName;
       
   291 	_LIT(KIndividualIpcStat, "%S used %d times, sum of CPU time = %d ms");
       
   292 	for (i = 0; i < KNumIpcs; i++)
       
   293 		{
       
   294 		if (ipcStats[i].iUseCount == 0)
       
   295 			{
       
   296 			continue;
       
   297 			}
       
   298 
       
   299 		numIpcMsgs += ipcStats[i].iUseCount;
       
   300 		eventName = GetFuncCodeName(i);
       
   301 		ConvertTickToSecAndMilli(ipcStats[i].iSumElapsedTicks, sec, milliSec);
       
   302 		if (sec > 0)
       
   303 			{
       
   304 			milliSec += sec * 1000;
       
   305 			}
       
   306 		Logger().WriteFormat(KIndividualIpcStat, eventName, ipcStats[i].iUseCount, milliSec);
       
   307 		if (testMode == ETiming)
       
   308 			{
       
   309 			sharedString.AppendFormat(_L(" %S %d %d"), eventName, ipcStats[i].iUseCount, milliSec);
       
   310 			numLogItems++;
       
   311 			}
       
   312 		}
       
   313 	if (testMode == ETiming)
       
   314 		{
       
   315 		TBuf<2> numofItems;
       
   316 		numofItems.Num(numLogItems);
       
   317 		sharedString.Insert(0, numofItems);
       
   318 		WriteSharedDataL(resultSection, sharedString, ESetText);
       
   319 		}
       
   320 
       
   321 	// Display Repository statistics
       
   322 	Logger().WriteFormat(KBlankLine);
       
   323 	Logger().WriteFormat(KBlankLine);
       
   324 	_LIT(KRepStatsFmt, "Repository Statistics:");
       
   325 	Logger().WriteFormat(KRepStatsFmt);
       
   326 
       
   327 	if (testMode == ETiming)
       
   328 		{
       
   329 		numLogItems = 0;
       
   330 		sharedString.Copy(_L(" "));
       
   331 		}
       
   332 	_LIT(KIndividualRepStat, "%X used %d times, sum of load time %d ms");
       
   333 	for (i = 0; i < repStats.Count(); i++)
       
   334 		{
       
   335 		ConvertTickToSecAndMilli(repStats[i].iSumLoadTicks, sec, milliSec);
       
   336 		if (sec > 0)
       
   337 			{
       
   338 			milliSec += sec * 1000;
       
   339 			}
       
   340 		Logger().WriteFormat(KIndividualRepStat, repStats[i].iRepUid,
       
   341 			repStats[i].iUseCount, milliSec);
       
   342 		if (testMode == ETiming)
       
   343 			{
       
   344 			sharedString.AppendFormat(_L(" %08X %d %d"), repStats[i].iRepUid, repStats[i].iUseCount, milliSec);
       
   345 			numLogItems++;
       
   346 			}
       
   347 		}
       
   348 		
       
   349 	if (testMode == ETiming)
       
   350 		{
       
   351 		TBuf<2> numofItems;
       
   352 		numofItems.Num(numLogItems);
       
   353 		sharedString.Insert(1, numofItems);
       
   354 		WriteSharedDataL(resultSection, sharedString, EAppendText);
       
   355 		
       
   356 		Logger().WriteFormat(KBlankLine);
       
   357 		}
       
   358 
       
   359 	if (testMode == EBoot)
       
   360 		{
       
   361 		// show total CPU used by CentralRepository server.
       
   362 		ConvertTickToSecAndMilli(totalElapsedTicks, sec, milliSec);
       
   363 		if (sec > 0)
       
   364 			{
       
   365 			milliSec += sec * 1000;
       
   366 			}
       
   367 
       
   368 		Logger().WriteFormat(KBlankLine);
       
   369 		Logger().WriteFormat(KBlankLine);
       
   370 		_LIT(KTotalCpuFmt, "Total CPU time used by CentRepSrv: %d ms");
       
   371 		Logger().WriteFormat(KTotalCpuFmt, milliSec);
       
   372 
       
   373 		_LIT(KNoteAboutTotal, "The above does not include kernel processing time and client idle time for the %d IPC messages.\n");
       
   374 		Logger().WriteFormat(KNoteAboutTotal, numIpcMsgs);
       
   375 		}
       
   376 
       
   377 	// Stop performance test data recording in the server
       
   378 	TInt r = SetGetParameters(TIpcArgs(EStopPerfTests));
       
   379 	TEST(r==KErrNone);
       
   380 		
       
   381 	CleanupStack::PopAndDestroy(); // repStats
       
   382 	CleanupStack::PopAndDestroy(); // perfData
       
   383 	return EPass;
       
   384 #else
       
   385 	_LIT(KWarnTestMacroOff, "Performance test macro __CENTREP_SERVER_PERFTEST__ is disabled. Test not run.");
       
   386 	WARN_PRINTF1(KWarnTestMacroOff);
       
   387 	return EPass;
       
   388 #endif
       
   389 	}
       
   390 
       
   391 // ConvertTickToSecAndMilli
       
   392 // Convert FastCounter ticks to seconds and milli-seconds.
       
   393 //
       
   394 // param aTick - ticks from User::FastCounter
       
   395 // param aSec - return number of seconds in aTick
       
   396 // param aMilliSec - return number of ms left behind after number of
       
   397 //                   seconds is subtracted from aTick.
       
   398 void CPerfTestStep::ConvertTickToSecAndMilli(TUint32 aTick, TUint& aSec, TUint& aMilliSec)
       
   399 	{
       
   400 	aSec = aTick / iTickFreq;
       
   401 	aMilliSec = ((aTick - aSec * iTickFreq) * 1000 + (iTickFreq >> 1)) / iTickFreq;
       
   402 	}
       
   403 
       
   404 //------------------------
       
   405 // class TRepStatistics
       
   406 //------------------------
       
   407 
       
   408 // AddData
       
   409 // Increment number of times this rep is open, sum of CPU used
       
   410 // to load it, and check cache miss.
       
   411 void TRepStatistics::AddData(TUint32 aElapsedTicks)
       
   412 	{
       
   413 	iSumLoadTicks += aElapsedTicks;
       
   414 	iUseCount++;
       
   415 	if (aElapsedTicks >= KTicks2LoadFromCache)
       
   416 		{
       
   417 		iCacheMisses++;
       
   418 		}
       
   419 	}
       
   420 
       
   421 //---------------------
       
   422 // class TIpcStatistics
       
   423 //---------------------
       
   424 
       
   425 // AddData
       
   426 // Increment number of times the IPC msg is received by server.
       
   427 // Sum time to service this type of request.
       
   428 void TIpcStatistics::AddData(TUint32 aElapsedTicks)
       
   429 	{
       
   430 	iUseCount++;
       
   431 	iSumElapsedTicks += aElapsedTicks;
       
   432 	}