sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\misc\t_ramuse.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
struct SThread
|
sl@0
|
21 |
{
|
sl@0
|
22 |
TUint iId;
|
sl@0
|
23 |
HBufC* iFullName;
|
sl@0
|
24 |
TInt iHandles;
|
sl@0
|
25 |
};
|
sl@0
|
26 |
|
sl@0
|
27 |
struct SProcess
|
sl@0
|
28 |
{
|
sl@0
|
29 |
TUint iId;
|
sl@0
|
30 |
HBufC* iFullName;
|
sl@0
|
31 |
TInt iHandles;
|
sl@0
|
32 |
};
|
sl@0
|
33 |
|
sl@0
|
34 |
LOCAL_D RTest test(_L("T_RAMUSE"));
|
sl@0
|
35 |
LOCAL_D RArray<SThread> Threads;
|
sl@0
|
36 |
LOCAL_D RArray<SProcess> Processes;
|
sl@0
|
37 |
|
sl@0
|
38 |
LOCAL_C void GetProcessInfo()
|
sl@0
|
39 |
{
|
sl@0
|
40 |
TFindProcess fp(_L("*"));
|
sl@0
|
41 |
TFullName fn;
|
sl@0
|
42 |
while (fp.Next(fn)==KErrNone)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
RProcess p;
|
sl@0
|
45 |
TInt r=p.Open(fp);
|
sl@0
|
46 |
if (r!=KErrNone)
|
sl@0
|
47 |
continue;
|
sl@0
|
48 |
SProcess pInfo;
|
sl@0
|
49 |
TProcessId pid=p.Id();
|
sl@0
|
50 |
pInfo.iId=*((TUint*)&pid);
|
sl@0
|
51 |
pInfo.iFullName=fn.Alloc();
|
sl@0
|
52 |
pInfo.iHandles=-1;
|
sl@0
|
53 |
p.Close();
|
sl@0
|
54 |
Processes.InsertInUnsignedKeyOrder(pInfo);
|
sl@0
|
55 |
}
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
LOCAL_C void GetThreadInfo()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
TFindThread ft(_L("*"));
|
sl@0
|
61 |
TFullName fn;
|
sl@0
|
62 |
while (ft.Next(fn)==KErrNone)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
RThread t;
|
sl@0
|
65 |
TInt r=t.Open(ft);
|
sl@0
|
66 |
if (r!=KErrNone)
|
sl@0
|
67 |
continue;
|
sl@0
|
68 |
SThread tInfo;
|
sl@0
|
69 |
TThreadId tid=t.Id();
|
sl@0
|
70 |
tInfo.iId=*((TUint*)&tid);
|
sl@0
|
71 |
tInfo.iFullName=fn.Alloc();
|
sl@0
|
72 |
TInt tHandles;
|
sl@0
|
73 |
TInt pHandles;
|
sl@0
|
74 |
t.HandleCount(pHandles,tHandles);
|
sl@0
|
75 |
tInfo.iHandles=tHandles;
|
sl@0
|
76 |
RProcess p;
|
sl@0
|
77 |
r=t.Process(p);
|
sl@0
|
78 |
if (r==KErrNone)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
TProcessId pid=p.Id();
|
sl@0
|
81 |
SProcess pInfo;
|
sl@0
|
82 |
pInfo.iId=*((TUint*)&pid);
|
sl@0
|
83 |
TInt i;
|
sl@0
|
84 |
r=Processes.FindInUnsignedKeyOrder(pInfo,i);
|
sl@0
|
85 |
if (r==KErrNone)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
if (Processes[i].iHandles<0)
|
sl@0
|
88 |
Processes[i].iHandles=pHandles;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
p.Close();
|
sl@0
|
91 |
}
|
sl@0
|
92 |
t.Close();
|
sl@0
|
93 |
Threads.InsertInUnsignedKeyOrder(tInfo);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
LOCAL_C void DisplayProcessInfo()
|
sl@0
|
98 |
{
|
sl@0
|
99 |
TInt n=Processes.Count();
|
sl@0
|
100 |
TInt i;
|
sl@0
|
101 |
test.Printf(_L("%d Processes:\n"),n);
|
sl@0
|
102 |
for (i=0; i<n; i++)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
test.Printf(_L("%S %d handles\n"),Processes[i].iFullName,Processes[i].iHandles);
|
sl@0
|
105 |
test.Getch();
|
sl@0
|
106 |
}
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
LOCAL_C void DisplayThreadInfo()
|
sl@0
|
110 |
{
|
sl@0
|
111 |
TInt n=Threads.Count();
|
sl@0
|
112 |
TInt i;
|
sl@0
|
113 |
test.Printf(_L("%d Threads:\n"),n);
|
sl@0
|
114 |
for (i=0; i<n; i++)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
test.Printf(_L("%S %d handles\n"),Threads[i].iFullName,Threads[i].iHandles);
|
sl@0
|
117 |
test.Getch();
|
sl@0
|
118 |
}
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
#ifdef __EPOC32__
|
sl@0
|
122 |
extern TUint32 KernelHeapUsed();
|
sl@0
|
123 |
#else
|
sl@0
|
124 |
TUint32 KernelHeapUsed()
|
sl@0
|
125 |
{
|
sl@0
|
126 |
return 0;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
#endif
|
sl@0
|
129 |
|
sl@0
|
130 |
GLDEF_C TInt E32Main()
|
sl@0
|
131 |
{
|
sl@0
|
132 |
test.Title();
|
sl@0
|
133 |
test.Start(_L("Checking kernel RAM use"));
|
sl@0
|
134 |
|
sl@0
|
135 |
test.Printf(_L("Total kernel heap used = %d bytes\n"),KernelHeapUsed());
|
sl@0
|
136 |
|
sl@0
|
137 |
GetProcessInfo();
|
sl@0
|
138 |
GetThreadInfo();
|
sl@0
|
139 |
DisplayProcessInfo();
|
sl@0
|
140 |
DisplayThreadInfo();
|
sl@0
|
141 |
|
sl@0
|
142 |
test.End();
|
sl@0
|
143 |
return 0;
|
sl@0
|
144 |
}
|