summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 20:03:54 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 20:03:54 +0000
commit1ecbf13615d89a0e0369cab2e70692d5b9a46341 (patch)
tree8938e0f033cb69a1ef1c4b009396bec20c4e623a /net/disk_cache
parent91a55b979b98d4dd69c7dcf61bc408ae230efab1 (diff)
downloadchromium_src-1ecbf13615d89a0e0369cab2e70692d5b9a46341.zip
chromium_src-1ecbf13615d89a0e0369cab2e70692d5b9a46341.tar.gz
chromium_src-1ecbf13615d89a0e0369cab2e70692d5b9a46341.tar.bz2
Port flush_cache tool and perf_tests.
BUG=4160,4263 Review URL: http://codereview.chromium.org/9639 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/disk_cache_perftest.cc101
1 files changed, 18 insertions, 83 deletions
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index ecae2c3..08d0374 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -2,17 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <fcntl.h>
-
#include <string>
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "base/file_util.h"
#include "base/perftimer.h"
-#if defined(OS_WIN)
-#include "base/scoped_handle.h"
-#endif
#include "base/string_util.h"
+#include "base/test_file_util.h"
#include "base/timer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/block_files.h"
@@ -32,62 +29,6 @@ typedef PlatformTest DiskCacheTest;
namespace {
-bool EvictFileFromSystemCache(const wchar_t* name) {
-#if defined(OS_WIN)
- // Overwrite it with no buffering.
- ScopedHandle file(CreateFile(name, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
- OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL));
- if (!file.IsValid())
- return false;
-
- // Execute in chunks. It could be optimized. We want to do few of these since
- // these opterations will be slow without the cache.
- char buffer[128 * 1024];
- int total_bytes = 0;
- DWORD bytes_read;
- for (;;) {
- if (!ReadFile(file, buffer, sizeof(buffer), &bytes_read, NULL))
- return false;
- if (bytes_read == 0)
- break;
-
- bool final = false;
- if (bytes_read < sizeof(buffer))
- final = true;
-
- DWORD to_write = final ? sizeof(buffer) : bytes_read;
-
- DWORD actual;
- SetFilePointer(file, total_bytes, 0, FILE_BEGIN);
- if (!WriteFile(file, buffer, to_write, &actual, NULL))
- return false;
- total_bytes += bytes_read;
-
- if (final) {
- SetFilePointer(file, total_bytes, 0, FILE_BEGIN);
- SetEndOfFile(file);
- break;
- }
- }
- return true;
-#elif defined(OS_LINUX)
- int fd = open(WideToUTF8(std::wstring(name)).c_str(), O_RDONLY);
- if (fd < 0)
- return false;
- if (fdatasync(fd) != 0)
- return false;
- if (posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) != 0)
- return false;
- close(fd);
- return true;
-#else
- // TODO(port): Mac has its own way to do this.
- NOTIMPLEMENTED();
- return false;
-#endif
-}
-
struct TestEntry {
std::string key;
int data_len;
@@ -214,9 +155,10 @@ TEST_F(DiskCacheTest, Hash) {
TEST_F(DiskCacheTest, CacheBackendPerformance) {
MessageLoopForIO message_loop;
- std::wstring path = GetCachePath();
- ASSERT_TRUE(DeleteCache(path.c_str()));
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0);
+ std::wstring path_wstring = GetCachePath();
+ ASSERT_TRUE(DeleteCache(path_wstring.c_str()));
+ disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path_wstring,
+ false, 0);
ASSERT_TRUE(NULL != cache);
int seed = static_cast<int>(Time::Now().ToInternalValue());
@@ -231,27 +173,20 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
MessageLoop::current()->RunAllPending();
delete cache;
- std::wstring filename(path);
- file_util::AppendToPath(&filename, L"index");
- ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
-
- filename = path;
- file_util::AppendToPath(&filename, L"data_0");
- ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
-
- filename = path;
- file_util::AppendToPath(&filename, L"data_1");
- ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
-
- filename = path;
- file_util::AppendToPath(&filename, L"data_2");
- ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
+ FilePath path = FilePath::FromWStringHack(path_wstring);
- filename = path;
- file_util::AppendToPath(&filename, L"data_3");
- ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
+ ASSERT_TRUE(file_util::EvictFileFromSystemCache(
+ path.Append(FILE_PATH_LITERAL("index"))));
+ ASSERT_TRUE(file_util::EvictFileFromSystemCache(
+ path.Append(FILE_PATH_LITERAL("data_0"))));
+ ASSERT_TRUE(file_util::EvictFileFromSystemCache(
+ path.Append(FILE_PATH_LITERAL("data_1"))));
+ ASSERT_TRUE(file_util::EvictFileFromSystemCache(
+ path.Append(FILE_PATH_LITERAL("data_2"))));
+ ASSERT_TRUE(file_util::EvictFileFromSystemCache(
+ path.Append(FILE_PATH_LITERAL("data_3"))));
- cache = disk_cache::CreateCacheBackend(path, false, 0);
+ cache = disk_cache::CreateCacheBackend(path_wstring, false, 0);
ASSERT_TRUE(NULL != cache);
ret = TimeRead(num_entries, cache, entries, true);