diff options
-rw-r--r-- | base/file_util.cc | 3 | ||||
-rw-r--r-- | base/file_util.h | 2 | ||||
-rw-r--r-- | chrome/test/page_cycler/page_cycler_test.cc | 37 |
3 files changed, 18 insertions, 24 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index 79921ff..5bc73ce 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -186,7 +186,8 @@ bool ReadFileToString(const FilePath& path, std::string* contents) { char buf[1 << 16]; size_t len; while ((len = fread(buf, 1, sizeof(buf), file)) > 0) { - contents->append(buf, len); + if (contents) + contents->append(buf, len); } CloseFile(file); diff --git a/base/file_util.h b/base/file_util.h index 64a91ee..e62b30e 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -159,6 +159,8 @@ bool ContentsEqual(const FilePath& filename1, bool TextContentsEqual(const FilePath& filename1, const FilePath& filename2); // Read the file at |path| into |contents|, returning true on success. +// |contents| may be NULL, in which case this function is useful for its +// side effect of priming the disk cache. // Useful for unit tests. bool ReadFileToString(const FilePath& path, std::string* contents); diff --git a/chrome/test/page_cycler/page_cycler_test.cc b/chrome/test/page_cycler/page_cycler_test.cc index 96f678e..1e3d080 100644 --- a/chrome/test/page_cycler/page_cycler_test.cc +++ b/chrome/test/page_cycler/page_cycler_test.cc @@ -4,7 +4,6 @@ #include "base/basictypes.h" #include "base/command_line.h" -#include "base/eintr_wrapper.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" @@ -22,8 +21,6 @@ #include "net/base/net_util.h" #if defined(OS_MACOSX) -#include <errno.h> -#include <fcntl.h> #include <string.h> #include <sys/resource.h> #endif @@ -76,14 +73,16 @@ void SetFileDescriptorLimit(rlim_t max_descriptors) { PLOG(ERROR) << "Failed to get file descriptor limit"; } } +#endif // OS_MACOSX -void PopulateUBC(const FilePath &test_dir) { - // This will recursively walk the directory given and read all the files it - // finds. This is done so the Mac UBC is likely to have as much loaded as - // possible. Without this, the tests of this build gets one set of timings - // and then the reference build test, gets slightly faster ones (even if the - // reference build is the same binary). The hope is by forcing all the - // possible data into the UBC we equalize the tests for comparing timing data. +void PopulateBufferCache(const FilePath& test_dir) { + // This will recursively walk the directory given and read all the + // files it finds. This is done so the system file cache is likely + // to have as much loaded as possible. Without this, the tests of + // this build gets one set of timings and then the reference build + // test, gets slightly faster ones (even if the reference build is + // the same binary). The hope is by forcing all the possible data + // into the cache we equalize the tests for comparing timing data. // We don't want to walk into .svn dirs, so we have to do the tree walk // ourselves. @@ -104,7 +103,6 @@ void PopulateUBC(const FilePath &test_dir) { } } - char buf[1024]; unsigned int loaded = 0; // We seem to have some files in the data dirs that are just there for @@ -141,19 +139,14 @@ void PopulateUBC(const FilePath &test_dir) { if (should_skip) continue; - // Read the file to get it into the UBC - int fd = open(path.value().c_str(), O_RDONLY); - if (fd >= 0) { + // Read the file fully to get it into the cache. + // We don't care what the contents are. + if (file_util::ReadFileToString(path, NULL)) ++loaded; - while (HANDLE_EINTR(read(fd, buf, sizeof(buf))) > 0) { - } - HANDLE_EINTR(close(fd)); - } } } - LOG(INFO) << "UBC should be loaded with " << loaded << " files."; + LOG(INFO) << "Buffer cache should be primed with " << loaded << " files."; } -#endif // defined(OS_MACOSX) class PageCyclerTest : public UITest { protected: @@ -208,9 +201,7 @@ class PageCyclerTest : public UITest { ASSERT_TRUE(file_util::DirectoryExists(test_path)) << "Missing test directory " << test_path.value(); -#if defined(OS_MACOSX) - PopulateUBC(test_path); -#endif + PopulateBufferCache(test_path); GURL test_url; if (use_http) { |