summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/file_util.h4
-rw-r--r--base/file_util_linux.cc12
-rw-r--r--base/file_util_mac.mm6
-rw-r--r--base/file_util_win.cc41
-rw-r--r--chrome/SConscript2
-rw-r--r--chrome/test/test_file_util.cc30
-rw-r--r--chrome/test/test_file_util.h11
-rw-r--r--chrome/tools/perf/flush_cache/SConscript30
-rw-r--r--chrome/tools/perf/flush_cache/flush_cache.cc11
-rw-r--r--net/disk_cache/disk_cache_perftest.cc100
10 files changed, 109 insertions, 138 deletions
diff --git a/base/file_util.h b/base/file_util.h
index 3df31e4..0bdb56d 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -389,6 +389,10 @@ bool RenameFileAndResetSecurityDescriptor(
const std::wstring& source_file_path,
const std::wstring& target_file_path);
+// Clear a specific file from the system cache. After this call, trying
+// to access this file will result in a cold load from the hard drive.
+bool EvictFileFromSystemCache(const FilePath path);
+
} // namespace file_util
#endif // BASE_FILE_UTIL_H_
diff --git a/base/file_util_linux.cc b/base/file_util_linux.cc
index f776c91..d2a6870 100644
--- a/base/file_util_linux.cc
+++ b/base/file_util_linux.cc
@@ -72,4 +72,16 @@ bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
return result;
}
+bool EvictFileFromSystemCache(const FilePath path) {
+ int fd = open(path.value().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;
+}
+
} // namespace file_util
diff --git a/base/file_util_mac.mm b/base/file_util_mac.mm
index f7f5632..0cf63d2 100644
--- a/base/file_util_mac.mm
+++ b/base/file_util_mac.mm
@@ -28,4 +28,10 @@ bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
to_path.value().c_str(), NULL, COPYFILE_ALL) == 0);
}
+bool EvictFileFromSystemCache(const FilePath path) {
+ // TODO(port): Implement.
+ NOTIMPLEMENTED();
+ return false;
+}
+
} // namespace
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 355bdfd..5f75544 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -692,4 +692,45 @@ std::wstring FileEnumerator::Next() {
return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
}
+bool EvictFileFromSystemCache(const FilePath path) {
+ // Overwrite it with no buffering.
+ ScopedHandle file(CreateFile(path.value().c_str(),
+ 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 operations 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;
+}
+
} // namespace file_util
diff --git a/chrome/SConscript b/chrome/SConscript
index d691dd9..16e9d5d 100644
--- a/chrome/SConscript
+++ b/chrome/SConscript
@@ -391,6 +391,7 @@ if env_flat['PLATFORM'] == 'win32':
sconscript_files = [
'test/chrome_plugin/SConscript',
+ 'tools/perf/flush_cache/SConscript',
'tools/test/image_diff/SConscript',
'third_party/hunspell/SConscript',
'$THIRD_PARTY_DIR/sqlite/SConscript',
@@ -417,7 +418,6 @@ if env['PLATFORM'] == 'win32':
'test/startup/SConscript',
'test/tab_switching/SConscript',
'tools/crash_service/SConscript',
- 'tools/perf/flush_cache/SConscript',
'views/SConscript',
])
diff --git a/chrome/test/test_file_util.cc b/chrome/test/test_file_util.cc
index 5bb55cc..633fdc9 100644
--- a/chrome/test/test_file_util.cc
+++ b/chrome/test/test_file_util.cc
@@ -12,34 +12,6 @@
namespace file_util {
-bool EvictFileFromSystemCache(const wchar_t* file) {
- // Request exclusive access to the file and overwrite it with no buffering.
- win_util::ScopedHandle hfile(
- CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL,
- OPEN_EXISTING, FILE_FLAG_NO_BUFFERING,
- NULL));
- if (!hfile)
- 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[4096];
- int total_bytes = 0;
- DWORD bytes_read;
- for (;;) {
- bytes_read = 0;
- ReadFile(hfile, buffer, sizeof(buffer), &bytes_read, NULL);
- if (bytes_read == 0)
- break;
-
- SetFilePointer(hfile, total_bytes, 0, FILE_BEGIN);
- if (!WriteFile(hfile, buffer, bytes_read, &bytes_read, NULL))
- return false;
- total_bytes += bytes_read;
- }
- return true;
-}
-
// Like CopyFileNoCache but recursively copies all files and subdirectories
// in the given input directory to the output directory.
bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
@@ -88,7 +60,7 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
// files that are in the repository, and they will have read-only set.
// This will prevent us from evicting from the cache, but these don't
// matter anyway.
- EvictFileFromSystemCache(cur_dest_path.c_str());
+ file_util::EvictFileFromSystemCache(cur_dest_path.c_str());
}
} while (FindNextFile(fh, &fd));
diff --git a/chrome/test/test_file_util.h b/chrome/test/test_file_util.h
index dd4e34f..bf415a1 100644
--- a/chrome/test/test_file_util.h
+++ b/chrome/test/test_file_util.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_TEST_TEST_FILE_UTIL_H__
-#define CHROME_TEST_TEST_FILE_UTIL_H__
+#ifndef CHROME_TEST_TEST_FILE_UTIL_H_
+#define CHROME_TEST_TEST_FILE_UTIL_H_
// File utility functions used only by tests.
@@ -11,11 +11,6 @@
namespace file_util {
-// Clear a specific file from the system cache using a neat trick. After this
-// call, trying to access this file will result in a cold load from the hard
-// drive.
-bool EvictFileFromSystemCache(const wchar_t* file);
-
// Like CopyFileNoCache but recursively copies all files and subdirectories
// in the given input directory to the output directory. Any files in the
// destination that already exist will be overwritten.
@@ -27,5 +22,5 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
} // namespace file_util
-#endif // CHROME_TEST_TEST_FILE_UTIL_H__
+#endif // CHROME_TEST_TEST_FILE_UTIL_H_
diff --git a/chrome/tools/perf/flush_cache/SConscript b/chrome/tools/perf/flush_cache/SConscript
index a33cb3c..cd1cacf 100644
--- a/chrome/tools/perf/flush_cache/SConscript
+++ b/chrome/tools/perf/flush_cache/SConscript
@@ -16,26 +16,26 @@ env_test.Prepend(
],
)
-env_test.Prepend(
- LINKFLAGS = [
- '/INCREMENTAL',
- '/DEBUG',
+if env_test['PLATFORM'] == 'win32':
+ env_test.Prepend(
+ LINKFLAGS = [
+ '/INCREMENTAL',
+ '/DEBUG',
- '/DELAYLOAD:"dwmapi.dll"',
- '/DELAYLOAD:"uxtheme.dll"',
+ '/DELAYLOAD:"dwmapi.dll"',
+ '/DELAYLOAD:"uxtheme.dll"',
- '/MACHINE:X86',
- '/FIXED:No',
+ '/MACHINE:X86',
+ '/FIXED:No',
- '/safeseh',
- '/dynamicbase',
- '/ignore:4199',
- '/nxcompat',
- ],
-)
+ '/safeseh',
+ '/dynamicbase',
+ '/ignore:4199',
+ '/nxcompat',
+ ],
+ )
input_files = [
- '$CHROME_DIR/test/test_file_util$OBJSUFFIX',
'flush_cache.cc',
]
diff --git a/chrome/tools/perf/flush_cache/flush_cache.cc b/chrome/tools/perf/flush_cache/flush_cache.cc
index f10b69b..f029028 100644
--- a/chrome/tools/perf/flush_cache/flush_cache.cc
+++ b/chrome/tools/perf/flush_cache/flush_cache.cc
@@ -5,10 +5,13 @@
// This little program attempts to flush the disk cache for some files.
// It's useful for testing Chrome with a cold database.
+#include "build/build_config.h"
+
+#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/string_piece.h"
#include "base/process_util.h"
#include "base/sys_string_conversions.h"
-#include "chrome/test/test_file_util.h"
int main(int argc, const char* argv[]) {
process_util::EnableTerminationOnHeapCorruption();
@@ -19,8 +22,12 @@ int main(int argc, const char* argv[]) {
}
for (int i = 1; i < argc; ++i) {
+#if defined(OS_POSIX)
+ std::string filename(argv[i]);
+#elif defined(OS_WIN)
std::wstring filename = base::SysNativeMBToWide(argv[i]);
- if (!file_util::EvictFileFromSystemCache(filename.c_str())) {
+#endif
+ if (!file_util::EvictFileFromSystemCache(FilePath(filename))) {
fprintf(stderr, "Failed to evict %s from cache -- is it a directory?\n",
argv[i]);
}
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 33cad54..8c61158 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -2,17 +2,13 @@
// 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"
#include "base/platform_test.h"
-#if defined(OS_WIN)
-#include "base/scoped_handle.h"
-#endif
#include "base/string_util.h"
#include "base/timer.h"
#include "net/base/net_errors.h"
@@ -32,62 +28,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 +154,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,25 +172,18 @@ 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()));
-
- filename = path;
- file_util::AppendToPath(&filename, L"data_3");
- ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
+ FilePath path = FilePath::FromWStringHack(path_wstring);
+
+ 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);
ASSERT_TRUE(NULL != cache);