os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/EComSessionAux.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/EComSessionAux.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,620 @@
     1.4 +// Copyright (c) 2005-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 "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 +//
    1.18 +
    1.19 +#include <ecom/ecom.h>
    1.20 +#include <hal.h>
    1.21 +#include "EComSessionAux.h"
    1.22 +
    1.23 +#ifdef __ECOM_SERVER_TESTABILITY__
    1.24 +
    1.25 +/**
    1.26 +@internalComponent
    1.27 +A helper function to use SetGetParametersL to set the next
    1.28 +state to be used by the ServerStartupManager of EComServer
    1.29 +@param aState the next state to be used by the EComServer
    1.30 +*/
    1.31 +void ChangeStartupStateL(TInt aState)
    1.32 +	{
    1.33 +	TIpcArgs params = TIpcArgs(EChangeStartupState, aState);
    1.34 +	REComSession::SetGetParametersL(params);
    1.35 +	}
    1.36 +	
    1.37 +/**
    1.38 +@internalComponent
    1.39 +A helper function to use SetGetParametersL to force EComServer
    1.40 +to process the next state.
    1.41 +*/
    1.42 +void ProcessCurrentStartupStateL()
    1.43 +	{
    1.44 +	TIpcArgs params = TIpcArgs(EProcessStartupState);
    1.45 +	REComSession::SetGetParametersL(params);
    1.46 +	}
    1.47 +	
    1.48 +/**
    1.49 +@internalComponent
    1.50 +A helper function to use SetGetParametersL to get the current 
    1.51 +startup state of EComServer
    1.52 +@return current startup state of EComServer
    1.53 +*/
    1.54 +TInt GetCurrentStartupStateL()
    1.55 +	{
    1.56 +	TInt currentState = 0;
    1.57 +	TPckg<TInt> statePckg(currentState);
    1.58 +	TIpcArgs params = TIpcArgs(EGetStartupState, &statePckg);
    1.59 +	REComSession::SetGetParametersL(params);
    1.60 +	
    1.61 +	return currentState;
    1.62 +	}
    1.63 +
    1.64 +#endif
    1.65 +
    1.66 +#ifdef __ECOM_SERVER_PERFORMANCE__
    1.67 +
    1.68 +//==================== For Startup State Time Results ===================
    1.69 +/** Method used for TLinearOrder for TTimerResult arrays*/
    1.70 +TInt CompareTimerResults(const TStartupStateTimerResult& aTimerResult1, const TStartupStateTimerResult& aTimerResult2)
    1.71 +	{
    1.72 +	if(aTimerResult1.iState < aTimerResult2.iState)
    1.73 +		{
    1.74 +		return -1;
    1.75 +		}
    1.76 +	else if(aTimerResult1.iState > aTimerResult2.iState)
    1.77 +		{
    1.78 +		return 1;
    1.79 +		}
    1.80 +		
    1.81 +	return 0;
    1.82 +	}
    1.83 +	
    1.84 +/** Method used for TIdentityRelation for TTimerResult arrays*/
    1.85 +TBool MatchOnState(const TStartupStateTimerResult& aKey, const TStartupStateTimerResult& aIndexItem)
    1.86 +	{
    1.87 +	return aIndexItem.iState == aKey.iState;
    1.88 +	}
    1.89 +
    1.90 +TInt RStartupStateTimerResults::FindTimerResult(TInt aState)
    1.91 +	{
    1.92 +	TIdentityRelation<TStartupStateTimerResult> identity(MatchOnState);
    1.93 +	TStartupStateTimerResult key;
    1.94 +	key.iState = aState;
    1.95 +	return iTimerResults.Find(key, identity);
    1.96 +	}
    1.97 +
    1.98 +/**
    1.99 +Method that returns the idx of the timer result at requested state
   1.100 +@param aTimerResults the sorted timer results array to search for the 
   1.101 +timer value
   1.102 +@param aState the state of the requested timer result 
   1.103 +@return The index of the matching timer result KErrNotFound, if no 
   1.104 +matching object can be found
   1.105 +*/	
   1.106 +TInt RStartupStateTimerResults::FindInOrderTimerResult(TInt aState)
   1.107 +	{
   1.108 +	TLinearOrder<TStartupStateTimerResult> compareFunc(CompareTimerResults);
   1.109 +	TStartupStateTimerResult key;
   1.110 +	key.iState = aState;
   1.111 +	return iTimerResults.FindInOrder(key, compareFunc);
   1.112 +	}
   1.113 +
   1.114 +/**
   1.115 +@internalComponent
   1.116 +A helper function to use SetGetParametersL to get the timer recordings
   1.117 +for performance testing. If the specified aTimerIdx is beyond the boundaries
   1.118 +of the recorded values then aTimerResult would return a value of 0 and aState
   1.119 +would return a value of -1. 
   1.120 +@param aTimerIdx the index of the timer to use
   1.121 +@param aTimerResult the timer readings
   1.122 +@param aState the state of the server when timer was read (a zero indexed value)
   1.123 +*/
   1.124 +TInt RStartupStateTimerResults::GetTimerResult(TInt aTimerIdx, TUint32& aTimerResult, TInt& aState)
   1.125 +	{
   1.126 +	TInt returnedStatus;
   1.127 +	TStartupStateTimerEntry result;
   1.128 +
   1.129 +	TPckg<TInt> statusPckg(returnedStatus);
   1.130 +	TPckg<TStartupStateTimerEntry> resultPckg(result);
   1.131 +
   1.132 +	TIpcArgs params = TIpcArgs(EGetStartupStateTimerResult, aTimerIdx, &statusPckg, &resultPckg);
   1.133 +	TRAPD(err, REComSession::SetGetParametersL(params));
   1.134 +	if (err != KErrNone)
   1.135 +		{
   1.136 +		return err;	
   1.137 +		}
   1.138 +	
   1.139 +	aTimerResult = result.iTimerResult;
   1.140 +	aState = result.iState;
   1.141 +	
   1.142 +	return returnedStatus;
   1.143 +	}
   1.144 +
   1.145 +/**
   1.146 +@internalComponent
   1.147 +A helper function to use SetGetParametersL to get all of the timer recordings
   1.148 +for performance testing.
   1.149 +@param aTimerResults a reference to an array to store sorted timer results.
   1.150 +*/
   1.151 +void RStartupStateTimerResults::GetAllTimerResults()
   1.152 +	{
   1.153 +	TInt counter = 0;
   1.154 +	while(ETrue)
   1.155 +		{
   1.156 +		TUint32 time = 0;
   1.157 +		TInt state = -1;
   1.158 +		TReal realTime = 0.0;
   1.159 +		
   1.160 +		// get state start info
   1.161 +		TInt err = GetTimerResult(counter++, time, state);
   1.162 +		if(err || (time == 0 && state == -1))
   1.163 +			{
   1.164 +			break;
   1.165 +			}
   1.166 +		
   1.167 +		realTime = FastCountToMilliseconds(time);
   1.168 +		
   1.169 +		//search state
   1.170 +		TInt idx = FindTimerResult(state);
   1.171 +		if(idx == KErrNotFound) //if it has not been entered to the array make a new entry
   1.172 +			{
   1.173 +			TStartupStateTimerResult timerResult;
   1.174 +			timerResult.iState = state;
   1.175 +			timerResult.iStartTime = realTime;
   1.176 +			timerResult.iEndTime = 0;
   1.177 +			
   1.178 +			iTimerResults.Append(timerResult);
   1.179 +			}
   1.180 +		else //if it has already been entered update the end time
   1.181 +			{
   1.182 +			TStartupStateTimerResult& timerResult = iTimerResults[idx];
   1.183 +			timerResult.iEndTime = realTime;
   1.184 +			}
   1.185 +		}
   1.186 +	
   1.187 +	//the array is populated, sort it for faster search.
   1.188 +	TLinearOrder<TStartupStateTimerResult> compareFunc(CompareTimerResults);
   1.189 +	iTimerResults.Sort(compareFunc);
   1.190 +	}
   1.191 +
   1.192 +void RStartupStateTimerResults::ResetTimerCountL()
   1.193 +	{
   1.194 +	
   1.195 +	TIpcArgs params = TIpcArgs(EResetStartupStateTimerCounts);
   1.196 +	REComSession::SetGetParametersL(params);
   1.197 +	}
   1.198 +	
   1.199 +/**
   1.200 + Frees any allocated resources
   1.201 +*/
   1.202 +void RStartupStateTimerResults::Close()
   1.203 +	{
   1.204 +	iTimerResults.Close();
   1.205 +	}
   1.206 +
   1.207 +/**
   1.208 + Startup state timer results must have been populated by a call to RetrieveResults before this method is called
   1.209 + @param aIndex The index of the timing entry to retrieve
   1.210 + @return The timer result entry for the given index
   1.211 +*/
   1.212 +TStartupStateTimerResult& RStartupStateTimerResults::At(TInt aIndex)
   1.213 +	{
   1.214 +	return iTimerResults[aIndex];
   1.215 +	}
   1.216 +
   1.217 +/**
   1.218 + @return The number of timer results retrieved
   1.219 +*/
   1.220 +TInt RStartupStateTimerResults::Count()
   1.221 +	{
   1.222 +	return iTimerResults.Count();
   1.223 +	}
   1.224 +
   1.225 +//==================== For Client Requests Time Results ===================
   1.226 +/**
   1.227 + Retrieves a single client request timer entry from the ECom server
   1.228 + @param aTimerIdx The index of the timing entry to retrieve
   1.229 + @return KErrNone if successful, KErrOverflow if aTimerIdx is greater than the number of timing entries
   1.230 +*/
   1.231 +TInt RClientRequestTimerResults::GetTimerResult(TInt aTimerIdx, TClientRequestTimerEntry& aTimerEntry)
   1.232 +	{
   1.233 +	TInt returnedStatus;
   1.234 +	TPckg<TInt> statusPckg(returnedStatus);
   1.235 +	TPckg<TClientRequestTimerEntry> resultPckg(aTimerEntry);
   1.236 +	
   1.237 +	TIpcArgs params = TIpcArgs(EGetAccumulatedClientRequestsTimerResult, aTimerIdx, &statusPckg, &resultPckg);
   1.238 +	TRAPD(err, REComSession::SetGetParametersL(params));
   1.239 +	if (err != KErrNone)	
   1.240 +		{
   1.241 +		return err;	
   1.242 +		}
   1.243 +	
   1.244 +	return returnedStatus;
   1.245 +	}
   1.246 +	
   1.247 +/**
   1.248 +Retrieves all client request timer entries from the ECom server
   1.249 +*/
   1.250 +void RClientRequestTimerResults::RetrieveResultsL()
   1.251 +	{
   1.252 +	TClientRequestTimerEntry timerEntry;
   1.253 +	TInt err = KErrNone;
   1.254 +	for (TInt i = 0; err == KErrNone; i++)
   1.255 +		{
   1.256 +		err = GetTimerResult(i, timerEntry);
   1.257 +		if (err == KErrNone)
   1.258 +			{
   1.259 +			iResults.Append(timerEntry);
   1.260 +			}
   1.261 +		else if (err != KErrOverflow)
   1.262 +			{
   1.263 +			User::Leave(err);
   1.264 +			}
   1.265 +		}
   1.266 +	}
   1.267 +	
   1.268 +/**
   1.269 + Determines the total time taken by ECom server servicing client requests with the given state and request type
   1.270 + by going through each of the retrieved timer entries and adding up their associated times
   1.271 + @pre RetrieveResultsL must have been called before this method is called
   1.272 + @param aState The startup state to retrieve timer results for
   1.273 + @param aRequestType The type of client request to retrieve timer results for
   1.274 + @param aNumRequests On return contains the number of client requests matching aState and aRequestType
   1.275 + @return The total time taken servicing client requests matching startup state aState and aRequestType
   1.276 +*/
   1.277 +TReal RClientRequestTimerResults::GetAccumulatedClientRequestTime(TInt aState, TEComClientRequestType aRequestType, TUint& aNumRequests)
   1.278 +	{
   1.279 +	TUint32 accumulatedTicks = 0;
   1.280 +	
   1.281 +	aNumRequests = 0;
   1.282 +	for (TInt i = 0; i < iResults.Count(); i++)
   1.283 +		{
   1.284 +		if (iResults[i].iState == aState && iResults[i].iClientRequestType == aRequestType)
   1.285 +			{
   1.286 +			TUint netTime = iResults[i].iEndTime - iResults[i].iStartTime;
   1.287 +			accumulatedTicks += netTime;
   1.288 +			aNumRequests++;
   1.289 +			}
   1.290 +		}
   1.291 +		
   1.292 +	return FastCountToMilliseconds(accumulatedTicks);
   1.293 +	}
   1.294 +
   1.295 +/**
   1.296 + Determines the total time taken by ECom server servicing client requests with the given state
   1.297 + by going through each of the retrieved timer entries and adding up their associated times
   1.298 + Client request timer results must have been populated by a call to RetrieveResults before this method is called
   1.299 + @param aState The startup state to retrieve timer results for
   1.300 + @param aNumRequests On return contains the number of client requests matching aState
   1.301 + @return The total time taken servicing client requests matching startup state aState
   1.302 +*/
   1.303 +TReal RClientRequestTimerResults::GetAccumulatedClientRequestTime(TInt aState, TUint& aNumRequests)
   1.304 +	{
   1.305 +	TUint32 accumulatedTicks = 0;
   1.306 +	
   1.307 +	aNumRequests = 0;
   1.308 +	for (TInt i = 0; i < iResults.Count(); i++)
   1.309 +		{
   1.310 +		if (iResults[i].iState == aState)
   1.311 +			{
   1.312 +			TUint netTime = iResults[i].iEndTime - iResults[i].iStartTime;
   1.313 +			accumulatedTicks += netTime;
   1.314 +			aNumRequests++;
   1.315 +			}
   1.316 +		}
   1.317 +		
   1.318 +	return FastCountToMilliseconds(accumulatedTicks);
   1.319 +	}
   1.320 +
   1.321 +/**
   1.322 + Determines the total time taken by ECom server servicing client requests with the given request type
   1.323 + by going through each of the retrieved timer entries and adding up their associated times
   1.324 + Client request timer results must have been populated by a call to RetrieveResults before this method is called
   1.325 + @param aRequestType The type of client request to retrieve timer results for
   1.326 + @param aNumRequests On return contains the number of client requests matching aRequestType
   1.327 + @return The total time taken servicing client requests matching startup state aRequestType
   1.328 +*/
   1.329 +TReal RClientRequestTimerResults::GetAccumulatedClientRequestTime(TEComClientRequestType aRequestType, TUint& aNumRequests)
   1.330 +	{
   1.331 +	TUint32 accumulatedTicks = 0;
   1.332 +	
   1.333 +	aNumRequests = 0;
   1.334 +	for (TInt i = 0; i < iResults.Count(); i++)
   1.335 +		{
   1.336 +		if (iResults[i].iClientRequestType == aRequestType)
   1.337 +			{
   1.338 +			TUint netTime = iResults[i].iEndTime - iResults[i].iStartTime;
   1.339 +			accumulatedTicks += netTime;
   1.340 +			aNumRequests++;
   1.341 +			}
   1.342 +		}
   1.343 +		
   1.344 +	return FastCountToMilliseconds(accumulatedTicks);
   1.345 +	}
   1.346 +
   1.347 +/**
   1.348 + Determines the total time taken by ECom server servicing all client requests
   1.349 + by going through each of the retrieved timer entries and adding up their associated times
   1.350 + Client request timer results must have been populated by a call to RetrieveResults before this method is called
   1.351 + @param aNumRequests On return contains the number of client requests
   1.352 + @return The total time taken servicing client requests
   1.353 +*/
   1.354 +TReal RClientRequestTimerResults::GetAccumulatedClientRequestTime(TUint& aNumRequests)
   1.355 +	{
   1.356 +	TUint32 accumulatedTicks = 0;
   1.357 +	
   1.358 +	aNumRequests = 0;
   1.359 +	for (TInt i = 0; i < iResults.Count(); i++)
   1.360 +		{
   1.361 +		TUint netTime = iResults[i].iEndTime - iResults[i].iStartTime;
   1.362 +		accumulatedTicks += netTime;
   1.363 +		aNumRequests++;
   1.364 +		}
   1.365 +		
   1.366 +	return FastCountToMilliseconds(accumulatedTicks);
   1.367 +	}
   1.368 +
   1.369 +/**
   1.370 +Frees any resources
   1.371 +*/
   1.372 +void RClientRequestTimerResults::Close()
   1.373 +	{
   1.374 +	iResults.Reset();
   1.375 +	}
   1.376 +
   1.377 +/**	
   1.378 +@internalComponent
   1.379 +A helper function to use SetGetParametersL to get the number of
   1.380 +drives, plugins, interfaces, implementation for performance testing.
   1.381 +@param aCounts a reference to a struct to store results.
   1.382 +*/
   1.383 +void RegistryCounts::GetRegistryCountsL(TRegistryCounts::TRegistryCountDriveType aType, TRegistryCounts& aCounts)
   1.384 +	{
   1.385 +	TPckg<TRegistryCounts> registryCountPckg(aCounts);
   1.386 +	TIpcArgs params = TIpcArgs(EGetRegistryCounts, aType, &registryCountPckg);
   1.387 +	REComSession::SetGetParametersL(params);
   1.388 +	}
   1.389 +
   1.390 +
   1.391 +//==================== For ECom Performance Time Results ===================
   1.392 +/**
   1.393 +@internalComponent
   1.394 +A helper function to use SetGetParametersL to get the time recordings
   1.395 +for performance testing. If the specified aTimerIdx is beyond the size
   1.396 +of the valid recorded values then KErrOverFlow returns from the server side
   1.397 +@param aTimerIdx the index of the time record to use
   1.398 +@param aTimeEntry the fast time record entry
   1.399 +*/
   1.400 +TInt REComPerfTimeRecords::GetTimeRecordEntry(TInt aTimeIdx, TEComPerfTimeRecordEntry& aTimeEntry)
   1.401 +	{
   1.402 +	TInt returnedStatus;
   1.403 +
   1.404 +	TPckg<TInt> statusPckg(returnedStatus);
   1.405 +	TPckg<TEComPerfTimeRecordEntry> resultPckg(aTimeEntry);
   1.406 +
   1.407 +	TIpcArgs params = TIpcArgs(EGetEComPerfTimeRecord, aTimeIdx, &statusPckg, &resultPckg);
   1.408 +	TRAPD(err, REComSession::SetGetParametersL(params));
   1.409 +	if (err != KErrNone)
   1.410 +		{
   1.411 +		return err;	
   1.412 +		}
   1.413 +		
   1.414 +	return returnedStatus;
   1.415 +	}
   1.416 +
   1.417 +/**
   1.418 +Get all ECom performance time records from server and fill up local array for further use
   1.419 +*/
   1.420 +void REComPerfTimeRecords::OpenL()
   1.421 +	{
   1.422 +	TEComPerfTimeRecordEntry timeEntry;
   1.423 +	TInt err = KErrNone;
   1.424 +	
   1.425 +	iTimeRecords.Reset();
   1.426 +	
   1.427 +	// Get the first record from server
   1.428 +	TInt idx = 0;
   1.429 +	err = GetTimeRecordEntry(idx, timeEntry);
   1.430 +	while(err == KErrNone)
   1.431 +		{
   1.432 +		// If it is a valid record entry, append it to local record array, 
   1.433 +		//  and get the next entry from server.
   1.434 +		if (timeEntry.iType != ENullType)
   1.435 +			{
   1.436 +			iTimeRecords.Append(timeEntry);
   1.437 +			idx++;
   1.438 +			err = GetTimeRecordEntry(idx, timeEntry);
   1.439 +			}
   1.440 +		// Otherwise finished
   1.441 +		else
   1.442 +			break;
   1.443 +		}
   1.444 +			
   1.445 +	if (err != KErrOverflow)
   1.446 +		{
   1.447 +		User::LeaveIfError(err);
   1.448 +		}
   1.449 +	}
   1.450 +
   1.451 +/**
   1.452 +Transform raw fast count records into real time results (in mSecs), and collect the results by specified type.
   1.453 +*/
   1.454 +void REComPerfTimeRecords::RetrieveResultsByTypeL(TEComPerfTimeRecordType aType, RArray<TEComPerfRealTimeResult>& aTimeResults)
   1.455 +	{
   1.456 +	TEComPerfRealTimeResult timeResult;
   1.457 +	TBool start = ETrue;
   1.458 +	TInt count = iTimeRecords.Count();
   1.459 +
   1.460 +	if(count)
   1.461 +		{
   1.462 +		for (TInt i = 0; i < count; i++)
   1.463 +			{
   1.464 +			// If the record has correct type
   1.465 +			if(iTimeRecords[i].iType == aType)
   1.466 +				{
   1.467 +				// If the record is the first of the couple, it should be the start time record
   1.468 +				if(start)
   1.469 +					{
   1.470 +					timeResult.iStartTime = FastCountToMilliseconds(iTimeRecords[i].iTime);
   1.471 +					timeResult.iType = iTimeRecords[i].iType;
   1.472 +					timeResult.iInfo = iTimeRecords[i].iInfo;
   1.473 +					start = EFalse;
   1.474 +					}
   1.475 +				// Otherwise it should be the end time record.
   1.476 +				else
   1.477 +					{
   1.478 +					timeResult.iEndTime = FastCountToMilliseconds(iTimeRecords[i].iTime);
   1.479 +					aTimeResults.Append(timeResult);
   1.480 +					start = ETrue;
   1.481 +					}
   1.482 +				}
   1.483 +			}
   1.484 +		}
   1.485 +	else // Leave if there's no records to retrieve
   1.486 +		{
   1.487 +		User::Leave(KErrNotFound);
   1.488 +		}
   1.489 +	}
   1.490 +
   1.491 +
   1.492 +/**
   1.493 +
   1.494 +*/
   1.495 +void REComPerfTimeRecords::RetrieveResultsInfoByTypeL(TEComPerfTimeRecordType aType, RArray<TInt>& aInfos)
   1.496 +	{
   1.497 +	TInt count = iTimeRecords.Count();
   1.498 +	if(count)
   1.499 +		{
   1.500 +		for (TInt i = 0; i < count; i++)
   1.501 +			{
   1.502 +			// If the record has correct type, insert the info into aInfos array. No duplicate infos are recorded.
   1.503 +			if(iTimeRecords[i].iType == aType)
   1.504 +				{
   1.505 +				TInt err = aInfos.InsertInOrder(iTimeRecords[i].iInfo);
   1.506 +				
   1.507 +				if(err!=KErrAlreadyExists)
   1.508 +					User::LeaveIfError(err);
   1.509 +				}
   1.510 +			}
   1.511 +		}
   1.512 +	else // Leave if there's no records to retrieve
   1.513 +		{
   1.514 +		User::Leave(KErrNotFound);
   1.515 +		}
   1.516 +	}
   1.517 +
   1.518 +// Reset all fast count records on server
   1.519 +void REComPerfTimeRecords::ResetRecordsOnServerL()
   1.520 +	{
   1.521 +	TIpcArgs params = TIpcArgs(EResetEComPerfTimeRecords);
   1.522 +	REComSession::SetGetParametersL(params);
   1.523 +	}
   1.524 +
   1.525 +TInt REComPerfTimeRecords::Count()
   1.526 +	{
   1.527 +	return iTimeRecords.Count();
   1.528 +	}
   1.529 +
   1.530 +// Empty local time result array
   1.531 +void REComPerfTimeRecords::Reset()
   1.532 +	{
   1.533 +	iTimeRecords.Reset();
   1.534 +	}
   1.535 +
   1.536 +// Release resources
   1.537 +void REComPerfTimeRecords::Close()
   1.538 +	{
   1.539 +	iTimeRecords.Close();
   1.540 +	}
   1.541 +
   1.542 +//==================== For ECom Performance Heap Usage Results ===================
   1.543 +/**
   1.544 +@internalComponent
   1.545 +*/
   1.546 +void REComHeapUsageRecords::OpenL()
   1.547 +	{
   1.548 +	iHeapRecords.Reset();
   1.549 +	
   1.550 +	// Get the first record from server
   1.551 +	TInt idx = 0;
   1.552 +	TEComPerfHeapUsage heapEntry;
   1.553 +	TInt err=GetHeapRecordEntry(idx,heapEntry);
   1.554 +	while(err == KErrNone && heapEntry.iState!=0)
   1.555 +		{
   1.556 +		//check existing array for a start item
   1.557 +		TBool startFound=EFalse;
   1.558 +		for (TInt i=0;i<iHeapRecords.Count();i++)
   1.559 +			{
   1.560 +			//if can find one this entry must be a start entry so update the heap usage
   1.561 +			if (iHeapRecords[i].iState==heapEntry.iState)
   1.562 +				{
   1.563 +				iHeapRecords[i].iHeapSize=heapEntry.iHeapSize-(iHeapRecords[i].iHeapSize);
   1.564 +				startFound=ETrue;
   1.565 +				break;
   1.566 +				}
   1.567 +			}
   1.568 +		//only append the entry if it is a new start entry
   1.569 +		if (!startFound)
   1.570 +			iHeapRecords.Append(heapEntry);
   1.571 +		idx++;
   1.572 +		err=GetHeapRecordEntry(idx,heapEntry);
   1.573 +		}
   1.574 +			
   1.575 +	if (err != KErrOverflow)
   1.576 +		{
   1.577 +		User::LeaveIfError(err);
   1.578 +		}	
   1.579 +	}
   1.580 +
   1.581 +TInt REComHeapUsageRecords::GetHeapUsageAtState(TInt aState)
   1.582 +	{
   1.583 +	for (TInt i=0;i<iHeapRecords.Count();i++)
   1.584 +		{
   1.585 +		if (iHeapRecords[i].iState==aState)
   1.586 +			{
   1.587 +			return iHeapRecords[i].iHeapSize;
   1.588 +			}
   1.589 +		}
   1.590 +	return KErrNotFound;
   1.591 +	}
   1.592 +
   1.593 +void REComHeapUsageRecords::Close()
   1.594 +	{
   1.595 +	iHeapRecords.Reset();
   1.596 +	iHeapRecords.Close();
   1.597 +	}
   1.598 +
   1.599 +TInt REComHeapUsageRecords::GetHeapRecordEntry(TInt aHeapIdx,TEComPerfHeapUsage& aHeapEntry)
   1.600 +	{
   1.601 +	TInt returnedStatus;
   1.602 +	TPckg<TInt> statusPckg(returnedStatus);
   1.603 +	TPckg<TEComPerfHeapUsage> resultPckg(aHeapEntry);
   1.604 +	TIpcArgs params = TIpcArgs(EGetEComServerHeapResult, aHeapIdx,&statusPckg,&resultPckg);
   1.605 +	TRAPD(err, REComSession::SetGetParametersL(params));
   1.606 +	return err;
   1.607 +	}
   1.608 +
   1.609 +//===========================================================
   1.610 +/**
   1.611 +Converts time retrieved using FastCounter to milliseconds
   1.612 + @param aFastCount The time to convert to milliseconds, retrieved using User::FastCounter
   1.613 + @return The time in milliseconds corresponding to aFastCount
   1.614 +*/
   1.615 +TReal FastCountToMilliseconds(TInt aFastCount)
   1.616 +	{
   1.617 +	TInt freqInHz;
   1.618 +	HAL::Get(HAL::EFastCounterFrequency, freqInHz);
   1.619 +	TReal freqInkHz = freqInHz / 1000;
   1.620 +	return (TReal)aFastCount / freqInkHz;
   1.621 +	}
   1.622 +	
   1.623 +#endif