sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\bench\t_kernbm.cpp sl@0: // Overview: sl@0: // Benchmark the performance of some kernel functions including RTimer sl@0: // and RThread. Calculation time required for creation & closing of sl@0: // timer objects, suspension of threads, handling kernel messages, and sl@0: // the number of threads created and stopped within a fixed time period. sl@0: // API Information: sl@0: // RTimer, RThread. sl@0: // Details: sl@0: // - Calculate and display the time required to create and close 1000 sl@0: // thread-relative timer objects. sl@0: // - Count and print the time taken to suspend the thread for 100000 times. sl@0: // - Count and display the time consumed for 100000 kernel messages. sl@0: // - Get and print the number of threads created and stopped within a sl@0: // specified timeframe, verify the ExitType, and ExitReason of the threads. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: #define TIMECOUNT() User::NTickCount() sl@0: #define TIMEDIFFMS(i,f) (f-i) sl@0: sl@0: LOCAL_D RTest test(_L("T_KERNBM")); sl@0: volatile TInt Count; sl@0: volatile TBool Stop; sl@0: sl@0: #ifdef __EPOC32__ sl@0: extern void DummyKernMsg(); sl@0: #else sl@0: void DummyKernMsg() sl@0: {} sl@0: #endif sl@0: sl@0: LOCAL_C TInt ThreadFunction(TAny*) sl@0: { sl@0: User::WaitForAnyRequest(); sl@0: return 0; sl@0: } sl@0: sl@0: TInt TestThread(TAny*) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: TInt TestThreadCreate(TAny*) sl@0: { sl@0: RThread t; sl@0: t.SetPriority(EPriorityAbsoluteVeryLow); sl@0: while (!Stop) sl@0: { sl@0: t.Create(KNullDesC,TestThread,4096,NULL,NULL); sl@0: t.Resume(); sl@0: t.Close(); sl@0: ++Count; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Start...\n")); sl@0: sl@0: RTimer t; sl@0: TInt i; sl@0: TInt r; sl@0: TUint32 c1=TIMECOUNT(); sl@0: for (i=0; i<1000; i++) sl@0: { sl@0: r=t.CreateLocal(); sl@0: if (r!=KErrNone) sl@0: test(0); sl@0: t.Close(); sl@0: } sl@0: TUint32 c2=TIMECOUNT(); sl@0: test.Printf(_L("Create and close 1000 timers takes %d ms\n"),TIMEDIFFMS(c1,c2)); sl@0: sl@0: RThread thrd; sl@0: r=thrd.Create(_L("DodgyThread"),ThreadFunction,4096,1024,8192,NULL); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("DodgyThread created\n")); sl@0: thrd.SetPriority(EPriorityMore); sl@0: thrd.Resume(); sl@0: test.Printf(_L("DodgyThread resumed\n")); sl@0: c1=TIMECOUNT(); sl@0: for (i=0; i<100000; i++) sl@0: { sl@0: thrd.Suspend(); sl@0: } sl@0: c2=TIMECOUNT(); sl@0: test.Printf(_L("Suspend 100000 times takes %d ms\n"),TIMEDIFFMS(c1,c2)); sl@0: thrd.Kill(0); sl@0: thrd.Close(); sl@0: test.Printf(_L("DodgyThread killed\n")); sl@0: sl@0: c1=TIMECOUNT(); sl@0: for (i=0; i<100000; i++) sl@0: { sl@0: DummyKernMsg(); sl@0: } sl@0: c2=TIMECOUNT(); sl@0: test.Printf(_L("100000 kernel messages take %d ms\n"),TIMEDIFFMS(c1,c2)); sl@0: sl@0: test.Next(_L("Create thread test")); sl@0: r=thrd.Create(_L("Creator"),TestThreadCreate,4096,NULL,NULL); sl@0: test(r==KErrNone); sl@0: thrd.SetPriority(EPriorityLess); sl@0: RThread().SetPriority(EPriorityMuchMore); sl@0: TRequestStatus s; sl@0: thrd.Logon(s); sl@0: thrd.Resume(); sl@0: Count=0; sl@0: Stop=EFalse; sl@0: c1=TIMECOUNT(); sl@0: User::After(1000000); sl@0: Stop=ETrue; sl@0: User::WaitForRequest(s); sl@0: c2=TIMECOUNT(); sl@0: test(thrd.ExitType()==EExitKill); sl@0: test(thrd.ExitReason()==0); sl@0: thrd.Close(); sl@0: test.Printf(_L("%d threads created and stopped in %dms\n"),Count,TIMEDIFFMS(c1,c2)); sl@0: sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: