| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const int add_count = 10000; | 23 const int add_count = 10000; |
| 24 const int load_test_add_count = 250000; | 24 const int load_test_add_count = 250000; |
| 25 const char added_prefix[] = "http://www.google.com/stuff/something/foo?session=8
5025602345625&id=1345142319023&seq="; | 25 const char added_prefix[] = "http://www.google.com/stuff/something/foo?session=8
5025602345625&id=1345142319023&seq="; |
| 26 const char unadded_prefix[] = "http://www.google.org/stuff/something/foo?session
=39586739476365&id=2347624314402&seq="; | 26 const char unadded_prefix[] = "http://www.google.org/stuff/something/foo?session
=39586739476365&id=2347624314402&seq="; |
| 27 | 27 |
| 28 // Returns a URL with the given prefix and index | 28 // Returns a URL with the given prefix and index |
| 29 GURL TestURL(const char* prefix, int i) { | 29 GURL TestURL(const char* prefix, int i) { |
| 30 return GURL(StringPrintf("%s%d", prefix, i)); | 30 return GURL(StringPrintf("%s%d", prefix, i)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // we have no slaves, so this broadcase is a NOP | 33 // We have no slaves, so all methods on this listener are a no-ops. |
| 34 VisitedLinkMaster::PostNewTableEvent DummyBroadcastNewTableEvent; | 34 class DummyVisitedLinkEventListener : public VisitedLinkMaster::Listener { |
| 35 void DummyBroadcastNewTableEvent(base::SharedMemory *table) { | 35 public: |
| 36 } | 36 DummyVisitedLinkEventListener() {} |
| 37 virtual void NewTable(base::SharedMemory* table) {} |
| 38 virtual void Add(VisitedLinkCommon::Fingerprint) {} |
| 39 virtual void Reset() {} |
| 40 |
| 41 static DummyVisitedLinkEventListener* GetInstance() { |
| 42 static DummyVisitedLinkEventListener instance; |
| 43 return &instance; |
| 44 } |
| 45 }; |
| 46 |
| 37 | 47 |
| 38 // Call at the beginning of the test to retrieve the database name. | 48 // Call at the beginning of the test to retrieve the database name. |
| 39 void InitDBName(std::wstring* db_name) { | 49 void InitDBName(std::wstring* db_name) { |
| 40 FilePath db_path; | 50 FilePath db_path; |
| 41 ASSERT_TRUE(file_util::GetCurrentDirectory(&db_path)); | 51 ASSERT_TRUE(file_util::GetCurrentDirectory(&db_path)); |
| 42 db_path = db_path.AppendASCII("TempVisitedLinks"); | 52 db_path = db_path.AppendASCII("TempVisitedLinks"); |
| 43 *db_name = db_path.ToWStringHack(); | 53 *db_name = db_path.ToWStringHack(); |
| 44 } | 54 } |
| 45 | 55 |
| 46 // this checks IsVisited for the URLs starting with the given prefix and | 56 // this checks IsVisited for the URLs starting with the given prefix and |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 | 83 |
| 74 } // namespace | 84 } // namespace |
| 75 | 85 |
| 76 // This test tests adding many things to a database, and how long it takes | 86 // This test tests adding many things to a database, and how long it takes |
| 77 // to query the database with different numbers of things in it. The time | 87 // to query the database with different numbers of things in it. The time |
| 78 // is the total time to do all the operations, and as such, it is only | 88 // is the total time to do all the operations, and as such, it is only |
| 79 // useful for a regression test. If there is a regression, it might be | 89 // useful for a regression test. If there is a regression, it might be |
| 80 // useful to make another set of tests to test these things in isolation. | 90 // useful to make another set of tests to test these things in isolation. |
| 81 TEST_F(VisitedLink, TestAddAndQuery) { | 91 TEST_F(VisitedLink, TestAddAndQuery) { |
| 82 // init | 92 // init |
| 83 VisitedLinkMaster master(NULL, DummyBroadcastNewTableEvent, NULL, true, | 93 VisitedLinkMaster master(NULL, DummyVisitedLinkEventListener::GetInstance(), |
| 84 FilePath(db_name_), 0); | 94 NULL, true, FilePath(db_name_), 0); |
| 85 ASSERT_TRUE(master.Init()); | 95 ASSERT_TRUE(master.Init()); |
| 86 | 96 |
| 87 PerfTimeLogger timer("Visited_link_add_and_query"); | 97 PerfTimeLogger timer("Visited_link_add_and_query"); |
| 88 | 98 |
| 89 // first check without anything in the table | 99 // first check without anything in the table |
| 90 CheckVisited(master, added_prefix, 0, add_count); | 100 CheckVisited(master, added_prefix, 0, add_count); |
| 91 | 101 |
| 92 // now fill half the table | 102 // now fill half the table |
| 93 const int half_size = add_count / 2; | 103 const int half_size = add_count / 2; |
| 94 FillTable(master, added_prefix, 0, half_size); | 104 FillTable(master, added_prefix, 0, half_size); |
| 95 | 105 |
| 96 // check the table again, half of these URLs will be visited, the other half | 106 // check the table again, half of these URLs will be visited, the other half |
| 97 // will not | 107 // will not |
| 98 CheckVisited(master, added_prefix, 0, add_count); | 108 CheckVisited(master, added_prefix, 0, add_count); |
| 99 | 109 |
| 100 // fill the rest of the table | 110 // fill the rest of the table |
| 101 FillTable(master, added_prefix, half_size, add_count); | 111 FillTable(master, added_prefix, half_size, add_count); |
| 102 | 112 |
| 103 // check URLs, doing half visited, half unvisited | 113 // check URLs, doing half visited, half unvisited |
| 104 CheckVisited(master, added_prefix, 0, add_count); | 114 CheckVisited(master, added_prefix, 0, add_count); |
| 105 CheckVisited(master, unadded_prefix, 0, add_count); | 115 CheckVisited(master, unadded_prefix, 0, add_count); |
| 106 } | 116 } |
| 107 | 117 |
| 108 // Tests how long it takes to write and read a large database to and from disk. | 118 // Tests how long it takes to write and read a large database to and from disk. |
| 109 TEST_F(VisitedLink, TestLoad) { | 119 TEST_F(VisitedLink, TestLoad) { |
| 110 // create a big DB | 120 // create a big DB |
| 111 { | 121 { |
| 112 PerfTimeLogger table_initialization_timer("Table_initialization"); | 122 PerfTimeLogger table_initialization_timer("Table_initialization"); |
| 113 | 123 |
| 114 VisitedLinkMaster master(NULL, DummyBroadcastNewTableEvent, NULL, true, | 124 VisitedLinkMaster master(NULL, DummyVisitedLinkEventListener::GetInstance(), |
| 115 FilePath(db_name_), 0); | 125 NULL, true, FilePath(db_name_), 0); |
| 116 | 126 |
| 117 // time init with empty table | 127 // time init with empty table |
| 118 PerfTimeLogger initTimer("Empty_visited_link_init"); | 128 PerfTimeLogger initTimer("Empty_visited_link_init"); |
| 119 bool success = master.Init(); | 129 bool success = master.Init(); |
| 120 initTimer.Done(); | 130 initTimer.Done(); |
| 121 ASSERT_TRUE(success); | 131 ASSERT_TRUE(success); |
| 122 | 132 |
| 123 // add a bunch of stuff | 133 // add a bunch of stuff |
| 124 // TODO(maruel): This is very inefficient because the file gets rewritten | 134 // TODO(maruel): This is very inefficient because the file gets rewritten |
| 125 // many time and this is the actual bottleneck of this test. The file should | 135 // many time and this is the actual bottleneck of this test. The file should |
| (...skipping 18 matching lines...) Expand all Loading... |
| 144 for (int i = 0; i < load_count; i++) | 154 for (int i = 0; i < load_count; i++) |
| 145 { | 155 { |
| 146 // make sure the file has to be re-loaded | 156 // make sure the file has to be re-loaded |
| 147 file_util::EvictFileFromSystemCache( | 157 file_util::EvictFileFromSystemCache( |
| 148 FilePath::FromWStringHack(std::wstring(db_name_))); | 158 FilePath::FromWStringHack(std::wstring(db_name_))); |
| 149 | 159 |
| 150 // cold load (no OS cache, hopefully) | 160 // cold load (no OS cache, hopefully) |
| 151 { | 161 { |
| 152 PerfTimer cold_timer; | 162 PerfTimer cold_timer; |
| 153 | 163 |
| 154 VisitedLinkMaster master(NULL, DummyBroadcastNewTableEvent, NULL, true, | 164 VisitedLinkMaster master(NULL, |
| 155 FilePath(db_name_), 0); | 165 DummyVisitedLinkEventListener::GetInstance(), |
| 166 NULL, |
| 167 true, |
| 168 FilePath(db_name_), |
| 169 0); |
| 156 bool success = master.Init(); | 170 bool success = master.Init(); |
| 157 TimeDelta elapsed = cold_timer.Elapsed(); | 171 TimeDelta elapsed = cold_timer.Elapsed(); |
| 158 ASSERT_TRUE(success); | 172 ASSERT_TRUE(success); |
| 159 | 173 |
| 160 cold_load_times.push_back(elapsed.InMillisecondsF()); | 174 cold_load_times.push_back(elapsed.InMillisecondsF()); |
| 161 } | 175 } |
| 162 | 176 |
| 163 // hot load (with OS caching the file in memory) | 177 // hot load (with OS caching the file in memory) |
| 164 { | 178 { |
| 165 PerfTimer hot_timer; | 179 PerfTimer hot_timer; |
| 166 | 180 |
| 167 VisitedLinkMaster master(NULL, DummyBroadcastNewTableEvent, NULL, true, | 181 VisitedLinkMaster master(NULL, |
| 168 FilePath(db_name_), 0); | 182 DummyVisitedLinkEventListener::GetInstance(), |
| 183 NULL, |
| 184 true, |
| 185 FilePath(db_name_), |
| 186 0); |
| 169 bool success = master.Init(); | 187 bool success = master.Init(); |
| 170 TimeDelta elapsed = hot_timer.Elapsed(); | 188 TimeDelta elapsed = hot_timer.Elapsed(); |
| 171 ASSERT_TRUE(success); | 189 ASSERT_TRUE(success); |
| 172 | 190 |
| 173 hot_load_times.push_back(elapsed.InMillisecondsF()); | 191 hot_load_times.push_back(elapsed.InMillisecondsF()); |
| 174 } | 192 } |
| 175 } | 193 } |
| 176 | 194 |
| 177 // We discard the max and return the average time. | 195 // We discard the max and return the average time. |
| 178 cold_load_times.erase(std::max_element(cold_load_times.begin(), | 196 cold_load_times.erase(std::max_element(cold_load_times.begin(), |
| 179 cold_load_times.end())); | 197 cold_load_times.end())); |
| 180 hot_load_times.erase(std::max_element(hot_load_times.begin(), | 198 hot_load_times.erase(std::max_element(hot_load_times.begin(), |
| 181 hot_load_times.end())); | 199 hot_load_times.end())); |
| 182 | 200 |
| 183 double cold_sum = 0, hot_sum = 0; | 201 double cold_sum = 0, hot_sum = 0; |
| 184 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) { | 202 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) { |
| 185 cold_sum += cold_load_times[i]; | 203 cold_sum += cold_load_times[i]; |
| 186 hot_sum += hot_load_times[i]; | 204 hot_sum += hot_load_times[i]; |
| 187 } | 205 } |
| 188 LogPerfResult("Visited_link_cold_load_time", | 206 LogPerfResult("Visited_link_cold_load_time", |
| 189 cold_sum / cold_load_times.size(), "ms"); | 207 cold_sum / cold_load_times.size(), "ms"); |
| 190 LogPerfResult("Visited_link_hot_load_time", | 208 LogPerfResult("Visited_link_hot_load_time", |
| 191 hot_sum / hot_load_times.size(), "ms"); | 209 hot_sum / hot_load_times.size(), "ms"); |
| 192 } | 210 } |
| OLD | NEW |