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

Side by Side Diff: components/visitedlink/test/visitedlink_perftest.cc

Issue 1417943002: Load the table of visited links from database file asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Load the table of visited links asynchronously and inform render about finish loading process. Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/memory/shared_memory.h" 11 #include "base/memory/shared_memory.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/test/perf_log.h" 13 #include "base/test/perf_log.h"
14 #include "base/test/perf_time_logger.h" 14 #include "base/test/perf_time_logger.h"
15 #include "base/test/test_file_util.h" 15 #include "base/test/test_file_util.h"
16 #include "base/timer/elapsed_timer.h" 16 #include "base/timer/elapsed_timer.h"
17 #include "components/visitedlink/browser/visitedlink_master.h" 17 #include "components/visitedlink/browser/visitedlink_master.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "content/public/test/test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 21 #include "url/gurl.h"
20 22
21 using base::TimeDelta; 23 using base::TimeDelta;
22 24
23 namespace visitedlink { 25 namespace visitedlink {
24 26
25 namespace { 27 namespace {
26 28
27 // how we generate URLs, note that the two strings should be the same length 29 // how we generate URLs, note that the two strings should be the same length
28 const int add_count = 10000; 30 const int add_count = 10000;
29 const int load_test_add_count = 250000; 31 const int load_test_add_count = 250000;
30 const char added_prefix[] = "http://www.google.com/stuff/something/foo?session=8 5025602345625&id=1345142319023&seq="; 32 const char added_prefix[] = "http://www.google.com/stuff/something/foo?session=8 5025602345625&id=1345142319023&seq=";
31 const char unadded_prefix[] = "http://www.google.org/stuff/something/foo?session =39586739476365&id=2347624314402&seq="; 33 const char unadded_prefix[] = "http://www.google.org/stuff/something/foo?session =39586739476365&id=2347624314402&seq=";
32 34
33 // Returns a URL with the given prefix and index 35 // Returns a URL with the given prefix and index
34 GURL TestURL(const char* prefix, int i) { 36 GURL TestURL(const char* prefix, int i) {
35 return GURL(base::StringPrintf("%s%d", prefix, i)); 37 return GURL(base::StringPrintf("%s%d", prefix, i));
36 } 38 }
37 39
38 // We have no slaves, so all methods on this listener are a no-ops. 40 // We have no slaves, so all methods on this listener are a no-ops.
39 class DummyVisitedLinkEventListener : public VisitedLinkMaster::Listener { 41 class DummyVisitedLinkEventListener : public VisitedLinkMaster::Listener {
40 public: 42 public:
41 DummyVisitedLinkEventListener() {} 43 DummyVisitedLinkEventListener() {}
42 void NewTable(base::SharedMemory* table) override {} 44 void NewTable(base::SharedMemory* table) override {}
43 void Add(VisitedLinkCommon::Fingerprint) override {} 45 void Add(VisitedLinkCommon::Fingerprint) override {}
44 void Reset() override {} 46 void Reset(bool invalidate_hashes) override {}
45 }; 47 };
46 48
47 49
48 // this checks IsVisited for the URLs starting with the given prefix and 50 // this checks IsVisited for the URLs starting with the given prefix and
49 // within the given range 51 // within the given range
50 void CheckVisited(VisitedLinkMaster& master, const char* prefix, 52 void CheckVisited(VisitedLinkMaster& master, const char* prefix,
51 int begin, int end) { 53 int begin, int end) {
52 for (int i = begin; i < end; i++) 54 for (int i = begin; i < end; i++)
53 master.IsVisited(TestURL(prefix, i)); 55 master.IsVisited(TestURL(prefix, i));
54 } 56 }
55 57
56 // Fills that master's table with URLs starting with the given prefix and 58 // Fills that master's table with URLs starting with the given prefix and
57 // within the given range 59 // within the given range
58 void FillTable(VisitedLinkMaster& master, const char* prefix, 60 void FillTable(VisitedLinkMaster& master, const char* prefix,
59 int begin, int end) { 61 int begin, int end) {
60 for (int i = begin; i < end; i++) 62 for (int i = begin; i < end; i++)
61 master.AddURL(TestURL(prefix, i)); 63 master.AddURL(TestURL(prefix, i));
62 } 64 }
63 65
64 class VisitedLink : public testing::Test { 66 class VisitedLink : public testing::Test {
65 protected: 67 protected:
66 base::FilePath db_path_; 68 base::FilePath db_path_;
67 void SetUp() override { ASSERT_TRUE(base::CreateTemporaryFile(&db_path_)); } 69 void SetUp() override { ASSERT_TRUE(base::CreateTemporaryFile(&db_path_)); }
68 void TearDown() override { base::DeleteFile(db_path_, false); } 70 void TearDown() override { base::DeleteFile(db_path_, false); }
71
72 private:
73 content::TestBrowserThreadBundle thread_bundle_;
69 }; 74 };
70 75
71 } // namespace 76 } // namespace
72 77
73 // This test tests adding many things to a database, and how long it takes 78 // This test tests adding many things to a database, and how long it takes
74 // to query the database with different numbers of things in it. The time 79 // to query the database with different numbers of things in it. The time
75 // is the total time to do all the operations, and as such, it is only 80 // is the total time to do all the operations, and as such, it is only
76 // useful for a regression test. If there is a regression, it might be 81 // useful for a regression test. If there is a regression, it might be
77 // useful to make another set of tests to test these things in isolation. 82 // useful to make another set of tests to test these things in isolation.
78 TEST_F(VisitedLink, TestAddAndQuery) { 83 TEST_F(VisitedLink, TestAddAndQuery) {
79 // init 84 // init
80 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), 85 VisitedLinkMaster master(new DummyVisitedLinkEventListener(),
81 NULL, true, true, db_path_, 0); 86 NULL, true, true, db_path_, 0);
82 ASSERT_TRUE(master.Init()); 87 ASSERT_TRUE(master.Init());
88 content::RunAllBlockingPoolTasksUntilIdle();
83 89
84 base::PerfTimeLogger timer("Visited_link_add_and_query"); 90 base::PerfTimeLogger timer("Visited_link_add_and_query");
85 91
86 // first check without anything in the table 92 // first check without anything in the table
87 CheckVisited(master, added_prefix, 0, add_count); 93 CheckVisited(master, added_prefix, 0, add_count);
88 94
89 // now fill half the table 95 // now fill half the table
90 const int half_size = add_count / 2; 96 const int half_size = add_count / 2;
91 FillTable(master, added_prefix, 0, half_size); 97 FillTable(master, added_prefix, 0, half_size);
92 98
(...skipping 14 matching lines...) Expand all
107 // create a big DB 113 // create a big DB
108 { 114 {
109 base::PerfTimeLogger table_initialization_timer("Table_initialization"); 115 base::PerfTimeLogger table_initialization_timer("Table_initialization");
110 116
111 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), 117 VisitedLinkMaster master(new DummyVisitedLinkEventListener(),
112 NULL, true, true, db_path_, 0); 118 NULL, true, true, db_path_, 0);
113 119
114 // time init with empty table 120 // time init with empty table
115 base::PerfTimeLogger initTimer("Empty_visited_link_init"); 121 base::PerfTimeLogger initTimer("Empty_visited_link_init");
116 bool success = master.Init(); 122 bool success = master.Init();
123 content::RunAllBlockingPoolTasksUntilIdle();
117 initTimer.Done(); 124 initTimer.Done();
118 ASSERT_TRUE(success); 125 ASSERT_TRUE(success);
119 126
120 // add a bunch of stuff 127 // add a bunch of stuff
121 // TODO(maruel): This is very inefficient because the file gets rewritten 128 // TODO(maruel): This is very inefficient because the file gets rewritten
122 // many time and this is the actual bottleneck of this test. The file should 129 // many time and this is the actual bottleneck of this test. The file should
123 // only get written that the end of the FillTable call, not 4169(!) times. 130 // only get written that the end of the FillTable call, not 4169(!) times.
124 FillTable(master, added_prefix, 0, load_test_add_count); 131 FillTable(master, added_prefix, 0, load_test_add_count);
125 132
126 // time writing the file out out 133 // time writing the file out out
(...skipping 19 matching lines...) Expand all
146 { 153 {
147 base::ElapsedTimer cold_timer; 154 base::ElapsedTimer cold_timer;
148 155
149 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), 156 VisitedLinkMaster master(new DummyVisitedLinkEventListener(),
150 NULL, 157 NULL,
151 true, 158 true,
152 true, 159 true,
153 db_path_, 160 db_path_,
154 0); 161 0);
155 bool success = master.Init(); 162 bool success = master.Init();
163 content::RunAllBlockingPoolTasksUntilIdle();
156 TimeDelta elapsed = cold_timer.Elapsed(); 164 TimeDelta elapsed = cold_timer.Elapsed();
157 ASSERT_TRUE(success); 165 ASSERT_TRUE(success);
158 166
159 cold_load_times.push_back(elapsed.InMillisecondsF()); 167 cold_load_times.push_back(elapsed.InMillisecondsF());
160 } 168 }
161 169
162 // hot load (with OS caching the file in memory) 170 // hot load (with OS caching the file in memory)
163 { 171 {
164 base::ElapsedTimer hot_timer; 172 base::ElapsedTimer hot_timer;
165 173
166 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), 174 VisitedLinkMaster master(new DummyVisitedLinkEventListener(),
167 NULL, 175 NULL,
168 true, 176 true,
169 true, 177 true,
170 db_path_, 178 db_path_,
171 0); 179 0);
172 bool success = master.Init(); 180 bool success = master.Init();
181 content::RunAllBlockingPoolTasksUntilIdle();
173 TimeDelta elapsed = hot_timer.Elapsed(); 182 TimeDelta elapsed = hot_timer.Elapsed();
174 ASSERT_TRUE(success); 183 ASSERT_TRUE(success);
175 184
176 hot_load_times.push_back(elapsed.InMillisecondsF()); 185 hot_load_times.push_back(elapsed.InMillisecondsF());
177 } 186 }
178 } 187 }
179 188
180 // We discard the max and return the average time. 189 // We discard the max and return the average time.
181 cold_load_times.erase(std::max_element(cold_load_times.begin(), 190 cold_load_times.erase(std::max_element(cold_load_times.begin(),
182 cold_load_times.end())); 191 cold_load_times.end()));
183 hot_load_times.erase(std::max_element(hot_load_times.begin(), 192 hot_load_times.erase(std::max_element(hot_load_times.begin(),
184 hot_load_times.end())); 193 hot_load_times.end()));
185 194
186 double cold_sum = 0, hot_sum = 0; 195 double cold_sum = 0, hot_sum = 0;
187 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) { 196 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) {
188 cold_sum += cold_load_times[i]; 197 cold_sum += cold_load_times[i];
189 hot_sum += hot_load_times[i]; 198 hot_sum += hot_load_times[i];
190 } 199 }
191 base::LogPerfResult( 200 base::LogPerfResult(
192 "Visited_link_cold_load_time", cold_sum / cold_load_times.size(), "ms"); 201 "Visited_link_cold_load_time", cold_sum / cold_load_times.size(), "ms");
193 base::LogPerfResult( 202 base::LogPerfResult(
194 "Visited_link_hot_load_time", hot_sum / hot_load_times.size(), "ms"); 203 "Visited_link_hot_load_time", hot_sum / hot_load_times.size(), "ms");
195 } 204 }
196 205
197 } // namespace visitedlink 206 } // namespace visitedlink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698