Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/test/live_sync/performance/sessions_sync_perf_test.cc

Issue 7575026: Session/tab sync performance tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment typos Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/stringprintf.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/sync/profile_sync_service_harness.h"
8 #include "chrome/test/live_sync/performance/sync_timing_helper.h"
9 #include "chrome/test/live_sync/live_sessions_sync_test.h"
10
11 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all
12 // datatypes into a performance test base class, once it is possible to do so.
13 static const int kNumTabs = 150;
14 static const int kNumBenchmarkPoints = 18;
15 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125,
16 150, 175, 200, 225, 250, 300, 350,
17 400, 500};
18
19 class SessionsSyncPerfTest: public TwoClientLiveSessionsSyncTest {
20 public:
21 SessionsSyncPerfTest() : url_number(0) {}
22
23 // Opens |num_tabs| new tabs on |profile|.
24 void AddTabs(int profile, int num_tabs);
25
26 // Update all tabs in |profile| by visiting a new URL.
27 void UpdateTabs(int profile);
28
29 // Close all tabs in |profile|.
30 void RemoveTabs(int profile);
31
32 // Returns the number of open tabs in all sessions (local + foreign) for
33 // |profile|. Returns -1 on failure.
34 int GetTabCount(int profile);
35
36 // Closes all tabs for all profiles. Called between benchmark iterations.
37 void Cleanup();
38
39 private:
40 // Returns a new unique URL.
41 GURL NextURL();
42
43 // Returns a unique URL according to the integer |n|.
44 GURL IntToURL(int n);
45
46 int url_number;
47 DISALLOW_COPY_AND_ASSIGN(SessionsSyncPerfTest);
48 };
49
50 void SessionsSyncPerfTest::AddTabs(int profile, int num_tabs) {
51 std::vector<GURL> urls;
52 for (int i = 0; i < num_tabs; ++i) {
53 urls.push_back(NextURL());
54 }
55 OpenMultipleTabs(profile, urls);
56 }
57
58 void SessionsSyncPerfTest::UpdateTabs(int profile) {
59 Browser* browser = GetBrowser(profile);
60 GURL url;
61 std::vector<GURL> urls;
62 for (int i = 0; i < browser->tab_count(); ++i) {
63 browser->SelectNumberedTab(i);
64 url = NextURL();
65 browser->OpenURL(
66 OpenURLParams(url, GURL("www.google.com"), CURRENT_TAB, 0));
67 urls.push_back(url);
68 }
69 AwaitSessionPropagation(profile, urls);
70 }
71
72 void SessionsSyncPerfTest::RemoveTabs(int profile) {
73 GetBrowser(profile)->CloseAllTabs();
74 }
75
76 int SessionsSyncPerfTest::GetTabCount(int profile) {
77 int tab_count = 0;
78 const SyncedSession* local_session;
79 std::vector<const SyncedSession*> sessions;
80
81 if (!GetLocalSession(profile, &local_session)) {
82 VLOG(1) << "GetLocalSession returned false";
83 return -1;
84 }
85
86 if (!GetSessionData(profile, &sessions)) {
87 // Foreign session data may be empty. In this case we only count tabs in
88 // the local session.
89 VLOG(1) << "GetSessionData returned false";
braffert 2011/08/04 23:47:34 Intentionally not returning -1 here. GetSessionDa
90 }
91
92 sessions.push_back(local_session);
93 for (std::vector<const SyncedSession*>::const_iterator it = sessions.begin();
94 it != sessions.end(); ++it) {
95 for (std::vector<SessionWindow*>::const_iterator win_it =
96 (*it)->windows.begin(); win_it != (*it)->windows.end(); ++win_it) {
97 tab_count += (*win_it)->tabs.size();
98 }
99 }
100 return tab_count;
101 }
102
103 void SessionsSyncPerfTest::Cleanup() {
104 for (int i = 0; i < num_clients(); ++i) {
105 RemoveTabs(i);
106 }
107 ASSERT_TRUE(AwaitQuiescence());
108 ASSERT_EQ(0, GetTabCount(0));
Nicolas Zea 2011/08/05 00:40:02 Doesn't this wind up being 1 (due to the NTP you m
braffert 2011/08/05 00:47:38 Yes, nice catch. This method is only called from
109 }
110
111 GURL SessionsSyncPerfTest::NextURL() {
112 return IntToURL(url_number++);
113 }
114
115 GURL SessionsSyncPerfTest::IntToURL(int n) {
116 return GURL(StringPrintf("http://history%d.google.com/", n));
117 }
118
119 IN_PROC_BROWSER_TEST_F(SessionsSyncPerfTest, P0) {
120 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
121
122 AddTabs(0, kNumTabs);
123 base::TimeDelta dt =
124 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
125 ASSERT_EQ(kNumTabs, GetTabCount(0));
126 ASSERT_EQ(kNumTabs, GetTabCount(1));
127 SyncTimingHelper::PrintResult("tabs", "add", dt);
128
129 UpdateTabs(0);
130 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
131 ASSERT_EQ(kNumTabs, GetTabCount(0));
132 ASSERT_EQ(kNumTabs, GetTabCount(1));
133 SyncTimingHelper::PrintResult("tabs", "update", dt);
134
135 RemoveTabs(0);
136 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
137 // New tab page opens after closing all tabs.
Nicolas Zea 2011/08/05 00:40:02 "New tab page remains on profile 0 after..."
braffert 2011/08/05 17:43:55 Done.
138 ASSERT_EQ(1, GetTabCount(0));
139 ASSERT_EQ(0, GetTabCount(1));
140 SyncTimingHelper::PrintResult("tabs", "delete", dt);
141 }
142
143 IN_PROC_BROWSER_TEST_F(SessionsSyncPerfTest, DISABLED_Benchmark) {
Nicolas Zea 2011/08/05 00:40:02 Why disabled?
braffert 2011/08/05 17:43:55 We have one of these tests for each datatype - the
144 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
145
146 for (int i = 0; i < kNumBenchmarkPoints; ++i) {
147 int num_tabs = kBenchmarkPoints[i];
148 AddTabs(0, num_tabs);
149 base::TimeDelta dt_add =
150 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
151 ASSERT_EQ(num_tabs, GetTabCount(0));
152 VLOG(0) << std::endl << "Add: " << num_tabs << " " << dt_add.InSecondsF();
153
154 UpdateTabs(0);
155 base::TimeDelta dt_update =
156 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
157 ASSERT_EQ(num_tabs, GetTabCount(0));
158 VLOG(0) << std::endl << "Update: " << num_tabs << " "
159 << dt_update.InSecondsF();
160
161 RemoveTabs(0);
162 base::TimeDelta dt_delete =
163 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
164 ASSERT_EQ(1, GetTabCount(0));
165 VLOG(0) << std::endl << "Delete: " << num_tabs << " "
166 << dt_delete.InSecondsF();
167
168 Cleanup();
169 }
170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698