os/kernelhwsrv/kerneltest/e32test/misc/t_ramuse.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/t_ramuse.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,144 @@
     1.4 +// Copyright (c) 1998-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 the License "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 +// e32test\misc\t_ramuse.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32test.h>
    1.22 +
    1.23 +struct SThread
    1.24 +	{
    1.25 +	TUint iId;
    1.26 +	HBufC* iFullName;
    1.27 +	TInt iHandles;
    1.28 +	};
    1.29 +
    1.30 +struct SProcess
    1.31 +	{
    1.32 +	TUint iId;
    1.33 +	HBufC* iFullName;
    1.34 +	TInt iHandles;
    1.35 +	};
    1.36 +
    1.37 +LOCAL_D RTest test(_L("T_RAMUSE"));
    1.38 +LOCAL_D RArray<SThread> Threads;
    1.39 +LOCAL_D RArray<SProcess> Processes;
    1.40 +
    1.41 +LOCAL_C void GetProcessInfo()
    1.42 +	{
    1.43 +	TFindProcess fp(_L("*"));
    1.44 +	TFullName fn;
    1.45 +	while (fp.Next(fn)==KErrNone)
    1.46 +		{
    1.47 +		RProcess p;
    1.48 +		TInt r=p.Open(fp);
    1.49 +		if (r!=KErrNone)
    1.50 +			continue;
    1.51 +		SProcess pInfo;
    1.52 +		TProcessId pid=p.Id();
    1.53 +		pInfo.iId=*((TUint*)&pid);
    1.54 +		pInfo.iFullName=fn.Alloc();
    1.55 +		pInfo.iHandles=-1;
    1.56 +		p.Close();
    1.57 +		Processes.InsertInUnsignedKeyOrder(pInfo);
    1.58 +		}
    1.59 +	}
    1.60 +
    1.61 +LOCAL_C void GetThreadInfo()
    1.62 +	{
    1.63 +	TFindThread ft(_L("*"));
    1.64 +	TFullName fn;
    1.65 +	while (ft.Next(fn)==KErrNone)
    1.66 +		{
    1.67 +		RThread t;
    1.68 +		TInt r=t.Open(ft);
    1.69 +		if (r!=KErrNone)
    1.70 +			continue;
    1.71 +		SThread tInfo;
    1.72 +		TThreadId tid=t.Id();
    1.73 +		tInfo.iId=*((TUint*)&tid);
    1.74 +		tInfo.iFullName=fn.Alloc();
    1.75 +		TInt tHandles;
    1.76 +		TInt pHandles;
    1.77 +		t.HandleCount(pHandles,tHandles);
    1.78 +		tInfo.iHandles=tHandles;
    1.79 +		RProcess p;
    1.80 +		r=t.Process(p);
    1.81 +		if (r==KErrNone)
    1.82 +			{
    1.83 +			TProcessId pid=p.Id();
    1.84 +			SProcess pInfo;
    1.85 +			pInfo.iId=*((TUint*)&pid);
    1.86 +			TInt i;
    1.87 +			r=Processes.FindInUnsignedKeyOrder(pInfo,i);
    1.88 +			if (r==KErrNone)
    1.89 +				{
    1.90 +				if (Processes[i].iHandles<0)
    1.91 +					Processes[i].iHandles=pHandles;
    1.92 +				}
    1.93 +			p.Close();
    1.94 +			}
    1.95 +		t.Close();
    1.96 +		Threads.InsertInUnsignedKeyOrder(tInfo);
    1.97 +		}
    1.98 +	}
    1.99 +
   1.100 +LOCAL_C void DisplayProcessInfo()
   1.101 +	{
   1.102 +	TInt n=Processes.Count();
   1.103 +	TInt i;
   1.104 +	test.Printf(_L("%d Processes:\n"),n);
   1.105 +	for (i=0; i<n; i++)
   1.106 +		{
   1.107 +		test.Printf(_L("%S %d handles\n"),Processes[i].iFullName,Processes[i].iHandles);
   1.108 +		test.Getch();
   1.109 +		}
   1.110 +	}
   1.111 +
   1.112 +LOCAL_C void DisplayThreadInfo()
   1.113 +	{
   1.114 +	TInt n=Threads.Count();
   1.115 +	TInt i;
   1.116 +	test.Printf(_L("%d Threads:\n"),n);
   1.117 +	for (i=0; i<n; i++)
   1.118 +		{
   1.119 +		test.Printf(_L("%S %d handles\n"),Threads[i].iFullName,Threads[i].iHandles);
   1.120 +		test.Getch();
   1.121 +		}
   1.122 +	}
   1.123 +
   1.124 +#ifdef __EPOC32__
   1.125 +extern TUint32 KernelHeapUsed();
   1.126 +#else
   1.127 +TUint32 KernelHeapUsed()
   1.128 +	{
   1.129 +	return 0;
   1.130 +	}
   1.131 +#endif
   1.132 +
   1.133 +GLDEF_C TInt E32Main()
   1.134 +	{
   1.135 +	test.Title();
   1.136 +	test.Start(_L("Checking kernel RAM use"));
   1.137 +
   1.138 +	test.Printf(_L("Total kernel heap used = %d bytes\n"),KernelHeapUsed());
   1.139 +
   1.140 +	GetProcessInfo();
   1.141 +	GetThreadInfo();
   1.142 +	DisplayProcessInfo();
   1.143 +	DisplayThreadInfo();
   1.144 +
   1.145 +	test.End();
   1.146 +	return 0;
   1.147 +	}