multimediacommsengine/tsrc/testdriver/siptester/src/TCmdGetMemoryUsage.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <utf.h>
       
    20 #include <hal.h>
       
    21 #include "TCmdGetMemoryUsage.h"
       
    22 #include "SIPConstants.h"
       
    23 
       
    24 /**
       
    25  * INPUT:
       
    26  *   Headers:		-
       
    27  *   Parameters:	KParamProcess
       
    28  *   IDs:			-
       
    29  *
       
    30  * OUTPUT:
       
    31  *   Parameters:	KParamUsedMemory, KParamFreeMemory
       
    32  *   IDs:			-
       
    33  */
       
    34 void TCmdGetMemoryUsage::ExecuteL()
       
    35 	{
       
    36 	//This returns the used memory across the whole system, and not for the
       
    37 	//specified server
       
    38 	TInt totalMemory = 0;	
       
    39 	User::LeaveIfError( HAL::Get( HALData::EMemoryRAM, totalMemory ) );
       
    40 	TInt freeMemory = 0;
       
    41 	User::LeaveIfError( HAL::Get( HALData::EMemoryRAMFree, freeMemory ) );
       
    42 	TInt usedMemory = totalMemory - freeMemory;
       
    43 
       
    44 
       
    45 
       
    46 	//TODO: Obtaining the memory use of target process doesn't work yet
       
    47 #if 0
       
    48 	TPtrC8 serverParam = ExtractTextL( KParamProcess );
       
    49 	HBufC16* server = CnvUtfConverter::ConvertToUnicodeFromUtf8L( serverParam );
       
    50 	CleanupStack::PushL( server );
       
    51 
       
    52 	HBufC* matchPattern = HBufC::NewL( server->Size() + 2 );
       
    53 	TPtr ptr = matchPattern->Des();
       
    54 	_LIT( KProcessMatchFormat, "*%S*" );
       
    55 	ptr.AppendFormat( KProcessMatchFormat, server );
       
    56 	CleanupStack::PopAndDestroy( server );
       
    57 	CleanupStack::PushL( matchPattern );
       
    58 
       
    59 #if ( !defined( EKA2 ) && ( defined( __WINS__ ) || defined( __WINSCW__ ) ) )
       
    60 	// Emulator doesn't have a concept of process (in EKA1)
       
    61 	RThread process;
       
    62 	TFindThread processFinder( *matchPattern );
       
    63 #else
       
    64 	RProcess process;
       
    65 	TFindProcess processFinder( *matchPattern );
       
    66 #endif
       
    67 	
       
    68 	// Find the process
       
    69 	TFullName processName;
       
    70 	if ( processFinder.Next( processName ) == KErrNone )
       
    71 		{
       
    72 		User::InfoPrint( _L( "Found" ) );
       
    73 		User::LeaveIfError( process.Open( processFinder ) );
       
    74 
       
    75 		TModuleMemoryInfo memInfo;
       
    76 		//Currently returns KErrNotSupported
       
    77 		TInt err = process.GetMemoryInfo( memInfo );
       
    78 		//What does the value returned by memInfo.GetInitialisedDataSize() mean?
       
    79 
       
    80 
       
    81 		//User-functions AllocSize, Available, CountAllocCells act on the
       
    82 		//currently active process
       
    83 		
       
    84 		//User::SwitchHeap could be used to set the head of the target process
       
    85 		//as the default heap, and then use RHeap::AllocSize? But how to get
       
    86 		//RHeap from RProcess?
       
    87 
       
    88 		//It is not allowed to use kernel code from user code
       
    89 		//(Kern::FreeRamInBytes etc)
       
    90 
       
    91 		process.Close();
       
    92 		}
       
    93 	
       
    94 	CleanupStack::PopAndDestroy( matchPattern );
       
    95 #endif // #if 0
       
    96 
       
    97 	// -- Response creation ---------------------------------------------------
       
    98 
       
    99 	AddIntegerResponseL( KParamUsedMemory, usedMemory );
       
   100 	AddIntegerResponseL( KParamFreeMemory, freeMemory );	
       
   101 	}
       
   102 
       
   103 TBool TCmdGetMemoryUsage::Match( const TTcIdentifier& aId )
       
   104 	{
       
   105 	return TTcSIPCommandBase::Match( aId, _L8("GetMemoryUsage") );
       
   106 	}
       
   107 
       
   108 TTcCommandBase* TCmdGetMemoryUsage::CreateL( MTcTestContext& aContext )
       
   109 	{
       
   110 	return new( ELeave ) TCmdGetMemoryUsage( aContext );
       
   111 	}