OLD | NEW |
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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.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" |
| 14 #include "base/test/perf_time_logger.h" |
13 #include "base/test/perftimer.h" | 15 #include "base/test/perftimer.h" |
14 #include "base/test/test_file_util.h" | 16 #include "base/test/test_file_util.h" |
15 #include "components/visitedlink/browser/visitedlink_master.h" | 17 #include "components/visitedlink/browser/visitedlink_master.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "url/gurl.h" | 19 #include "url/gurl.h" |
18 | 20 |
19 using base::TimeDelta; | 21 using base::TimeDelta; |
20 | 22 |
21 namespace visitedlink { | 23 namespace visitedlink { |
22 | 24 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // to query the database with different numbers of things in it. The time | 78 // to query the database with different numbers of things in it. The time |
77 // is the total time to do all the operations, and as such, it is only | 79 // is the total time to do all the operations, and as such, it is only |
78 // useful for a regression test. If there is a regression, it might be | 80 // useful for a regression test. If there is a regression, it might be |
79 // useful to make another set of tests to test these things in isolation. | 81 // useful to make another set of tests to test these things in isolation. |
80 TEST_F(VisitedLink, TestAddAndQuery) { | 82 TEST_F(VisitedLink, TestAddAndQuery) { |
81 // init | 83 // init |
82 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), | 84 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), |
83 NULL, true, true, db_path_, 0); | 85 NULL, true, true, db_path_, 0); |
84 ASSERT_TRUE(master.Init()); | 86 ASSERT_TRUE(master.Init()); |
85 | 87 |
86 PerfTimeLogger timer("Visited_link_add_and_query"); | 88 base::PerfTimeLogger timer("Visited_link_add_and_query"); |
87 | 89 |
88 // first check without anything in the table | 90 // first check without anything in the table |
89 CheckVisited(master, added_prefix, 0, add_count); | 91 CheckVisited(master, added_prefix, 0, add_count); |
90 | 92 |
91 // now fill half the table | 93 // now fill half the table |
92 const int half_size = add_count / 2; | 94 const int half_size = add_count / 2; |
93 FillTable(master, added_prefix, 0, half_size); | 95 FillTable(master, added_prefix, 0, half_size); |
94 | 96 |
95 // check the table again, half of these URLs will be visited, the other half | 97 // check the table again, half of these URLs will be visited, the other half |
96 // will not | 98 // will not |
97 CheckVisited(master, added_prefix, 0, add_count); | 99 CheckVisited(master, added_prefix, 0, add_count); |
98 | 100 |
99 // fill the rest of the table | 101 // fill the rest of the table |
100 FillTable(master, added_prefix, half_size, add_count); | 102 FillTable(master, added_prefix, half_size, add_count); |
101 | 103 |
102 // check URLs, doing half visited, half unvisited | 104 // check URLs, doing half visited, half unvisited |
103 CheckVisited(master, added_prefix, 0, add_count); | 105 CheckVisited(master, added_prefix, 0, add_count); |
104 CheckVisited(master, unadded_prefix, 0, add_count); | 106 CheckVisited(master, unadded_prefix, 0, add_count); |
105 } | 107 } |
106 | 108 |
107 // Tests how long it takes to write and read a large database to and from disk. | 109 // Tests how long it takes to write and read a large database to and from disk. |
108 TEST_F(VisitedLink, TestLoad) { | 110 TEST_F(VisitedLink, TestLoad) { |
109 // create a big DB | 111 // create a big DB |
110 { | 112 { |
111 PerfTimeLogger table_initialization_timer("Table_initialization"); | 113 base::PerfTimeLogger table_initialization_timer("Table_initialization"); |
112 | 114 |
113 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), | 115 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), |
114 NULL, true, true, db_path_, 0); | 116 NULL, true, true, db_path_, 0); |
115 | 117 |
116 // time init with empty table | 118 // time init with empty table |
117 PerfTimeLogger initTimer("Empty_visited_link_init"); | 119 base::PerfTimeLogger initTimer("Empty_visited_link_init"); |
118 bool success = master.Init(); | 120 bool success = master.Init(); |
119 initTimer.Done(); | 121 initTimer.Done(); |
120 ASSERT_TRUE(success); | 122 ASSERT_TRUE(success); |
121 | 123 |
122 // add a bunch of stuff | 124 // add a bunch of stuff |
123 // TODO(maruel): This is very inefficient because the file gets rewritten | 125 // TODO(maruel): This is very inefficient because the file gets rewritten |
124 // many time and this is the actual bottleneck of this test. The file should | 126 // many time and this is the actual bottleneck of this test. The file should |
125 // only get written that the end of the FillTable call, not 4169(!) times. | 127 // only get written that the end of the FillTable call, not 4169(!) times. |
126 FillTable(master, added_prefix, 0, load_test_add_count); | 128 FillTable(master, added_prefix, 0, load_test_add_count); |
127 | 129 |
128 // time writing the file out out | 130 // time writing the file out out |
129 PerfTimeLogger flushTimer("Visited_link_database_flush"); | 131 base::PerfTimeLogger flushTimer("Visited_link_database_flush"); |
130 master.RewriteFile(); | 132 master.RewriteFile(); |
131 // TODO(maruel): Without calling FlushFileBuffers(master.file_); you don't | 133 // TODO(maruel): Without calling FlushFileBuffers(master.file_); you don't |
132 // know really how much time it took to write the file. | 134 // know really how much time it took to write the file. |
133 flushTimer.Done(); | 135 flushTimer.Done(); |
134 | 136 |
135 table_initialization_timer.Done(); | 137 table_initialization_timer.Done(); |
136 } | 138 } |
137 | 139 |
138 // test loading the DB back, we do this several times since the flushing is | 140 // test loading the DB back, we do this several times since the flushing is |
139 // not very reliable. | 141 // not very reliable. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 cold_load_times.erase(std::max_element(cold_load_times.begin(), | 185 cold_load_times.erase(std::max_element(cold_load_times.begin(), |
184 cold_load_times.end())); | 186 cold_load_times.end())); |
185 hot_load_times.erase(std::max_element(hot_load_times.begin(), | 187 hot_load_times.erase(std::max_element(hot_load_times.begin(), |
186 hot_load_times.end())); | 188 hot_load_times.end())); |
187 | 189 |
188 double cold_sum = 0, hot_sum = 0; | 190 double cold_sum = 0, hot_sum = 0; |
189 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) { | 191 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) { |
190 cold_sum += cold_load_times[i]; | 192 cold_sum += cold_load_times[i]; |
191 hot_sum += hot_load_times[i]; | 193 hot_sum += hot_load_times[i]; |
192 } | 194 } |
193 LogPerfResult("Visited_link_cold_load_time", | 195 base::LogPerfResult( |
194 cold_sum / cold_load_times.size(), "ms"); | 196 "Visited_link_cold_load_time", cold_sum / cold_load_times.size(), "ms"); |
195 LogPerfResult("Visited_link_hot_load_time", | 197 base::LogPerfResult( |
196 hot_sum / hot_load_times.size(), "ms"); | 198 "Visited_link_hot_load_time", hot_sum / hot_load_times.size(), "ms"); |
197 } | 199 } |
198 | 200 |
199 } // namespace visitedlink | 201 } // namespace visitedlink |
OLD | NEW |