OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <limits> | 5 #include <limits> |
| 6 #include <memory> |
6 #include <string> | 7 #include <string> |
7 | 8 |
8 #include "base/bind.h" | 9 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
10 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/hash.h" | 13 #include "base/hash.h" |
13 #include "base/process/process_metrics.h" | 14 #include "base/process/process_metrics.h" |
14 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/test/perf_time_logger.h" | 18 #include "base/test/perf_time_logger.h" |
18 #include "base/test/scoped_task_environment.h" | 19 #include "base/test/scoped_task_environment.h" |
19 #include "base/test/test_file_util.h" | 20 #include "base/test/test_file_util.h" |
20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "build/build_config.h" |
21 #include "net/base/cache_type.h" | 23 #include "net/base/cache_type.h" |
22 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
23 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
24 #include "net/base/test_completion_callback.h" | 26 #include "net/base/test_completion_callback.h" |
25 #include "net/disk_cache/backend_cleanup_tracker.h" | 27 #include "net/disk_cache/backend_cleanup_tracker.h" |
26 #include "net/disk_cache/blockfile/backend_impl.h" | 28 #include "net/disk_cache/blockfile/backend_impl.h" |
27 #include "net/disk_cache/blockfile/block_files.h" | 29 #include "net/disk_cache/blockfile/block_files.h" |
28 #include "net/disk_cache/disk_cache.h" | 30 #include "net/disk_cache/disk_cache.h" |
29 #include "net/disk_cache/disk_cache_test_base.h" | 31 #include "net/disk_cache/disk_cache_test_base.h" |
30 #include "net/disk_cache/disk_cache_test_util.h" | 32 #include "net/disk_cache/disk_cache_test_util.h" |
31 #include "net/disk_cache/simple/simple_backend_impl.h" | 33 #include "net/disk_cache/simple/simple_backend_impl.h" |
32 #include "net/disk_cache/simple/simple_index.h" | 34 #include "net/disk_cache/simple/simple_index.h" |
33 #include "net/disk_cache/simple/simple_index_file.h" | 35 #include "net/disk_cache/simple/simple_index_file.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "testing/platform_test.h" | 37 #include "testing/platform_test.h" |
36 | 38 |
37 using base::Time; | 39 using base::Time; |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
| 43 const size_t kNumEntries = 1000; |
| 44 const int kHeadersSize = 800; |
| 45 |
| 46 const int kBodySize = 256 * 1024 - 1; |
| 47 |
| 48 // As of 2017-01-12, this is the typical IPC size used for |
| 49 const int kChunkSize = 64 * 1024; |
| 50 |
| 51 // As of 2017-01-12, this is a typical per-tab limit on HTTP connections. |
| 52 const int kMaxParallelOperations = 10; |
| 53 |
41 size_t MaybeGetMaxFds() { | 54 size_t MaybeGetMaxFds() { |
42 #if defined(OS_POSIX) | 55 #if defined(OS_POSIX) |
43 return base::GetMaxFds(); | 56 return base::GetMaxFds(); |
44 #else | 57 #else |
45 return std::numeric_limits<size_t>::max(); | 58 return std::numeric_limits<size_t>::max(); |
46 #endif | 59 #endif |
47 } | 60 } |
48 | 61 |
49 void MaybeSetFdLimit(unsigned int max_descriptors) { | 62 void MaybeSetFdLimit(unsigned int max_descriptors) { |
50 #if defined(OS_POSIX) | 63 #if defined(OS_POSIX) |
51 base::SetFdLimit(max_descriptors); | 64 base::SetFdLimit(max_descriptors); |
52 #endif | 65 #endif |
53 } | 66 } |
54 | 67 |
55 struct TestEntry { | 68 struct TestEntry { |
56 std::string key; | 69 std::string key; |
57 int data_len; | 70 int data_len; |
58 }; | 71 }; |
59 | 72 |
| 73 enum class WhatToRead { |
| 74 HEADERS_ONLY, |
| 75 HEADERS_AND_BODY, |
| 76 }; |
| 77 |
60 class DiskCachePerfTest : public DiskCacheTestWithCache { | 78 class DiskCachePerfTest : public DiskCacheTestWithCache { |
61 public: | 79 public: |
62 DiskCachePerfTest() : saved_fd_limit_(MaybeGetMaxFds()) { | 80 DiskCachePerfTest() { |
63 if (saved_fd_limit_ < kFdLimitForCacheTests) | 81 if (saved_fd_limit_ < kFdLimitForCacheTests) |
64 MaybeSetFdLimit(kFdLimitForCacheTests); | 82 MaybeSetFdLimit(kFdLimitForCacheTests); |
65 } | 83 } |
66 | 84 |
67 ~DiskCachePerfTest() override { | 85 ~DiskCachePerfTest() override { |
68 if (saved_fd_limit_ < kFdLimitForCacheTests) | 86 if (saved_fd_limit_ < kFdLimitForCacheTests) |
69 MaybeSetFdLimit(saved_fd_limit_); | 87 MaybeSetFdLimit(saved_fd_limit_); |
70 } | 88 } |
71 | 89 |
| 90 const std::vector<TestEntry>& entries() const { return entries_; } |
| 91 |
72 protected: | 92 protected: |
73 enum class WhatToRead { | |
74 HEADERS_ONLY, | |
75 HEADERS_AND_BODY, | |
76 }; | |
77 | 93 |
78 // Helper methods for constructing tests. | 94 // Helper methods for constructing tests. |
79 bool TimeWrite(); | 95 bool TimeWrites(); |
80 bool TimeRead(WhatToRead what_to_read, const char* timer_message); | 96 bool TimeReads(WhatToRead what_to_read, const char* timer_message); |
81 void ResetAndEvictSystemDiskCache(); | 97 void ResetAndEvictSystemDiskCache(); |
82 | 98 |
| 99 // Callbacks used within tests for intermediate operations. |
| 100 void WriteCallback(const net::CompletionCallback& final_callback, |
| 101 scoped_refptr<net::IOBuffer> headers_buffer, |
| 102 scoped_refptr<net::IOBuffer> body_buffer, |
| 103 disk_cache::Entry* cache_entry, |
| 104 int entry_index, |
| 105 size_t write_offset, |
| 106 int result); |
| 107 |
83 // Complete perf tests. | 108 // Complete perf tests. |
84 void CacheBackendPerformance(); | 109 void CacheBackendPerformance(); |
85 | 110 |
86 const size_t kFdLimitForCacheTests = 8192; | 111 const size_t kFdLimitForCacheTests = 8192; |
87 | 112 |
88 const int kNumEntries = 1000; | |
89 const int kHeadersSize = 800; | |
90 const int kBodySize = 256 * 1024 - 1; | |
91 | |
92 std::vector<TestEntry> entries_; | 113 std::vector<TestEntry> entries_; |
93 | 114 |
| 115 size_t next_entry_ = 0; // Which entry will be the next entry to read/write. |
| 116 size_t pending_operations_count_ = 0; |
| 117 int pending_result_; |
| 118 |
94 private: | 119 private: |
95 const size_t saved_fd_limit_; | |
96 base::test::ScopedTaskEnvironment scoped_task_environment_; | 120 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 121 const size_t saved_fd_limit_ = MaybeGetMaxFds(); |
97 }; | 122 }; |
98 | 123 |
99 // Creates num_entries on the cache, and writes kHeaderSize bytes of metadata | 124 class WriteHandler { |
100 // and up to kBodySize of data to each entry. | 125 public: |
101 bool DiskCachePerfTest::TimeWrite() { | 126 WriteHandler(const DiskCachePerfTest* test, |
102 // TODO(gavinp): This test would be significantly more realistic if it didn't | 127 disk_cache::Backend* cache, |
103 // do single reads and writes. Perhaps entries should be written 64kb at a | 128 net::CompletionCallback final_callback) |
104 // time. As well, not all entries should be created and written essentially | 129 : test_(test), cache_(cache), final_callback_(final_callback) { |
105 // simultaneously; some number of entries in flight at a time would be a | 130 CacheTestFillBuffer(headers_buffer_->data(), kHeadersSize, false); |
106 // likely better testing load. | 131 CacheTestFillBuffer(body_buffer_->data(), kChunkSize, false); |
107 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kHeadersSize)); | 132 } |
108 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kBodySize)); | 133 |
109 | 134 void Run(); |
110 CacheTestFillBuffer(buffer1->data(), kHeadersSize, false); | 135 |
111 CacheTestFillBuffer(buffer2->data(), kBodySize, false); | 136 protected: |
112 | 137 void CreateNextEntry(); |
113 int expected = 0; | 138 |
114 | 139 void CreateCallback(std::unique_ptr<disk_cache::Entry*> unique_entry_ptr, |
115 MessageLoopHelper helper; | 140 int data_len, |
116 CallbackTest callback(&helper, true); | 141 int result); |
117 | 142 void WriteDataCallback(disk_cache::Entry* entry, |
118 base::PerfTimeLogger timer("Write disk cache entries"); | 143 int next_offset, |
119 | 144 int data_len, |
120 for (int i = 0; i < kNumEntries; i++) { | 145 int expected_result, |
| 146 int result); |
| 147 |
| 148 private: |
| 149 bool CheckForErrorAndCancel(int result); |
| 150 |
| 151 const DiskCachePerfTest* test_; |
| 152 disk_cache::Backend* cache_; |
| 153 net::CompletionCallback final_callback_; |
| 154 |
| 155 size_t next_entry_index_ = 0; |
| 156 size_t pending_operations_count_ = 0; |
| 157 |
| 158 int pending_result_ = net::OK; |
| 159 |
| 160 scoped_refptr<net::IOBuffer> headers_buffer_ = |
| 161 new net::IOBuffer(kHeadersSize); |
| 162 scoped_refptr<net::IOBuffer> body_buffer_ = new net::IOBuffer(kChunkSize); |
| 163 }; |
| 164 |
| 165 void WriteHandler::Run() { |
| 166 for (int i = 0; i < kMaxParallelOperations; ++i) { |
| 167 ++pending_operations_count_; |
| 168 CreateNextEntry(); |
| 169 } |
| 170 } |
| 171 |
| 172 void WriteHandler::CreateNextEntry() { |
| 173 EXPECT_GT(kNumEntries, next_entry_index_); |
| 174 TestEntry test_entry = test_->entries()[next_entry_index_++]; |
| 175 disk_cache::Entry** entry_ptr = new disk_cache::Entry*(); |
| 176 std::unique_ptr<disk_cache::Entry*> unique_entry_ptr(entry_ptr); |
| 177 net::CompletionCallback callback = |
| 178 base::Bind(&WriteHandler::CreateCallback, base::Unretained(this), |
| 179 base::Passed(&unique_entry_ptr), test_entry.data_len); |
| 180 int result = cache_->CreateEntry(test_entry.key, entry_ptr, callback); |
| 181 if (result != net::ERR_IO_PENDING) |
| 182 callback.Run(result); |
| 183 } |
| 184 |
| 185 void WriteHandler::CreateCallback(std::unique_ptr<disk_cache::Entry*> entry_ptr, |
| 186 int data_len, |
| 187 int result) { |
| 188 if (CheckForErrorAndCancel(result)) |
| 189 return; |
| 190 |
| 191 disk_cache::Entry* entry = *entry_ptr; |
| 192 |
| 193 net::CompletionCallback callback = |
| 194 base::Bind(&WriteHandler::WriteDataCallback, base::Unretained(this), |
| 195 entry, 0, data_len, kHeadersSize); |
| 196 int new_result = entry->WriteData(0, 0, headers_buffer_.get(), kHeadersSize, |
| 197 callback, false); |
| 198 if (new_result != net::ERR_IO_PENDING) |
| 199 callback.Run(new_result); |
| 200 } |
| 201 |
| 202 void WriteHandler::WriteDataCallback(disk_cache::Entry* entry, |
| 203 int next_offset, |
| 204 int data_len, |
| 205 int expected_result, |
| 206 int result) { |
| 207 if (CheckForErrorAndCancel(result)) { |
| 208 entry->Close(); |
| 209 return; |
| 210 } |
| 211 if (next_offset >= data_len) { |
| 212 entry->Close(); |
| 213 if (next_entry_index_ < kNumEntries) { |
| 214 CreateNextEntry(); |
| 215 } else { |
| 216 --pending_operations_count_; |
| 217 if (pending_operations_count_ == 0) |
| 218 final_callback_.Run(net::OK); |
| 219 } |
| 220 return; |
| 221 } |
| 222 |
| 223 int write_size = std::min(kChunkSize, data_len - next_offset); |
| 224 net::CompletionCallback callback = |
| 225 base::Bind(&WriteHandler::WriteDataCallback, base::Unretained(this), |
| 226 entry, next_offset + write_size, data_len, write_size); |
| 227 int new_result = entry->WriteData(1, next_offset, body_buffer_.get(), |
| 228 write_size, callback, false); |
| 229 if (new_result != net::ERR_IO_PENDING) |
| 230 callback.Run(new_result); |
| 231 } |
| 232 |
| 233 bool WriteHandler::CheckForErrorAndCancel(int result) { |
| 234 DCHECK_NE(net::ERR_IO_PENDING, result); |
| 235 if (result != net::OK && !(result > 0)) |
| 236 pending_result_ = result; |
| 237 if (pending_result_ != net::OK) { |
| 238 --pending_operations_count_; |
| 239 if (pending_operations_count_ == 0) |
| 240 final_callback_.Run(pending_result_); |
| 241 return true; |
| 242 } |
| 243 return false; |
| 244 } |
| 245 |
| 246 class ReadHandler { |
| 247 public: |
| 248 ReadHandler(const DiskCachePerfTest* test, |
| 249 WhatToRead what_to_read, |
| 250 disk_cache::Backend* cache, |
| 251 net::CompletionCallback final_callback) |
| 252 : test_(test), |
| 253 what_to_read_(what_to_read), |
| 254 cache_(cache), |
| 255 final_callback_(final_callback) { |
| 256 for (int i = 0; i < kMaxParallelOperations; ++i) |
| 257 read_buffers_[i] = new net::IOBuffer(std::max(kHeadersSize, kChunkSize)); |
| 258 } |
| 259 |
| 260 void Run(); |
| 261 |
| 262 protected: |
| 263 void OpenNextEntry(int parallel_operation_index); |
| 264 |
| 265 void OpenCallback(int parallel_operation_index, |
| 266 std::unique_ptr<disk_cache::Entry*> unique_entry_ptr, |
| 267 int data_len, |
| 268 int result); |
| 269 void ReadDataCallback(int parallel_operation_index, |
| 270 disk_cache::Entry* entry, |
| 271 int next_offset, |
| 272 int data_len, |
| 273 int expected_result, |
| 274 int result); |
| 275 |
| 276 private: |
| 277 bool CheckForErrorAndCancel(int result); |
| 278 |
| 279 const DiskCachePerfTest* test_; |
| 280 const WhatToRead what_to_read_; |
| 281 |
| 282 disk_cache::Backend* cache_; |
| 283 net::CompletionCallback final_callback_; |
| 284 |
| 285 size_t next_entry_index_ = 0; |
| 286 size_t pending_operations_count_ = 0; |
| 287 |
| 288 int pending_result_ = net::OK; |
| 289 |
| 290 scoped_refptr<net::IOBuffer> read_buffers_[kMaxParallelOperations]; |
| 291 }; |
| 292 |
| 293 void ReadHandler::Run() { |
| 294 for (int i = 0; i < kMaxParallelOperations; ++i) { |
| 295 OpenNextEntry(pending_operations_count_); |
| 296 ++pending_operations_count_; |
| 297 } |
| 298 } |
| 299 |
| 300 void ReadHandler::OpenNextEntry(int parallel_operation_index) { |
| 301 EXPECT_GT(kNumEntries, next_entry_index_); |
| 302 TestEntry test_entry = test_->entries()[next_entry_index_++]; |
| 303 disk_cache::Entry** entry_ptr = new disk_cache::Entry*(); |
| 304 std::unique_ptr<disk_cache::Entry*> unique_entry_ptr(entry_ptr); |
| 305 net::CompletionCallback callback = |
| 306 base::Bind(&ReadHandler::OpenCallback, base::Unretained(this), |
| 307 parallel_operation_index, base::Passed(&unique_entry_ptr), |
| 308 test_entry.data_len); |
| 309 int result = cache_->OpenEntry(test_entry.key, entry_ptr, callback); |
| 310 if (result != net::ERR_IO_PENDING) |
| 311 callback.Run(result); |
| 312 } |
| 313 |
| 314 void ReadHandler::OpenCallback(int parallel_operation_index, |
| 315 std::unique_ptr<disk_cache::Entry*> entry_ptr, |
| 316 int data_len, |
| 317 int result) { |
| 318 if (CheckForErrorAndCancel(result)) |
| 319 return; |
| 320 |
| 321 disk_cache::Entry* entry = *(entry_ptr.get()); |
| 322 |
| 323 EXPECT_EQ(data_len, entry->GetDataSize(1)); |
| 324 |
| 325 net::CompletionCallback callback = |
| 326 base::Bind(&ReadHandler::ReadDataCallback, base::Unretained(this), |
| 327 parallel_operation_index, entry, 0, data_len, kHeadersSize); |
| 328 int new_result = |
| 329 entry->ReadData(0, 0, read_buffers_[parallel_operation_index].get(), |
| 330 kChunkSize, callback); |
| 331 if (new_result != net::ERR_IO_PENDING) |
| 332 callback.Run(new_result); |
| 333 } |
| 334 |
| 335 void ReadHandler::ReadDataCallback(int parallel_operation_index, |
| 336 disk_cache::Entry* entry, |
| 337 int next_offset, |
| 338 int data_len, |
| 339 int expected_result, |
| 340 int result) { |
| 341 if (CheckForErrorAndCancel(result)) { |
| 342 entry->Close(); |
| 343 return; |
| 344 } |
| 345 if (what_to_read_ == WhatToRead::HEADERS_ONLY || next_offset >= data_len) { |
| 346 entry->Close(); |
| 347 if (next_entry_index_ < kNumEntries) { |
| 348 OpenNextEntry(parallel_operation_index); |
| 349 } else { |
| 350 --pending_operations_count_; |
| 351 if (pending_operations_count_ == 0) |
| 352 final_callback_.Run(net::OK); |
| 353 } |
| 354 return; |
| 355 } |
| 356 |
| 357 int expected_read_size = std::min(kChunkSize, data_len - next_offset); |
| 358 net::CompletionCallback callback = |
| 359 base::Bind(&ReadHandler::ReadDataCallback, base::Unretained(this), |
| 360 parallel_operation_index, entry, next_offset + kChunkSize, |
| 361 data_len, expected_read_size); |
| 362 int new_result = entry->ReadData( |
| 363 1, next_offset, read_buffers_[parallel_operation_index].get(), kChunkSize, |
| 364 callback); |
| 365 if (new_result != net::ERR_IO_PENDING) |
| 366 callback.Run(new_result); |
| 367 } |
| 368 |
| 369 bool ReadHandler::CheckForErrorAndCancel(int result) { |
| 370 DCHECK_NE(net::ERR_IO_PENDING, result); |
| 371 if (result != net::OK && !(result > 0)) |
| 372 pending_result_ = result; |
| 373 if (pending_result_ != net::OK) { |
| 374 --pending_operations_count_; |
| 375 if (pending_operations_count_ == 0) |
| 376 final_callback_.Run(pending_result_); |
| 377 return true; |
| 378 } |
| 379 return false; |
| 380 } |
| 381 |
| 382 bool DiskCachePerfTest::TimeWrites() { |
| 383 for (size_t i = 0; i < kNumEntries; i++) { |
121 TestEntry entry; | 384 TestEntry entry; |
122 entry.key = GenerateKey(true); | 385 entry.key = GenerateKey(true); |
123 entry.data_len = base::RandInt(0, kBodySize); | 386 entry.data_len = base::RandInt(0, kBodySize); |
124 entries_.push_back(entry); | 387 entries_.push_back(entry); |
125 | 388 } |
126 disk_cache::Entry* cache_entry; | 389 |
127 net::TestCompletionCallback cb; | 390 net::TestCompletionCallback cb; |
128 int rv = cache_->CreateEntry(entry.key, &cache_entry, cb.callback()); | 391 |
129 if (net::OK != cb.GetResult(rv)) | 392 base::PerfTimeLogger timer("Write disk cache entries"); |
130 break; | 393 |
131 int ret = cache_entry->WriteData( | 394 std::unique_ptr<WriteHandler> write_handler( |
132 0, 0, buffer1.get(), kHeadersSize, | 395 new WriteHandler(this, cache_.get(), cb.callback())); |
133 base::Bind(&CallbackTest::Run, base::Unretained(&callback)), false); | 396 write_handler->Run(); |
134 if (net::ERR_IO_PENDING == ret) | 397 return cb.WaitForResult() == net::OK; |
135 expected++; | 398 } |
136 else if (kHeadersSize != ret) | 399 |
137 break; | 400 bool DiskCachePerfTest::TimeReads(WhatToRead what_to_read, |
138 | 401 const char* timer_message) { |
139 ret = cache_entry->WriteData( | |
140 1, 0, buffer2.get(), entry.data_len, | |
141 base::Bind(&CallbackTest::Run, base::Unretained(&callback)), false); | |
142 if (net::ERR_IO_PENDING == ret) | |
143 expected++; | |
144 else if (entry.data_len != ret) | |
145 break; | |
146 cache_entry->Close(); | |
147 } | |
148 | |
149 helper.WaitUntilCacheIoFinished(expected); | |
150 timer.Done(); | |
151 | |
152 return expected == helper.callbacks_called(); | |
153 } | |
154 | |
155 // Reads the data and metadata from each entry listed on |entries|. | |
156 bool DiskCachePerfTest::TimeRead(WhatToRead what_to_read, | |
157 const char* timer_message) { | |
158 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kHeadersSize)); | |
159 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kBodySize)); | |
160 | |
161 CacheTestFillBuffer(buffer1->data(), kHeadersSize, false); | |
162 CacheTestFillBuffer(buffer2->data(), kBodySize, false); | |
163 | |
164 int expected = 0; | |
165 | |
166 MessageLoopHelper helper; | |
167 CallbackTest callback(&helper, true); | |
168 | |
169 base::PerfTimeLogger timer(timer_message); | 402 base::PerfTimeLogger timer(timer_message); |
170 | 403 |
171 for (int i = 0; i < kNumEntries; i++) { | 404 net::TestCompletionCallback cb; |
172 disk_cache::Entry* cache_entry; | 405 std::unique_ptr<ReadHandler> read_handler( |
173 net::TestCompletionCallback cb; | 406 new ReadHandler(this, what_to_read, cache_.get(), cb.callback())); |
174 int rv = cache_->OpenEntry(entries_[i].key, &cache_entry, cb.callback()); | 407 read_handler->Run(); |
175 if (net::OK != cb.GetResult(rv)) | 408 return cb.WaitForResult() == net::OK; |
176 break; | |
177 int ret = cache_entry->ReadData( | |
178 0, 0, buffer1.get(), kHeadersSize, | |
179 base::Bind(&CallbackTest::Run, base::Unretained(&callback))); | |
180 if (net::ERR_IO_PENDING == ret) | |
181 expected++; | |
182 else if (kHeadersSize != ret) | |
183 break; | |
184 | |
185 if (what_to_read == WhatToRead::HEADERS_AND_BODY) { | |
186 ret = cache_entry->ReadData( | |
187 1, 0, buffer2.get(), entries_[i].data_len, | |
188 base::Bind(&CallbackTest::Run, base::Unretained(&callback))); | |
189 if (net::ERR_IO_PENDING == ret) | |
190 expected++; | |
191 else if (entries_[i].data_len != ret) | |
192 break; | |
193 } | |
194 | |
195 cache_entry->Close(); | |
196 } | |
197 | |
198 helper.WaitUntilCacheIoFinished(expected); | |
199 timer.Done(); | |
200 | |
201 return (expected == helper.callbacks_called()); | |
202 } | 409 } |
203 | 410 |
204 TEST_F(DiskCachePerfTest, BlockfileHashes) { | 411 TEST_F(DiskCachePerfTest, BlockfileHashes) { |
205 base::PerfTimeLogger timer("Hash disk cache keys"); | 412 base::PerfTimeLogger timer("Hash disk cache keys"); |
206 for (int i = 0; i < 300000; i++) { | 413 for (int i = 0; i < 300000; i++) { |
207 std::string key = GenerateKey(true); | 414 std::string key = GenerateKey(true); |
208 base::Hash(key); | 415 base::Hash(key); |
209 } | 416 } |
210 timer.Done(); | 417 timer.Done(); |
211 } | 418 } |
(...skipping 19 matching lines...) Expand all Loading... |
231 } | 438 } |
232 ASSERT_TRUE(base::EvictFileFromSystemCache(cache_path_)); | 439 ASSERT_TRUE(base::EvictFileFromSystemCache(cache_path_)); |
233 #endif | 440 #endif |
234 | 441 |
235 DisableFirstCleanup(); | 442 DisableFirstCleanup(); |
236 InitCache(); | 443 InitCache(); |
237 } | 444 } |
238 | 445 |
239 void DiskCachePerfTest::CacheBackendPerformance() { | 446 void DiskCachePerfTest::CacheBackendPerformance() { |
240 InitCache(); | 447 InitCache(); |
241 EXPECT_TRUE(TimeWrite()); | 448 EXPECT_TRUE(TimeWrites()); |
242 | 449 |
243 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | 450 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
244 base::RunLoop().RunUntilIdle(); | 451 base::RunLoop().RunUntilIdle(); |
245 | 452 |
246 ResetAndEvictSystemDiskCache(); | 453 ResetAndEvictSystemDiskCache(); |
247 EXPECT_TRUE(TimeRead(WhatToRead::HEADERS_ONLY, | 454 EXPECT_TRUE(TimeReads(WhatToRead::HEADERS_ONLY, |
248 "Read disk cache headers only (cold)")); | 455 "Read disk cache headers only (cold)")); |
249 EXPECT_TRUE(TimeRead(WhatToRead::HEADERS_ONLY, | 456 EXPECT_TRUE(TimeReads(WhatToRead::HEADERS_ONLY, |
250 "Read disk cache headers only (warm)")); | 457 "Read disk cache headers only (warm)")); |
251 | 458 |
252 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | 459 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
253 base::RunLoop().RunUntilIdle(); | 460 base::RunLoop().RunUntilIdle(); |
254 | 461 |
255 ResetAndEvictSystemDiskCache(); | 462 ResetAndEvictSystemDiskCache(); |
256 EXPECT_TRUE( | 463 EXPECT_TRUE(TimeReads(WhatToRead::HEADERS_AND_BODY, |
257 TimeRead(WhatToRead::HEADERS_AND_BODY, "Read disk cache entries (cold)")); | 464 "Read disk cache entries (cold)")); |
258 EXPECT_TRUE( | 465 EXPECT_TRUE(TimeReads(WhatToRead::HEADERS_AND_BODY, |
259 TimeRead(WhatToRead::HEADERS_AND_BODY, "Read disk cache entries (warm)")); | 466 "Read disk cache entries (warm)")); |
260 | 467 |
261 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | 468 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
262 base::RunLoop().RunUntilIdle(); | 469 base::RunLoop().RunUntilIdle(); |
263 } | 470 } |
264 | 471 |
265 TEST_F(DiskCachePerfTest, CacheBackendPerformance) { | 472 TEST_F(DiskCachePerfTest, CacheBackendPerformance) { |
266 CacheBackendPerformance(); | 473 CacheBackendPerformance(); |
267 } | 474 } |
268 | 475 |
269 TEST_F(DiskCachePerfTest, SimpleCacheBackendPerformance) { | 476 TEST_F(DiskCachePerfTest, SimpleCacheBackendPerformance) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 index.SetMaxSize(kEntries); | 552 index.SetMaxSize(kEntries); |
346 index.UpdateEntrySize(0, 1u); | 553 index.UpdateEntrySize(0, 1u); |
347 evict_elapsed_ms += timer.Elapsed().InMillisecondsF(); | 554 evict_elapsed_ms += timer.Elapsed().InMillisecondsF(); |
348 } | 555 } |
349 | 556 |
350 LOG(ERROR) << "Average time to evict:" << (evict_elapsed_ms / iterations) | 557 LOG(ERROR) << "Average time to evict:" << (evict_elapsed_ms / iterations) |
351 << "ms"; | 558 << "ms"; |
352 } | 559 } |
353 | 560 |
354 } // namespace | 561 } // namespace |
OLD | NEW |