summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/performance/t_perfsyncdelete.cpp
blob: 70e749c09cc63903919f2560f919848974009965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
* This is a performance test harness measuring a sync deletion of 
* a proportion of Contacts in the default database.
*
*/


#include <cntvcard.h>
#include <cntitem.h>
#include <f32file.h>
#include <s32mem.h>
#include "t_perfsyncdelete.h"
#include "../t_utils.h"

// Constants

_LIT(KDbName,"C:Contacts.cdb");

const TPtrC KDbPath((KDbName)); 
const TInt KCompactResolution = 16;
_LIT(KOutputFormat,"Sync Delete took: %d s %03d deleting %d of %d Contacts\n");

CSyncDelete::CSyncDelete(TInt64 aSeed)
	{
	iRandSeed = aSeed;
	} 

CSyncDelete::~CSyncDelete()
	{
	delete iDb;
	iFs.Close();
	} 
	
CSyncDelete* CSyncDelete::NewLC(RTest& aTest, TInt64 ranSeed)
	{;
	CSyncDelete* self = new (ELeave) CSyncDelete(ranSeed);
	CleanupStack::PushL(self);
	self->ConstructL(aTest);
	return(self);
	}  

void CSyncDelete::ConstructL(RTest& aTest)
	{
	iTest = &aTest;
	iDb = CContactDatabase::OpenL(KDbPath);
	User::LeaveIfError(iFs.Connect());
	CCntTest::ProfileReset(0, 59);
	} 

TBool CSyncDelete::ExistsInArray(const CArrayFix<TInt>& aArr, TInt aSize, TInt aNum)
/**
    Returns whether aNum exists in aArr from 0 to aSize in the aArr array
*/
	{
	for(TInt i = 0; i < aSize; ++i)
		{
		if (aNum == aArr[i])
			{
			return ETrue;
			}
		}
	return EFalse;
	}
	
void CSyncDelete::CreateRandomIdArray(CArrayFix<TInt>& aUids, TInt aNumIds, TInt aNumEntriesInDb)
/*
	Creates a random array of numbers corresponding to the uids in the 
	Contacts model.  No UID is repeated  
*/
	{
	for(TInt i = 0; i < aNumIds; ++i)
		{
		TInt uid = Math::Rand(iRandSeed)%(aNumEntriesInDb-1)+1;
		while(ExistsInArray(aUids,i,uid))
			{
			uid = Math::Rand(iRandSeed)%(aNumEntriesInDb-1)+1;
			}
		aUids[i] = uid;		
		}
	}
	
void CSyncDelete::CleanupPtrArray(TAny* aCArrayPtr)
/**
	Static convenience cleanup method copied from CSmlContactsDba  
*/
	{ 
	CArrayPtr<CContactItem>* array = reinterpret_cast<CArrayPtr<CContactItem>*>(aCArrayPtr);
	array->ResetAndDestroy();
	delete array;
	}	

void CSyncDelete::DoSyncL(TInt aEntryCount, TInt aNumEntriesInDb)
/** This routine deleted aEntryCount of aNumEntriesInDb where the Ids to delete are 
    generated at random.  This harness does not tests Sync Update
*/	
	{
	// create an array of random, non-repeating contact ids
	CArrayFixFlat<TInt>* uids = new(ELeave) CArrayFixFlat<TInt>(aEntryCount);
	CleanupStack::PushL(uids);
	uids->ResizeL(aEntryCount);	
	CreateRandomIdArray(*uids,aEntryCount,aNumEntriesInDb);
	
	// Most SML servers perform all the delete operations followed by all the
	// update operations (or vice verca) rather than intermingling the 2
	// operations. We are only interested in the deletion aspect at this state.
	//
	CCntTest::ProfileStart(0);
	for (TInt i = 0; i < aEntryCount; ++i)
		{		;
		const TContactItemId KEntryId = static_cast<TContactItemId>((*uids)[i]); 
		iDb->DeleteContactL(KEntryId);
		
		if ((i > 0) && ((i % KCompactResolution) == 0)) 
			{
			iDb->CompactL();
			}
		}
	CleanupStack::PopAndDestroy(uids);	
	CCntTest::ProfileEnd(0);
	
	TCntProfile p[1];
	TBuf<64> formattable;
	TInt sec;
	TInt msec; 
	
	CCntTest::ProfileResult(&p[0],0,1);	
	sec = p[0].iTime/1000000;
	msec = (p[0].iTime/1000)%1000;
	formattable.Format(KOutputFormat, sec, msec, aEntryCount, aNumEntriesInDb);
	iTest->Printf(formattable);
	}