sl@0
|
1 |
// Copyright (c) 1995-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\bench\t_kernbm.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Benchmark the performance of some kernel functions including RTimer
|
sl@0
|
17 |
// and RThread. Calculation time required for creation & closing of
|
sl@0
|
18 |
// timer objects, suspension of threads, handling kernel messages, and
|
sl@0
|
19 |
// the number of threads created and stopped within a fixed time period.
|
sl@0
|
20 |
// API Information:
|
sl@0
|
21 |
// RTimer, RThread.
|
sl@0
|
22 |
// Details:
|
sl@0
|
23 |
// - Calculate and display the time required to create and close 1000
|
sl@0
|
24 |
// thread-relative timer objects.
|
sl@0
|
25 |
// - Count and print the time taken to suspend the thread for 100000 times.
|
sl@0
|
26 |
// - Count and display the time consumed for 100000 kernel messages.
|
sl@0
|
27 |
// - Get and print the number of threads created and stopped within a
|
sl@0
|
28 |
// specified timeframe, verify the ExitType, and ExitReason of the threads.
|
sl@0
|
29 |
// Platforms/Drives/Compatibility:
|
sl@0
|
30 |
// All.
|
sl@0
|
31 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
32 |
// Failures and causes:
|
sl@0
|
33 |
// Base Port information:
|
sl@0
|
34 |
//
|
sl@0
|
35 |
//
|
sl@0
|
36 |
|
sl@0
|
37 |
#include <e32test.h>
|
sl@0
|
38 |
|
sl@0
|
39 |
#define TIMECOUNT() User::NTickCount()
|
sl@0
|
40 |
#define TIMEDIFFMS(i,f) (f-i)
|
sl@0
|
41 |
|
sl@0
|
42 |
LOCAL_D RTest test(_L("T_KERNBM"));
|
sl@0
|
43 |
volatile TInt Count;
|
sl@0
|
44 |
volatile TBool Stop;
|
sl@0
|
45 |
|
sl@0
|
46 |
#ifdef __EPOC32__
|
sl@0
|
47 |
extern void DummyKernMsg();
|
sl@0
|
48 |
#else
|
sl@0
|
49 |
void DummyKernMsg()
|
sl@0
|
50 |
{}
|
sl@0
|
51 |
#endif
|
sl@0
|
52 |
|
sl@0
|
53 |
LOCAL_C TInt ThreadFunction(TAny*)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
User::WaitForAnyRequest();
|
sl@0
|
56 |
return 0;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
TInt TestThread(TAny*)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
return 0;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
TInt TestThreadCreate(TAny*)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
RThread t;
|
sl@0
|
67 |
t.SetPriority(EPriorityAbsoluteVeryLow);
|
sl@0
|
68 |
while (!Stop)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
t.Create(KNullDesC,TestThread,4096,NULL,NULL);
|
sl@0
|
71 |
t.Resume();
|
sl@0
|
72 |
t.Close();
|
sl@0
|
73 |
++Count;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
return 0;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
GLDEF_C TInt E32Main()
|
sl@0
|
79 |
{
|
sl@0
|
80 |
test.Title();
|
sl@0
|
81 |
test.Start(_L("Start...\n"));
|
sl@0
|
82 |
|
sl@0
|
83 |
RTimer t;
|
sl@0
|
84 |
TInt i;
|
sl@0
|
85 |
TInt r;
|
sl@0
|
86 |
TUint32 c1=TIMECOUNT();
|
sl@0
|
87 |
for (i=0; i<1000; i++)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
r=t.CreateLocal();
|
sl@0
|
90 |
if (r!=KErrNone)
|
sl@0
|
91 |
test(0);
|
sl@0
|
92 |
t.Close();
|
sl@0
|
93 |
}
|
sl@0
|
94 |
TUint32 c2=TIMECOUNT();
|
sl@0
|
95 |
test.Printf(_L("Create and close 1000 timers takes %d ms\n"),TIMEDIFFMS(c1,c2));
|
sl@0
|
96 |
|
sl@0
|
97 |
RThread thrd;
|
sl@0
|
98 |
r=thrd.Create(_L("DodgyThread"),ThreadFunction,4096,1024,8192,NULL);
|
sl@0
|
99 |
test(r==KErrNone);
|
sl@0
|
100 |
test.Printf(_L("DodgyThread created\n"));
|
sl@0
|
101 |
thrd.SetPriority(EPriorityMore);
|
sl@0
|
102 |
thrd.Resume();
|
sl@0
|
103 |
test.Printf(_L("DodgyThread resumed\n"));
|
sl@0
|
104 |
c1=TIMECOUNT();
|
sl@0
|
105 |
for (i=0; i<100000; i++)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
thrd.Suspend();
|
sl@0
|
108 |
}
|
sl@0
|
109 |
c2=TIMECOUNT();
|
sl@0
|
110 |
test.Printf(_L("Suspend 100000 times takes %d ms\n"),TIMEDIFFMS(c1,c2));
|
sl@0
|
111 |
thrd.Kill(0);
|
sl@0
|
112 |
thrd.Close();
|
sl@0
|
113 |
test.Printf(_L("DodgyThread killed\n"));
|
sl@0
|
114 |
|
sl@0
|
115 |
c1=TIMECOUNT();
|
sl@0
|
116 |
for (i=0; i<100000; i++)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
DummyKernMsg();
|
sl@0
|
119 |
}
|
sl@0
|
120 |
c2=TIMECOUNT();
|
sl@0
|
121 |
test.Printf(_L("100000 kernel messages take %d ms\n"),TIMEDIFFMS(c1,c2));
|
sl@0
|
122 |
|
sl@0
|
123 |
test.Next(_L("Create thread test"));
|
sl@0
|
124 |
r=thrd.Create(_L("Creator"),TestThreadCreate,4096,NULL,NULL);
|
sl@0
|
125 |
test(r==KErrNone);
|
sl@0
|
126 |
thrd.SetPriority(EPriorityLess);
|
sl@0
|
127 |
RThread().SetPriority(EPriorityMuchMore);
|
sl@0
|
128 |
TRequestStatus s;
|
sl@0
|
129 |
thrd.Logon(s);
|
sl@0
|
130 |
thrd.Resume();
|
sl@0
|
131 |
Count=0;
|
sl@0
|
132 |
Stop=EFalse;
|
sl@0
|
133 |
c1=TIMECOUNT();
|
sl@0
|
134 |
User::After(1000000);
|
sl@0
|
135 |
Stop=ETrue;
|
sl@0
|
136 |
User::WaitForRequest(s);
|
sl@0
|
137 |
c2=TIMECOUNT();
|
sl@0
|
138 |
test(thrd.ExitType()==EExitKill);
|
sl@0
|
139 |
test(thrd.ExitReason()==0);
|
sl@0
|
140 |
thrd.Close();
|
sl@0
|
141 |
test.Printf(_L("%d threads created and stopped in %dms\n"),Count,TIMEDIFFMS(c1,c2));
|
sl@0
|
142 |
|
sl@0
|
143 |
test.End();
|
sl@0
|
144 |
return 0;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|