Index: chrome/test/live_sync/performance/sessions_sync_perf_test.cc |
diff --git a/chrome/test/live_sync/performance/sessions_sync_perf_test.cc b/chrome/test/live_sync/performance/sessions_sync_perf_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..915278b20cdbd8d312c57d3ce1ddfdc107ae5cb0 |
--- /dev/null |
+++ b/chrome/test/live_sync/performance/sessions_sync_perf_test.cc |
@@ -0,0 +1,170 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/stringprintf.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/sync/profile_sync_service_harness.h" |
+#include "chrome/test/live_sync/performance/sync_timing_helper.h" |
+#include "chrome/test/live_sync/live_sessions_sync_test.h" |
+ |
+// TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all |
+// datatypes into a performance test base class, once it is possible to do so. |
+static const int kNumTabs = 150; |
+static const int kNumBenchmarkPoints = 18; |
+static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, |
+ 150, 175, 200, 225, 250, 300, 350, |
+ 400, 500}; |
+ |
+class SessionsSyncPerfTest: public TwoClientLiveSessionsSyncTest { |
+ public: |
+ SessionsSyncPerfTest() : url_number(0) {} |
+ |
+ // Opens |num_tabs| new tabs on |profile|. |
+ void AddTabs(int profile, int num_tabs); |
+ |
+ // Update all tabs in |profile| by visiting a new URL. |
+ void UpdateTabs(int profile); |
+ |
+ // Close all tabs in |profile|. |
+ void RemoveTabs(int profile); |
+ |
+ // Returns the number of open tabs in all sessions (local + foreign) for |
+ // |profile|. Returns -1 on failure. |
+ int GetTabCount(int profile); |
+ |
+ // Closes all tabs for all profiles. Called between benchmark iterations. |
+ void Cleanup(); |
+ |
+ private: |
+ // Returns a new unique URL. |
+ GURL NextURL(); |
+ |
+ // Returns a unique URL according to the integer |n|. |
+ GURL IntToURL(int n); |
+ |
+ int url_number; |
+ DISALLOW_COPY_AND_ASSIGN(SessionsSyncPerfTest); |
+}; |
+ |
+void SessionsSyncPerfTest::AddTabs(int profile, int num_tabs) { |
+ std::vector<GURL> urls; |
+ for (int i = 0; i < num_tabs; ++i) { |
+ urls.push_back(NextURL()); |
+ } |
+ OpenMultipleTabs(profile, urls); |
+} |
+ |
+void SessionsSyncPerfTest::UpdateTabs(int profile) { |
+ Browser* browser = GetBrowser(profile); |
+ GURL url; |
+ std::vector<GURL> urls; |
+ for (int i = 0; i < browser->tab_count(); ++i) { |
+ browser->SelectNumberedTab(i); |
+ url = NextURL(); |
+ browser->OpenURL( |
+ OpenURLParams(url, GURL("www.google.com"), CURRENT_TAB, 0)); |
+ urls.push_back(url); |
+ } |
+ AwaitSessionPropagation(profile, urls); |
+} |
+ |
+void SessionsSyncPerfTest::RemoveTabs(int profile) { |
+ GetBrowser(profile)->CloseAllTabs(); |
+} |
+ |
+int SessionsSyncPerfTest::GetTabCount(int profile) { |
+ int tab_count = 0; |
+ const SyncedSession* local_session; |
+ std::vector<const SyncedSession*> sessions; |
+ |
+ if (!GetLocalSession(profile, &local_session)) { |
+ VLOG(1) << "GetLocalSession returned false"; |
+ return -1; |
+ } |
+ |
+ if (!GetSessionData(profile, &sessions)) { |
+ // Foreign session data may be empty. In this case we only count tabs in |
+ // the local session. |
+ VLOG(1) << "GetSessionData returned false"; |
braffert
2011/08/04 23:47:34
Intentionally not returning -1 here. GetSessionDa
|
+ } |
+ |
+ sessions.push_back(local_session); |
+ for (std::vector<const SyncedSession*>::const_iterator it = sessions.begin(); |
+ it != sessions.end(); ++it) { |
+ for (std::vector<SessionWindow*>::const_iterator win_it = |
+ (*it)->windows.begin(); win_it != (*it)->windows.end(); ++win_it) { |
+ tab_count += (*win_it)->tabs.size(); |
+ } |
+ } |
+ return tab_count; |
+} |
+ |
+void SessionsSyncPerfTest::Cleanup() { |
+ for (int i = 0; i < num_clients(); ++i) { |
+ RemoveTabs(i); |
+ } |
+ ASSERT_TRUE(AwaitQuiescence()); |
+ 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
|
+} |
+ |
+GURL SessionsSyncPerfTest::NextURL() { |
+ return IntToURL(url_number++); |
+} |
+ |
+GURL SessionsSyncPerfTest::IntToURL(int n) { |
+ return GURL(StringPrintf("http://history%d.google.com/", n)); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(SessionsSyncPerfTest, P0) { |
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ |
+ AddTabs(0, kNumTabs); |
+ base::TimeDelta dt = |
+ SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
+ ASSERT_EQ(kNumTabs, GetTabCount(0)); |
+ ASSERT_EQ(kNumTabs, GetTabCount(1)); |
+ SyncTimingHelper::PrintResult("tabs", "add", dt); |
+ |
+ UpdateTabs(0); |
+ dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
+ ASSERT_EQ(kNumTabs, GetTabCount(0)); |
+ ASSERT_EQ(kNumTabs, GetTabCount(1)); |
+ SyncTimingHelper::PrintResult("tabs", "update", dt); |
+ |
+ RemoveTabs(0); |
+ dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
+ // 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.
|
+ ASSERT_EQ(1, GetTabCount(0)); |
+ ASSERT_EQ(0, GetTabCount(1)); |
+ SyncTimingHelper::PrintResult("tabs", "delete", dt); |
+} |
+ |
+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
|
+ ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
+ |
+ for (int i = 0; i < kNumBenchmarkPoints; ++i) { |
+ int num_tabs = kBenchmarkPoints[i]; |
+ AddTabs(0, num_tabs); |
+ base::TimeDelta dt_add = |
+ SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
+ ASSERT_EQ(num_tabs, GetTabCount(0)); |
+ VLOG(0) << std::endl << "Add: " << num_tabs << " " << dt_add.InSecondsF(); |
+ |
+ UpdateTabs(0); |
+ base::TimeDelta dt_update = |
+ SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
+ ASSERT_EQ(num_tabs, GetTabCount(0)); |
+ VLOG(0) << std::endl << "Update: " << num_tabs << " " |
+ << dt_update.InSecondsF(); |
+ |
+ RemoveTabs(0); |
+ base::TimeDelta dt_delete = |
+ SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
+ ASSERT_EQ(1, GetTabCount(0)); |
+ VLOG(0) << std::endl << "Delete: " << num_tabs << " " |
+ << dt_delete.InSecondsF(); |
+ |
+ Cleanup(); |
+ } |
+} |