OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
6 #include "chrome/test/live_sync/bookmarks_helper.h" | 6 #include "chrome/test/live_sync/bookmarks_helper.h" |
7 #include "chrome/test/live_sync/live_sync_test.h" | 7 #include "chrome/test/live_sync/live_sync_test.h" |
8 #include "chrome/test/live_sync/performance/sync_timing_helper.h" | 8 #include "chrome/test/live_sync/performance/sync_timing_helper.h" |
9 | 9 |
10 using bookmarks_helper::AddURL; | 10 using bookmarks_helper::AddURL; |
11 using bookmarks_helper::AllModelsMatch; | 11 using bookmarks_helper::AllModelsMatch; |
12 using bookmarks_helper::GetBookmarkBarNode; | 12 using bookmarks_helper::GetBookmarkBarNode; |
13 using bookmarks_helper::IndexedURL; | 13 using bookmarks_helper::IndexedURL; |
14 using bookmarks_helper::IndexedURLTitle; | 14 using bookmarks_helper::IndexedURLTitle; |
15 using bookmarks_helper::Remove; | 15 using bookmarks_helper::Remove; |
16 using bookmarks_helper::SetURL; | 16 using bookmarks_helper::SetURL; |
17 | 17 |
18 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all | |
19 // datatypes into a performance test base class, once it is possible to do so. | |
20 static const int kNumBookmarks = 150; | 18 static const int kNumBookmarks = 150; |
21 static const int kNumBenchmarkPoints = 18; | |
22 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, | |
23 150, 175, 200, 225, 250, 300, 350, 400, | |
24 500}; | |
25 | 19 |
26 class BookmarksSyncPerfTest : public LiveSyncTest { | 20 class BookmarksSyncPerfTest : public LiveSyncTest { |
27 public: | 21 public: |
28 BookmarksSyncPerfTest() | 22 BookmarksSyncPerfTest() |
29 : LiveSyncTest(TWO_CLIENT), | 23 : LiveSyncTest(TWO_CLIENT), |
30 url_number_(0), | 24 url_number_(0), |
31 url_title_number_(0) {} | 25 url_title_number_(0) {} |
32 | 26 |
33 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|. | 27 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|. |
34 void AddURLs(int profile, int num_urls); | 28 void AddURLs(int profile, int num_urls); |
35 | 29 |
36 // Updates the URL for all bookmarks in the bookmark bar for |profile|. | 30 // Updates the URL for all bookmarks in the bookmark bar for |profile|. |
37 void UpdateURLs(int profile); | 31 void UpdateURLs(int profile); |
38 | 32 |
39 // Removes all bookmarks in the bookmark bar for |profile|. | 33 // Removes all bookmarks in the bookmark bar for |profile|. |
40 void RemoveURLs(int profile); | 34 void RemoveURLs(int profile); |
41 | 35 |
42 // Returns the number of bookmarks stored in the bookmark bar for |profile|. | 36 // Returns the number of bookmarks stored in the bookmark bar for |profile|. |
43 int GetURLCount(int profile); | 37 int GetURLCount(int profile); |
44 | 38 |
45 // Remvoes all bookmarks in the bookmark bars for all profiles. Called | |
46 // between benchmark iterations. | |
47 void Cleanup(); | |
48 | |
49 private: | 39 private: |
50 // Returns a new unique bookmark URL. | 40 // Returns a new unique bookmark URL. |
51 std::string NextIndexedURL(); | 41 std::string NextIndexedURL(); |
52 | 42 |
53 // Returns a new unique bookmark title. | 43 // Returns a new unique bookmark title. |
54 std::wstring NextIndexedURLTitle(); | 44 std::wstring NextIndexedURLTitle(); |
55 | 45 |
56 int url_number_; | 46 int url_number_; |
57 int url_title_number_; | 47 int url_title_number_; |
58 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest); | 48 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest); |
(...skipping 19 matching lines...) Expand all Loading... |
78 void BookmarksSyncPerfTest::RemoveURLs(int profile) { | 68 void BookmarksSyncPerfTest::RemoveURLs(int profile) { |
79 while (!GetBookmarkBarNode(profile)->empty()) { | 69 while (!GetBookmarkBarNode(profile)->empty()) { |
80 Remove(profile, GetBookmarkBarNode(profile), 0); | 70 Remove(profile, GetBookmarkBarNode(profile), 0); |
81 } | 71 } |
82 } | 72 } |
83 | 73 |
84 int BookmarksSyncPerfTest::GetURLCount(int profile) { | 74 int BookmarksSyncPerfTest::GetURLCount(int profile) { |
85 return GetBookmarkBarNode(profile)->child_count(); | 75 return GetBookmarkBarNode(profile)->child_count(); |
86 } | 76 } |
87 | 77 |
88 void BookmarksSyncPerfTest::Cleanup() { | |
89 for (int i = 0; i < num_clients(); ++i) { | |
90 RemoveURLs(i); | |
91 } | |
92 ASSERT_TRUE(AwaitQuiescence()); | |
93 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
94 ASSERT_TRUE(AllModelsMatch()); | |
95 } | |
96 | |
97 std::string BookmarksSyncPerfTest::NextIndexedURL() { | 78 std::string BookmarksSyncPerfTest::NextIndexedURL() { |
98 return IndexedURL(url_number_++); | 79 return IndexedURL(url_number_++); |
99 } | 80 } |
100 | 81 |
101 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() { | 82 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() { |
102 return IndexedURLTitle(url_title_number_++); | 83 return IndexedURLTitle(url_title_number_++); |
103 } | 84 } |
104 | 85 |
105 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, P0) { | 86 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, P0) { |
106 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 87 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
(...skipping 10 matching lines...) Expand all Loading... |
117 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 98 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
118 ASSERT_EQ(kNumBookmarks, GetURLCount(1)); | 99 ASSERT_EQ(kNumBookmarks, GetURLCount(1)); |
119 SyncTimingHelper::PrintResult("bookmarks", "update_bookmarks", dt); | 100 SyncTimingHelper::PrintResult("bookmarks", "update_bookmarks", dt); |
120 | 101 |
121 // TCM ID - 7566626. | 102 // TCM ID - 7566626. |
122 RemoveURLs(0); | 103 RemoveURLs(0); |
123 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 104 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
124 ASSERT_EQ(0, GetURLCount(1)); | 105 ASSERT_EQ(0, GetURLCount(1)); |
125 SyncTimingHelper::PrintResult("bookmarks", "delete_bookmarks", dt); | 106 SyncTimingHelper::PrintResult("bookmarks", "delete_bookmarks", dt); |
126 } | 107 } |
127 | |
128 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, DISABLED_Benchmark) { | |
129 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
130 DisableVerifier(); | |
131 | |
132 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | |
133 int num_bookmarks = kBenchmarkPoints[i]; | |
134 AddURLs(0, num_bookmarks); | |
135 base::TimeDelta dt_add = | |
136 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
137 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | |
138 ASSERT_TRUE(AllModelsMatch()); | |
139 VLOG(0) << std::endl << "Add: " << num_bookmarks << " " | |
140 << dt_add.InSecondsF(); | |
141 | |
142 UpdateURLs(0); | |
143 base::TimeDelta dt_update = | |
144 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
145 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | |
146 ASSERT_TRUE(AllModelsMatch()); | |
147 VLOG(0) << std::endl << "Update: " << num_bookmarks << " " | |
148 << dt_update.InSecondsF(); | |
149 | |
150 RemoveURLs(0); | |
151 base::TimeDelta dt_delete = | |
152 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
153 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
154 ASSERT_TRUE(AllModelsMatch()); | |
155 VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " | |
156 << dt_delete.InSecondsF(); | |
157 | |
158 Cleanup(); | |
159 } | |
160 } | |
OLD | NEW |