phonebookengines/contactsmodel/tsrc/performance/T_PerfStartUp.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2005-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 "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 //
       
    15 
       
    16 /**
       
    17 @SYMPREQ                  PREQ1192 PREQ1187
       
    18 @SYMComponent             app-engines_cntmodel
       
    19 @SYMAuthor                Simon Mellor, JamesCl
       
    20 @SYMTestStatus            Implemented
       
    21 @SYMTestType              CT
       
    22 
       
    23 @SYMTestCaseDesc          Tests the performance of opening a corporate-profile database of 
       
    24 						  1000 contacts, creating a remote view and retrieving some contacts.
       
    25 
       
    26 @SYMTestActions           Measures the time taken to:
       
    27 						  -- Open the database file with CContactDatabase::OpenL().
       
    28 						  -- Create a RContactViewSortOrder and pass it to CContactRemoteView::NewL() 
       
    29 						     to create a new remote view.
       
    30 						  -- Retrieve contacts from the remote view using CContactRemoteView::ContactAtL().
       
    31 
       
    32 @SYMTestExpectedResults   Test cases will run without leaving and will output timing information.
       
    33 
       
    34 */
       
    35 
       
    36 #include "T_PerfStartUp.h"
       
    37 	
       
    38 /**
       
    39  Factory function for CStartUp
       
    40 */
       
    41 CStartUp* CStartUp::NewLC(RTest& aTest)
       
    42 	{
       
    43 	CStartUp* self = new (ELeave) CStartUp(aTest);
       
    44 	CleanupStack::PushL(self);
       
    45 	self->ConstructL();
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 CStartUp::CStartUp(RTest& aTest) : 
       
    50 	CActive(CActive::EPriorityStandard),
       
    51 	iTest(aTest)
       
    52 	{
       
    53 	}
       
    54 	
       
    55 void CStartUp::ConstructL()
       
    56 	{
       
    57 	_LIT(KStartUpTestTitle, "\nBeginning Startup Time testing...\n");
       
    58 	iTest.Printf(KStartUpTestTitle);
       
    59 
       
    60 	// This creates KNumTimings timing slots in iTimes
       
    61 	// which are then accessed with the TTimings enums
       
    62 	for (TInt i = 0; i < KNumTimings; ++i)
       
    63 		{
       
    64 		iTimes.AppendL(0);
       
    65 		}
       
    66 
       
    67 	CActiveScheduler::Add(this);
       
    68 	}
       
    69 
       
    70 CStartUp::~CStartUp()
       
    71 	{
       
    72 	Cancel();
       
    73 	Cleanup();
       
    74 	iTimes.Close();
       
    75 	}
       
    76 	
       
    77 /**
       
    78  This will get called after the view is ready to be used. The only things left to do are clean up
       
    79  any resources and stop the active scheduler.
       
    80 */
       
    81 void CStartUp::RunL()
       
    82 	{
       
    83 	if (iViewType == ERemoteContactsView) // groups view is empty so don't try to retrieve contacts
       
    84 		{
       
    85 		// Get the first 8 contacts like an app would in order to display them in the UI
       
    86 		// and then get the ninth contacts like an app would if scrolling down one.
       
    87 		RetrieveContactsL();
       
    88 		}
       
    89 	
       
    90 	// Print results
       
    91 	_LIT(KStartupTotalText, "Startup Total: %d s %03d\nof which:\n");
       
    92 	_LIT(KOpenDbText, "    Open database: %d s %03d\n");
       
    93 	_LIT(KCreateViewText, "    Create view: %d s %03d\n");
       
    94 	_LIT(KGetFirstTwentyContactsText, "Get first 20 contacts: %d s %03d\n");
       
    95 	_LIT(KGetTwentyFirstContactText, "Get 21st (scrolldown): %d s %03d\n");
       
    96 
       
    97 	TBuf<255> buf;
       
    98 	TInt startupTotal = iTimes[EOpenDatabase]  + iTimes[ECreateView];
       
    99 	buf.AppendFormat(KStartupTotalText, (startupTotal / 1000000), ((startupTotal / 1000) % 1000));
       
   100 	buf.AppendFormat(KOpenDbText, (iTimes[EOpenDatabase] / 1000000), ((iTimes[EOpenDatabase] / 1000) % 1000));
       
   101 	buf.AppendFormat(KCreateViewText, (iTimes[ECreateView] / 1000000), ((iTimes[ECreateView] / 1000) % 1000));
       
   102 	if (iViewType == ERemoteContactsView)
       
   103 		{
       
   104 		buf.AppendFormat(KGetFirstTwentyContactsText, (iTimes[EGetFirstTwenty] / 1000000), ((iTimes[EGetFirstTwenty] / 1000) % 1000));
       
   105 		buf.AppendFormat(KGetTwentyFirstContactText, (iTimes[EGetTwentyFirst] / 1000000), ((iTimes[EGetTwentyFirst] / 1000) % 1000));
       
   106 
       
   107 		// Put the time for retrieving the first twenty in the variable passed in 
       
   108 		// to the DoTestL function to which iMs20FromViewPtr is pointing. Horrid.
       
   109 		*iNumMsToGet20ItemsFromViewPtr = iTimes[EGetFirstTwenty];
       
   110 		}
       
   111 	iTest.Printf(buf);
       
   112 
       
   113 
       
   114 	// Cleanup: Close the database and remote view
       
   115 	Cleanup();
       
   116 		
       
   117 	// Stop the active scheduler
       
   118 	CActiveScheduler::Stop();
       
   119 	}
       
   120 
       
   121 /**
       
   122  Implementation of CActive::DoCancel for CStartUp.
       
   123 */
       
   124 void CStartUp::DoCancel()
       
   125 	{
       
   126 	}
       
   127 	
       
   128 void CStartUp::CompleteSelf()
       
   129 	{
       
   130 	TRequestStatus* pStat = &iStatus;
       
   131   	User::RequestComplete(pStat, KErrNone);
       
   132    	SetActive();
       
   133 	}
       
   134 
       
   135 /**
       
   136  Begin the start-up test case. Opening the database is synchcronous as is the first
       
   137  part of creating the remote view. The second part (where the view is populated
       
   138  with contacts) is asynchronous and finishes when CStartUp::HandleContactViewEvent
       
   139  is called. CStartUp::RunL then just cleans up once the test case is finished.
       
   140 */
       
   141 void CStartUp::DoTestL(const TDesC& aDbName, TViewType aViewType, TInt& aNumMsToGet20ItemsFromView)
       
   142 	{
       
   143 	iViewType = aViewType;
       
   144 	iNumMsToGet20ItemsFromViewPtr = &aNumMsToGet20ItemsFromView;
       
   145 	_LIT(KRemoteContactViewText, "\n[Remote Contacts view]\n");
       
   146 	_LIT(KRemoteGroupViewText,   "\n[Remote Groups view]\n");
       
   147 	TBuf<32> buf;
       
   148 	if (iViewType == ERemoteContactsView)
       
   149 		{
       
   150 		buf.Append(KRemoteContactViewText);
       
   151 		}
       
   152 	else
       
   153 		{
       
   154 		buf.Append(KRemoteGroupViewText); 
       
   155 		}
       
   156 
       
   157 	iTest.Printf(buf);
       
   158 
       
   159 	// open database
       
   160 	OpenDatabaseL(aDbName);
       
   161 	
       
   162 	// create view
       
   163 	CreateRemoteViewL();
       
   164 	CActiveScheduler::Start();
       
   165 	}
       
   166 
       
   167 /**
       
   168  Called when the remote contact view is ready to be used. Records the time taken to 
       
   169  asynchronously create the remote view.
       
   170 */
       
   171 void CStartUp::HandleContactViewEvent(const CContactViewBase& aView, const TContactViewEvent& aEvent)
       
   172 	{
       
   173 	if (aEvent.iEventType == TContactViewEvent::EReady && &aView == iContactRemoteView)
       
   174 		{
       
   175 		// Called when the view is ready to use; complete the request status.
       
   176 		iTimer.StopTimer();
       
   177 		iTimes[ECreateView] = iTimer.Result();
       
   178 		iTimer.ResetTimer();
       
   179 		CompleteSelf();
       
   180 		}
       
   181 	}
       
   182 
       
   183 /**
       
   184  Times the opening of the database.
       
   185 */
       
   186 void CStartUp::OpenDatabaseL(const TDesC& aDbName)
       
   187 	{	
       
   188 	_LIT(KOpenDatabaseTitleFormat, "Opening Database: %S... \n");
       
   189 	iTest.Printf(KOpenDatabaseTitleFormat, &aDbName);
       
   190 
       
   191 	iTimer.ResetTimer();
       
   192 	iTimer.StartTimer();
       
   193 	iContactsDb = CContactDatabase::OpenL(aDbName);
       
   194 	iTimer.StopTimer();
       
   195 
       
   196 	iTimes[EOpenDatabase] = iTimer.Result();
       
   197 	iTimer.ResetTimer();
       
   198 	}
       
   199 
       
   200 /**
       
   201  Times the synchronous part of remote view creation.
       
   202 */
       
   203 void CStartUp::CreateRemoteViewL()
       
   204 	{
       
   205 	iTimer.ResetTimer();
       
   206 	iTimer.StartTimer();
       
   207 
       
   208 	RContactViewSortOrder viewSortOrder;
       
   209 	CleanupClosePushL(viewSortOrder);
       
   210 	
       
   211 	viewSortOrder.AppendL(KUidContactFieldFamilyName);
       
   212 	viewSortOrder.AppendL(KUidContactFieldGivenName);
       
   213 	viewSortOrder.AppendL(KUidContactFieldCompanyName);
       
   214 
       
   215 	if (iViewType == ERemoteContactsView)
       
   216 		{
       
   217 		iContactRemoteView = CContactRemoteView::NewL(*this, *iContactsDb, viewSortOrder, EContactsOnly);
       
   218 		}
       
   219 	else if (iViewType == ERemoteGroupsView)
       
   220 		{
       
   221 		iContactRemoteView = CContactRemoteView::NewL(*this, *iContactsDb, viewSortOrder, EGroupsOnly);
       
   222 		}
       
   223 	
       
   224 	CleanupStack::PopAndDestroy(&viewSortOrder);
       
   225 	}
       
   226 
       
   227 /**
       
   228  Deletes any resources used by this class.
       
   229 */
       
   230 void CStartUp::Cleanup()
       
   231 	{
       
   232 	if (iContactRemoteView) 
       
   233 		{
       
   234 		iContactRemoteView->Close(*this);
       
   235 		iContactRemoteView = NULL;
       
   236 		}
       
   237 
       
   238 	if (iContactsDb) 
       
   239 		{
       
   240 		delete iContactsDb;
       
   241 		iContactsDb = NULL;
       
   242 		}   
       
   243 	}
       
   244 	
       
   245 /**
       
   246  This gets the first 20 contacts from the remote view in the same way that 
       
   247  an app would to populate the UI view. Then it gets the 21st contacts from 
       
   248  the remote view in the same way that an app would when scrolling down one.
       
   249 */
       
   250 void CStartUp::RetrieveContactsL()
       
   251 	{
       
   252 	iTimer.ResetTimer();
       
   253 	iTimer.StartTimer();
       
   254 	const TInt K20CViewContactsToGet(20);
       
   255 	for (TInt ii = 0; ii < K20CViewContactsToGet; ++ii)
       
   256 		{
       
   257 		const CViewContact& viewContact = iContactRemoteView->ContactAtL(ii);
       
   258 		}
       
   259 	iTimer.StopTimer();
       
   260 	iTimes[EGetFirstTwenty] = iTimer.Result();
       
   261 	iTimer.ResetTimer();
       
   262 	
       
   263 	iTimer.StartTimer();
       
   264 	const TInt K21stCViewContact(K20CViewContactsToGet + 1);
       
   265 	const CViewContact& viewContact = iContactRemoteView->ContactAtL(K21stCViewContact);
       
   266 	iTimes[EGetTwentyFirst] = iTimer.Result();
       
   267 	iTimer.ResetTimer();
       
   268 	}