| 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/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/test/perf_time_logger.h" | 15 #include "base/test/perf_time_logger.h" |
| 16 #include "base/test/test_file_util.h" | 16 #include "base/test/test_file_util.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "net/base/cache_type.h" | 18 #include "net/base/cache_type.h" |
| 19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
| 22 #include "net/disk_cache/blockfile/backend_impl.h" | 22 #include "net/disk_cache/blockfile/backend_impl.h" |
| 23 #include "net/disk_cache/blockfile/block_files.h" | 23 #include "net/disk_cache/blockfile/block_files.h" |
| 24 #include "net/disk_cache/disk_cache.h" | 24 #include "net/disk_cache/disk_cache.h" |
| 25 #include "net/disk_cache/disk_cache_test_base.h" | 25 #include "net/disk_cache/disk_cache_test_base.h" |
| 26 #include "net/disk_cache/disk_cache_test_util.h" | 26 #include "net/disk_cache/disk_cache_test_util.h" |
| 27 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "testing/platform_test.h" | 29 #include "testing/platform_test.h" |
| 29 | 30 |
| 30 using base::Time; | 31 using base::Time; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 size_t MaybeGetMaxFds() { | 35 size_t MaybeGetMaxFds() { |
| 35 #if defined(OS_POSIX) | 36 #if defined(OS_POSIX) |
| 36 return base::GetMaxFds(); | 37 return base::GetMaxFds(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 #endif | 229 #endif |
| 229 | 230 |
| 230 DisableFirstCleanup(); | 231 DisableFirstCleanup(); |
| 231 InitCache(); | 232 InitCache(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 void DiskCachePerfTest::CacheBackendPerformance() { | 235 void DiskCachePerfTest::CacheBackendPerformance() { |
| 235 InitCache(); | 236 InitCache(); |
| 236 EXPECT_TRUE(TimeWrite()); | 237 EXPECT_TRUE(TimeWrite()); |
| 237 | 238 |
| 239 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
| 240 base::MessageLoop::current()->RunUntilIdle(); |
| 241 |
| 238 ResetAndEvictSystemDiskCache(); | 242 ResetAndEvictSystemDiskCache(); |
| 239 EXPECT_TRUE(TimeRead(WhatToRead::HEADERS_ONLY, | 243 EXPECT_TRUE(TimeRead(WhatToRead::HEADERS_ONLY, |
| 240 "Read disk cache headers only (cold)")); | 244 "Read disk cache headers only (cold)")); |
| 241 EXPECT_TRUE(TimeRead(WhatToRead::HEADERS_ONLY, | 245 EXPECT_TRUE(TimeRead(WhatToRead::HEADERS_ONLY, |
| 242 "Read disk cache headers only (warm)")); | 246 "Read disk cache headers only (warm)")); |
| 247 |
| 248 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
| 243 base::MessageLoop::current()->RunUntilIdle(); | 249 base::MessageLoop::current()->RunUntilIdle(); |
| 244 | 250 |
| 245 ResetAndEvictSystemDiskCache(); | 251 ResetAndEvictSystemDiskCache(); |
| 246 EXPECT_TRUE( | 252 EXPECT_TRUE( |
| 247 TimeRead(WhatToRead::HEADERS_AND_BODY, "Read disk cache entries (cold)")); | 253 TimeRead(WhatToRead::HEADERS_AND_BODY, "Read disk cache entries (cold)")); |
| 248 EXPECT_TRUE( | 254 EXPECT_TRUE( |
| 249 TimeRead(WhatToRead::HEADERS_AND_BODY, "Read disk cache entries (warm)")); | 255 TimeRead(WhatToRead::HEADERS_AND_BODY, "Read disk cache entries (warm)")); |
| 256 |
| 257 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
| 250 base::MessageLoop::current()->RunUntilIdle(); | 258 base::MessageLoop::current()->RunUntilIdle(); |
| 251 } | 259 } |
| 252 | 260 |
| 253 TEST_F(DiskCachePerfTest, CacheBackendPerformance) { | 261 TEST_F(DiskCachePerfTest, CacheBackendPerformance) { |
| 254 CacheBackendPerformance(); | 262 CacheBackendPerformance(); |
| 255 } | 263 } |
| 256 | 264 |
| 257 TEST_F(DiskCachePerfTest, SimpleCacheBackendPerformance) { | 265 TEST_F(DiskCachePerfTest, SimpleCacheBackendPerformance) { |
| 258 SetSimpleCacheMode(); | 266 SetSimpleCacheMode(); |
| 259 CacheBackendPerformance(); | 267 CacheBackendPerformance(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 files.DeleteBlock(address[entry], false); | 308 files.DeleteBlock(address[entry], false); |
| 301 EXPECT_TRUE( | 309 EXPECT_TRUE( |
| 302 files.CreateBlock(disk_cache::RANKINGS, BlockSize(), &address[entry])); | 310 files.CreateBlock(disk_cache::RANKINGS, BlockSize(), &address[entry])); |
| 303 } | 311 } |
| 304 | 312 |
| 305 timer2.Done(); | 313 timer2.Done(); |
| 306 base::MessageLoop::current()->RunUntilIdle(); | 314 base::MessageLoop::current()->RunUntilIdle(); |
| 307 } | 315 } |
| 308 | 316 |
| 309 } // namespace | 317 } // namespace |
| OLD | NEW |