2012-03-19 20:22:20 +04:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This test is meant to exercise the performance of Fennec's
|
|
|
|
* history and bookmarks content provider.
|
|
|
|
*/
|
|
|
|
public class testBrowserProviderPerf extends ContentProviderTest {
|
2012-03-24 02:52:20 +04:00
|
|
|
private final int NUMBER_OF_BASIC_HISTORY_URLS = 10000;
|
|
|
|
private final int NUMBER_OF_BASIC_BOOKMARK_URLS = 500;
|
|
|
|
private final int NUMBER_OF_COMBINED_URLS = 500;
|
|
|
|
|
2012-03-19 20:22:20 +04:00
|
|
|
private final int NUMBER_OF_KNOWN_URLS = 200;
|
|
|
|
private final int BATCH_SIZE = 500;
|
|
|
|
|
2012-04-02 22:56:43 +04:00
|
|
|
// Include spaces in prefix to test performance querying with
|
|
|
|
// multiple constraint words
|
|
|
|
private final String KNOWN_PREFIX = "my mozilla test ";
|
2012-03-19 20:22:20 +04:00
|
|
|
|
|
|
|
private Method mFilterMethod;
|
|
|
|
private Random mGenerator;
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
private final String MOBILE_FOLDER_GUID = "mobile";
|
|
|
|
private long mMobileFolderId;
|
|
|
|
|
|
|
|
private Uri mBookmarksUri;
|
2012-03-19 20:22:20 +04:00
|
|
|
private Uri mHistoryUri;
|
2012-03-24 02:52:20 +04:00
|
|
|
|
|
|
|
private String mBookmarksIdCol;
|
|
|
|
private String mBookmarksTitleCol;
|
|
|
|
private String mBookmarksUrlCol;
|
|
|
|
private String mBookmarksParentCol;
|
|
|
|
private String mBookmarksTypeCol;
|
|
|
|
private String mBookmarksPositionCol;
|
|
|
|
private String mBookmarksTagsCol;
|
|
|
|
private String mBookmarksDescriptionCol;
|
|
|
|
private String mBookmarksKeywordCol;
|
|
|
|
private String mBookmarksGuidCol;
|
|
|
|
private int mBookmarksTypeBookmark;
|
|
|
|
|
2012-03-19 20:22:20 +04:00
|
|
|
private String mHistoryTitleCol;
|
|
|
|
private String mHistoryUrlCol;
|
|
|
|
private String mHistoryVisitsCol;
|
|
|
|
private String mHistoryFaviconCol;
|
|
|
|
private String mHistoryThumbnailCol;
|
|
|
|
private String mHistoryLastVisitedCol;
|
|
|
|
|
|
|
|
private void loadFilterMethod() throws Exception {
|
|
|
|
Class browserDBClass = mClassLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
|
|
|
|
|
|
|
mFilterMethod =
|
|
|
|
browserDBClass.getDeclaredMethod("filter", ContentResolver.class,
|
|
|
|
CharSequence.class, int.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadContractInfo() throws Exception {
|
2012-03-24 02:52:20 +04:00
|
|
|
mBookmarksUri = getContentUri("Bookmarks");
|
2012-03-19 20:22:20 +04:00
|
|
|
mHistoryUri = getContentUri("History");
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
mBookmarksIdCol = getStringColumn("Bookmarks", "_ID");
|
|
|
|
mBookmarksTitleCol = getStringColumn("Bookmarks", "TITLE");
|
|
|
|
mBookmarksUrlCol = getStringColumn("Bookmarks", "URL");
|
|
|
|
mBookmarksParentCol = getStringColumn("Bookmarks", "PARENT");
|
|
|
|
mBookmarksTypeCol = getStringColumn("Bookmarks", "TYPE");
|
|
|
|
mBookmarksPositionCol = getStringColumn("Bookmarks", "POSITION");
|
|
|
|
mBookmarksTagsCol = getStringColumn("Bookmarks", "TAGS");
|
|
|
|
mBookmarksDescriptionCol = getStringColumn("Bookmarks", "DESCRIPTION");
|
|
|
|
mBookmarksKeywordCol= getStringColumn("Bookmarks", "KEYWORD");
|
|
|
|
mBookmarksGuidCol= getStringColumn("Bookmarks", "GUID");
|
|
|
|
mBookmarksTypeBookmark = getIntColumn("Bookmarks", "TYPE_BOOKMARK");
|
|
|
|
|
2012-03-19 20:22:20 +04:00
|
|
|
mHistoryTitleCol = getStringColumn("History", "TITLE");
|
|
|
|
mHistoryUrlCol = getStringColumn("History", "URL");
|
|
|
|
mHistoryVisitsCol = getStringColumn("History", "VISITS");
|
|
|
|
mHistoryLastVisitedCol = getStringColumn("History", "DATE_LAST_VISITED");
|
|
|
|
mHistoryFaviconCol = getStringColumn("History", "FAVICON");
|
|
|
|
}
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
private void loadMobileFolderId() throws Exception {
|
|
|
|
Cursor c = mProvider.query(mBookmarksUri, null,
|
|
|
|
mBookmarksGuidCol + " = ?",
|
|
|
|
new String[] { MOBILE_FOLDER_GUID },
|
|
|
|
null);
|
|
|
|
c.moveToFirst();
|
|
|
|
mMobileFolderId = c.getLong(c.getColumnIndex(mBookmarksIdCol));
|
|
|
|
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ContentValues createBookmarkEntry(String title, String url, long parentId,
|
|
|
|
int type, int position, String tags, String description, String keyword) throws Exception {
|
|
|
|
ContentValues bookmark = new ContentValues();
|
|
|
|
|
|
|
|
bookmark.put(mBookmarksTitleCol, title);
|
|
|
|
bookmark.put(mBookmarksUrlCol, url);
|
|
|
|
bookmark.put(mBookmarksParentCol, parentId);
|
|
|
|
bookmark.put(mBookmarksTypeCol, type);
|
|
|
|
bookmark.put(mBookmarksPositionCol, position);
|
|
|
|
bookmark.put(mBookmarksTagsCol, tags);
|
|
|
|
bookmark.put(mBookmarksDescriptionCol, description);
|
|
|
|
bookmark.put(mBookmarksKeywordCol, keyword);
|
|
|
|
|
|
|
|
return bookmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ContentValues createBookmarkEntryWithUrl(String url) throws Exception {
|
|
|
|
return createBookmarkEntry(url, url, mMobileFolderId,
|
|
|
|
mBookmarksTypeBookmark, 0, "tags", "description", "keyword");
|
|
|
|
}
|
|
|
|
|
|
|
|
private ContentValues createRandomBookmarkEntry() throws Exception {
|
|
|
|
return createRandomBookmarkEntry("");
|
|
|
|
}
|
|
|
|
|
|
|
|
private ContentValues createRandomBookmarkEntry(String knownPrefix) throws Exception {
|
|
|
|
String randomStr = createRandomUrl(knownPrefix);
|
|
|
|
return createBookmarkEntryWithUrl(randomStr);
|
|
|
|
}
|
|
|
|
|
2012-03-19 20:22:20 +04:00
|
|
|
private ContentValues createHistoryEntry(String title, String url, int visits,
|
|
|
|
long lastVisited, byte[] favicon) throws Exception {
|
|
|
|
ContentValues historyEntry = new ContentValues();
|
|
|
|
|
|
|
|
historyEntry.put(mHistoryTitleCol, title);
|
|
|
|
historyEntry.put(mHistoryUrlCol, url);
|
|
|
|
historyEntry.put(mHistoryVisitsCol, visits);
|
|
|
|
historyEntry.put(mHistoryLastVisitedCol, lastVisited);
|
|
|
|
historyEntry.put(mHistoryFaviconCol, favicon);
|
|
|
|
|
|
|
|
return historyEntry;
|
|
|
|
}
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
private ContentValues createHistoryEntryWithUrl(String url) throws Exception {
|
|
|
|
int visits = mGenerator.nextInt(500);
|
|
|
|
return createHistoryEntry(url, url, visits,
|
|
|
|
System.currentTimeMillis(), url.getBytes("UTF8"));
|
|
|
|
}
|
|
|
|
|
2012-03-19 20:22:20 +04:00
|
|
|
private ContentValues createRandomHistoryEntry() throws Exception {
|
|
|
|
return createRandomHistoryEntry("");
|
|
|
|
}
|
|
|
|
|
|
|
|
private ContentValues createRandomHistoryEntry(String knownPrefix) throws Exception {
|
2012-03-24 02:52:20 +04:00
|
|
|
String randomStr = createRandomUrl(knownPrefix);
|
|
|
|
return createHistoryEntryWithUrl(randomStr);
|
|
|
|
}
|
2012-03-19 20:22:20 +04:00
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
private String createRandomUrl(String knownPrefix) throws Exception {
|
|
|
|
return knownPrefix + UUID.randomUUID().toString();
|
2012-03-19 20:22:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addTonsOfUrls() throws Exception {
|
2012-03-24 02:52:20 +04:00
|
|
|
// Create some random bookmark entries
|
|
|
|
ContentValues[] bookmarkEntries = new ContentValues[BATCH_SIZE];
|
2012-03-19 20:22:20 +04:00
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
for (int i = 0; i < NUMBER_OF_BASIC_BOOKMARK_URLS / BATCH_SIZE; i++) {
|
|
|
|
bookmarkEntries = new ContentValues[BATCH_SIZE];
|
2012-03-19 20:22:20 +04:00
|
|
|
|
|
|
|
for (int j = 0; j < BATCH_SIZE; j++) {
|
2012-03-24 02:52:20 +04:00
|
|
|
bookmarkEntries[j] = createRandomBookmarkEntry();
|
2012-03-19 20:22:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
mProvider.bulkInsert(mBookmarksUri, bookmarkEntries);
|
2012-03-19 20:22:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
// Create some random history entries
|
|
|
|
ContentValues[] historyEntries = new ContentValues[BATCH_SIZE];
|
|
|
|
|
|
|
|
for (int i = 0; i < NUMBER_OF_BASIC_HISTORY_URLS / BATCH_SIZE; i++) {
|
|
|
|
historyEntries = new ContentValues[BATCH_SIZE];
|
|
|
|
|
|
|
|
for (int j = 0; j < BATCH_SIZE; j++) {
|
|
|
|
historyEntries[j] = createRandomHistoryEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider.bulkInsert(mHistoryUri, historyEntries);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create random bookmark/history entries with the same url
|
|
|
|
for (int i = 0; i < NUMBER_OF_COMBINED_URLS / BATCH_SIZE; i++) {
|
|
|
|
bookmarkEntries = new ContentValues[BATCH_SIZE];
|
|
|
|
historyEntries = new ContentValues[BATCH_SIZE];
|
|
|
|
|
|
|
|
for (int j = 0; j < BATCH_SIZE; j++) {
|
|
|
|
String url = createRandomUrl("");
|
|
|
|
bookmarkEntries[j] = createBookmarkEntryWithUrl(url);
|
|
|
|
historyEntries[j] = createHistoryEntryWithUrl(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider.bulkInsert(mBookmarksUri, bookmarkEntries);
|
|
|
|
mProvider.bulkInsert(mHistoryUri, historyEntries);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create some history entries with a known prefix
|
|
|
|
historyEntries = new ContentValues[NUMBER_OF_KNOWN_URLS];
|
2012-03-19 20:22:20 +04:00
|
|
|
for (int i = 0; i < NUMBER_OF_KNOWN_URLS; i++) {
|
2012-03-24 02:52:20 +04:00
|
|
|
historyEntries[i] = createRandomHistoryEntry(KNOWN_PREFIX);
|
2012-03-19 20:22:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
mProvider.bulkInsert(mHistoryUri, historyEntries);
|
2012-03-19 20:22:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
super.setUp("@ANDROID_PACKAGE_NAME@.db.BrowserProvider", "AUTHORITY");
|
|
|
|
|
|
|
|
mGenerator = new Random(19580427);
|
|
|
|
|
|
|
|
loadContractInfo();
|
|
|
|
loadFilterMethod();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testBrowserProviderPerf() throws Exception {
|
|
|
|
setTestType("talos");
|
|
|
|
|
2012-03-24 02:52:20 +04:00
|
|
|
loadMobileFolderId();
|
2012-03-19 20:22:20 +04:00
|
|
|
addTonsOfUrls();
|
|
|
|
|
|
|
|
long start = SystemClock.uptimeMillis();
|
|
|
|
|
|
|
|
Cursor c = (Cursor) mFilterMethod.invoke(null, mResolver, KNOWN_PREFIX, 100);
|
|
|
|
c.getCount(); // ensure query is not lazy loaded
|
|
|
|
|
|
|
|
long end = SystemClock.uptimeMillis();
|
|
|
|
|
|
|
|
mAsserter.dumpLog("__start_report" + Long.toString(end - start) + "__end_report");
|
2012-04-05 19:11:25 +04:00
|
|
|
mAsserter.dumpLog("__startTimestamp" + Long.toString(end - start) + "__endTimestamp");
|
2012-03-24 02:52:20 +04:00
|
|
|
|
|
|
|
c.close();
|
2012-03-19 20:22:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
super.tearDown();
|
|
|
|
}
|
|
|
|
}
|