kerneltest/e32test/misc/t_ramuse.cpp
changeset 9 96e5fb8b040d
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 // Copyright (c) 1998-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 the License "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 // e32test\misc\t_ramuse.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 
       
    20 struct SThread
       
    21 	{
       
    22 	TUint iId;
       
    23 	HBufC* iFullName;
       
    24 	TInt iHandles;
       
    25 	};
       
    26 
       
    27 struct SProcess
       
    28 	{
       
    29 	TUint iId;
       
    30 	HBufC* iFullName;
       
    31 	TInt iHandles;
       
    32 	};
       
    33 
       
    34 LOCAL_D RTest test(_L("T_RAMUSE"));
       
    35 LOCAL_D RArray<SThread> Threads;
       
    36 LOCAL_D RArray<SProcess> Processes;
       
    37 
       
    38 LOCAL_C void GetProcessInfo()
       
    39 	{
       
    40 	TFindProcess fp(_L("*"));
       
    41 	TFullName fn;
       
    42 	while (fp.Next(fn)==KErrNone)
       
    43 		{
       
    44 		RProcess p;
       
    45 		TInt r=p.Open(fp);
       
    46 		if (r!=KErrNone)
       
    47 			continue;
       
    48 		SProcess pInfo;
       
    49 		TProcessId pid=p.Id();
       
    50 		pInfo.iId=*((TUint*)&pid);
       
    51 		pInfo.iFullName=fn.Alloc();
       
    52 		pInfo.iHandles=-1;
       
    53 		p.Close();
       
    54 		Processes.InsertInUnsignedKeyOrder(pInfo);
       
    55 		}
       
    56 	}
       
    57 
       
    58 LOCAL_C void GetThreadInfo()
       
    59 	{
       
    60 	TFindThread ft(_L("*"));
       
    61 	TFullName fn;
       
    62 	while (ft.Next(fn)==KErrNone)
       
    63 		{
       
    64 		RThread t;
       
    65 		TInt r=t.Open(ft);
       
    66 		if (r!=KErrNone)
       
    67 			continue;
       
    68 		SThread tInfo;
       
    69 		TThreadId tid=t.Id();
       
    70 		tInfo.iId=*((TUint*)&tid);
       
    71 		tInfo.iFullName=fn.Alloc();
       
    72 		TInt tHandles;
       
    73 		TInt pHandles;
       
    74 		t.HandleCount(pHandles,tHandles);
       
    75 		tInfo.iHandles=tHandles;
       
    76 		RProcess p;
       
    77 		r=t.Process(p);
       
    78 		if (r==KErrNone)
       
    79 			{
       
    80 			TProcessId pid=p.Id();
       
    81 			SProcess pInfo;
       
    82 			pInfo.iId=*((TUint*)&pid);
       
    83 			TInt i;
       
    84 			r=Processes.FindInUnsignedKeyOrder(pInfo,i);
       
    85 			if (r==KErrNone)
       
    86 				{
       
    87 				if (Processes[i].iHandles<0)
       
    88 					Processes[i].iHandles=pHandles;
       
    89 				}
       
    90 			p.Close();
       
    91 			}
       
    92 		t.Close();
       
    93 		Threads.InsertInUnsignedKeyOrder(tInfo);
       
    94 		}
       
    95 	}
       
    96 
       
    97 LOCAL_C void DisplayProcessInfo()
       
    98 	{
       
    99 	TInt n=Processes.Count();
       
   100 	TInt i;
       
   101 	test.Printf(_L("%d Processes:\n"),n);
       
   102 	for (i=0; i<n; i++)
       
   103 		{
       
   104 		test.Printf(_L("%S %d handles\n"),Processes[i].iFullName,Processes[i].iHandles);
       
   105 		test.Getch();
       
   106 		}
       
   107 	}
       
   108 
       
   109 LOCAL_C void DisplayThreadInfo()
       
   110 	{
       
   111 	TInt n=Threads.Count();
       
   112 	TInt i;
       
   113 	test.Printf(_L("%d Threads:\n"),n);
       
   114 	for (i=0; i<n; i++)
       
   115 		{
       
   116 		test.Printf(_L("%S %d handles\n"),Threads[i].iFullName,Threads[i].iHandles);
       
   117 		test.Getch();
       
   118 		}
       
   119 	}
       
   120 
       
   121 #ifdef __EPOC32__
       
   122 extern TUint32 KernelHeapUsed();
       
   123 #else
       
   124 TUint32 KernelHeapUsed()
       
   125 	{
       
   126 	return 0;
       
   127 	}
       
   128 #endif
       
   129 
       
   130 GLDEF_C TInt E32Main()
       
   131 	{
       
   132 	test.Title();
       
   133 	test.Start(_L("Checking kernel RAM use"));
       
   134 
       
   135 	test.Printf(_L("Total kernel heap used = %d bytes\n"),KernelHeapUsed());
       
   136 
       
   137 	GetProcessInfo();
       
   138 	GetThreadInfo();
       
   139 	DisplayProcessInfo();
       
   140 	DisplayThreadInfo();
       
   141 
       
   142 	test.End();
       
   143 	return 0;
       
   144 	}