Update contrib.
1 // Copyright (c) 2002-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 class Thread : public BMProgram
24 Thread() : BMProgram(_L("Threads"))
26 virtual TBMResult* Run(TBMUInt64 aIter, TInt* aCount);
28 typedef void (*MeasurementFunc)(TBMResult*, TBMUInt64 aIter);
31 MeasurementFunc iFunc;
34 Measurement(MeasurementFunc aFunc, const TDesC& aName) :
35 iFunc(aFunc), iName(aName) {}
38 static TBMResult iResults[];
39 static Measurement iMeasurements[];
41 static TBMTicks iChildTime;
43 static void Creation(TBMResult*, TBMUInt64 aIter);
44 static TInt CreationChild(TAny*);
45 static void CreationSuicide(TBMResult*, TBMUInt64 aIter);
46 static TInt CreationSuicideChild(TAny*);
47 static void Suicide(TBMResult*, TBMUInt64 aIter);
48 static TInt SuicideChild(TAny*);
49 static void Killing(TBMResult*, TBMUInt64 aIter);
50 static TInt KillingChild(TAny*);
51 static void SetTls(TBMResult*, TBMUInt64 aIter);
52 static void GetTls(TBMResult*, TBMUInt64 aIter);
56 TInt prio = BMProgram::SetAbsPriority(RThread(), iOrigAbsPriority);
57 BMProgram::SetAbsPriority(RThread(), prio);
61 Thread::Measurement Thread::iMeasurements[] =
63 Measurement(&Thread::Creation, _L("Thread Creation Latency")),
64 Measurement(&Thread::CreationSuicide, _L("Thread Creation Suicide")),
65 Measurement(&Thread::Suicide, _L("Thread Suicide")),
66 Measurement(&Thread::Killing, _L("Thread Killing")),
67 Measurement(&Thread::SetTls, _L("Setting per-thread data")),
68 Measurement(&Thread::GetTls, _L("Getting per-thread data"))
70 TBMResult Thread::iResults[sizeof(Thread::iMeasurements)/sizeof(Thread::iMeasurements[0])];
72 TBMTicks Thread::iChildTime;
76 void Thread::Creation(TBMResult* aResult, TBMUInt64 aIter)
78 for (TBMUInt64 i = 0; i < aIter; ++i)
84 TInt r = child.Create(KNullDesC, Thread::CreationChild, 0x2000, NULL, NULL);
85 BM_ERROR(r, r == KErrNone);
87 BMProgram::SetAbsPriority(RThread(), KBMPriorityHigh);
89 User::WaitForRequest(st);
90 BM_ERROR(st.Int(), st == KErrNone);
91 aResult->Cumulate(TBMTicksDelta(t1, iChildTime));
92 CLOSE_AND_WAIT(child);
97 TInt Thread::CreationChild(TAny*)
99 ::bmTimer.Stamp(&iChildTime);
103 void Thread::CreationSuicide(TBMResult* aResult, TBMUInt64 aIter)
105 for (TBMUInt64 i = 0; i < aIter; ++i)
110 ::bmTimer.Stamp(&t1);
111 TInt r = child.Create(KNullDesC, Thread::CreationSuicideChild, 0x2000, NULL, NULL);
112 BM_ERROR(r, r == KErrNone);
114 BMProgram::SetAbsPriority(RThread(), KBMPriorityLow);
116 User::WaitForRequest(st);
117 BM_ERROR(st.Int(), st == KErrNone);
119 ::bmTimer.Stamp(&t2);
120 aResult->Cumulate(TBMTicksDelta(t1, t2));
121 CLOSE_AND_WAIT(child);
122 prog.EnableCleanup();
126 TInt Thread::CreationSuicideChild(TAny*)
131 void Thread::Suicide(TBMResult* aResult, TBMUInt64 aIter)
133 for (TBMUInt64 i = 0; i < aIter; ++i)
137 TInt r = child.Create(KNullDesC, Thread::SuicideChild, 0x2000, NULL, NULL);
138 BM_ERROR(r, r == KErrNone);
140 BMProgram::SetAbsPriority(RThread(), KBMPriorityLow);
142 User::WaitForRequest(st);
143 BM_ERROR(st.Int(), st == KErrNone);
145 ::bmTimer.Stamp(&t2);
146 aResult->Cumulate(TBMTicksDelta(iChildTime, t2));
147 CLOSE_AND_WAIT(child);
148 prog.EnableCleanup();
152 TInt Thread::SuicideChild(TAny*)
154 ::bmTimer.Stamp(&iChildTime);
158 void Thread::Killing(TBMResult* aResult, TBMUInt64 aIter)
160 for (TBMUInt64 i = 0; i < aIter; ++i)
164 TInt r = child.Create(KNullDesC, Thread::KillingChild, 0x2000, NULL, NULL);
165 BM_ERROR(r, r == KErrNone);
167 BMProgram::SetAbsPriority(RThread(), KBMPriorityHigh);
170 ::bmTimer.Stamp(&t1);
171 child.Kill(KErrCancel);
172 User::WaitForRequest(st);
173 BM_ERROR(st.Int(), st == KErrCancel);
175 ::bmTimer.Stamp(&t2);
176 aResult->Cumulate(TBMTicksDelta(t1, t2));
177 CLOSE_AND_WAIT(child);
178 prog.EnableCleanup();
182 TInt Thread::KillingChild(TAny*)
184 User::WaitForAnyRequest();
188 #define TLS_KEY ((TInt32) &Thread::SetTls)
190 void Thread::SetTls(TBMResult* aResult, TBMUInt64 aIter)
196 for (TBMUInt64 i = 0; i < aIter; ++i)
198 TInt r = UserSvr::DllSetTls(TLS_KEY, 0);
199 BM_ERROR(r, r == KErrNone);
201 TBMTicks t = ti.End();
202 aResult->Cumulate(t, aIter);
204 UserSvr::DllFreeTls(TLS_KEY);
207 void Thread::GetTls(TBMResult* aResult, TBMUInt64 aIter)
211 TInt r = UserSvr::DllSetTls(TLS_KEY, 0);
212 BM_ERROR(r, r == KErrNone);
216 for (TBMUInt64 i = 0; i < aIter; ++i)
218 UserSvr::DllTls(TLS_KEY);
220 TBMTicks t = ti.End();
221 aResult->Cumulate(t, aIter);
223 UserSvr::DllFreeTls(TLS_KEY);
226 TBMResult* Thread::Run(TBMUInt64 aIter, TInt* aCount)
228 TInt count = sizeof(iResults)/sizeof(iResults[0]);
230 for (TInt i = 0; i < count; ++i)
232 iResults[i].Reset(iMeasurements[i].iName);
233 iMeasurements[i].iFunc(&iResults[i], aIter);
234 iResults[i].Update();
243 BMProgram* next = bmSuite;
244 bmSuite=(BMProgram*)&prog;
245 bmSuite->Next()=next;