Chromium Code Reviews| 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 <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/hash.h" | 12 #include "base/hash.h" |
| 13 #include "base/process/process_metrics.h" | 13 #include "base/process/process_metrics.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/test/perf_time_logger.h" | 17 #include "base/test/perf_time_logger.h" |
| 18 #include "base/test/test_file_util.h" | 18 #include "base/test/test_file_util.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "net/base/cache_type.h" | 20 #include "net/base/cache_type.h" |
| 21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/base/test_completion_callback.h" | 23 #include "net/base/test_completion_callback.h" |
| 24 #include "net/disk_cache/blockfile/backend_impl.h" | 24 #include "net/disk_cache/blockfile/backend_impl.h" |
| 25 #include "net/disk_cache/blockfile/block_files.h" | 25 #include "net/disk_cache/blockfile/block_files.h" |
| 26 #include "net/disk_cache/disk_cache.h" | 26 #include "net/disk_cache/disk_cache.h" |
| 27 #include "net/disk_cache/disk_cache_test_base.h" | 27 #include "net/disk_cache/disk_cache_test_base.h" |
| 28 #include "net/disk_cache/disk_cache_test_util.h" | 28 #include "net/disk_cache/disk_cache_test_util.h" |
| 29 #include "net/disk_cache/simple/simple_backend_impl.h" | 29 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 30 #include "net/disk_cache/simple/simple_index.h" | |
| 31 #include "net/disk_cache/simple/simple_index_file.h" | |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "testing/platform_test.h" | 33 #include "testing/platform_test.h" |
| 32 | 34 |
| 33 using base::Time; | 35 using base::Time; |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 size_t MaybeGetMaxFds() { | 39 size_t MaybeGetMaxFds() { |
| 38 #if defined(OS_POSIX) | 40 #if defined(OS_POSIX) |
| 39 return base::GetMaxFds(); | 41 return base::GetMaxFds(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 | 300 |
| 299 files.DeleteBlock(address[entry], false); | 301 files.DeleteBlock(address[entry], false); |
| 300 EXPECT_TRUE( | 302 EXPECT_TRUE( |
| 301 files.CreateBlock(disk_cache::RANKINGS, block_size, &address[entry])); | 303 files.CreateBlock(disk_cache::RANKINGS, block_size, &address[entry])); |
| 302 } | 304 } |
| 303 | 305 |
| 304 timer2.Done(); | 306 timer2.Done(); |
| 305 base::RunLoop().RunUntilIdle(); | 307 base::RunLoop().RunUntilIdle(); |
| 306 } | 308 } |
| 307 | 309 |
| 310 // Measures how quickly SimpleIndex can compute which entries to evict. | |
| 311 TEST(SimpleIndexPerfTest, EvictionPerformance) { | |
| 312 const int kEntries = 10000; | |
| 313 | |
| 314 class NoOpDelegate : public disk_cache::SimpleIndexDelegate { | |
| 315 void DoomEntries(std::vector<uint64_t>* entry_hashes, | |
| 316 const net::CompletionCallback& callback) override {} | |
| 317 }; | |
| 318 | |
| 319 NoOpDelegate delegate; | |
| 320 base::Time start(base::Time::Now()); | |
| 321 | |
| 322 double evict_elapsed_ms = 0; | |
| 323 int iterations = 0; | |
| 324 while (iterations < 61000) { | |
| 325 ++iterations; | |
| 326 disk_cache::SimpleIndex index(nullptr, &delegate, net::DISK_CACHE, nullptr); | |
| 327 | |
| 328 // Make sure large enough to not evict on insertion. | |
| 329 index.SetMaxSize(kEntries * 2); | |
| 330 | |
| 331 for (int i = 0; i < kEntries; ++i) { | |
| 332 index.InsertEntryForTesting( | |
| 333 i, disk_cache::EntryMetadata(start + base::TimeDelta::FromSeconds(i), | |
|
pasko
2017/04/03 09:39:08
nit: maybe do a sha1(i) to make the keys look more
Maks Orlovich
2017/04/03 14:32:40
Yeah, I think I'll pass, since I trust unordered_m
| |
| 334 0u)); | |
| 335 index.UpdateEntrySize(i, 1u); | |
|
pasko
2017/04/03 09:39:08
I think it would be less error prone to make Inser
Maks Orlovich
2017/04/03 14:32:40
Done. Also added a DCHECK to require entry to not
| |
| 336 } | |
| 337 | |
| 338 // Trigger an eviction. | |
| 339 base::ElapsedTimer timer; | |
| 340 index.SetMaxSize(kEntries); | |
| 341 index.UpdateEntrySize(0, 1u); | |
| 342 evict_elapsed_ms += timer.Elapsed().InMillisecondsF(); | |
| 343 } | |
| 344 | |
| 345 LOG(ERROR) << "Average time to evict:" << (evict_elapsed_ms / iterations) | |
| 346 << "ms"; | |
| 347 } | |
| 348 | |
| 308 } // namespace | 349 } // namespace |
| OLD | NEW |