Port flush_cache tool and perf_tests.

BUG=4160,4263

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=6815
Review URL: http://codereview.chromium.org/9639

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6886 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
phajdan.jr@chromium.org
2008-12-12 12:00:40 +00:00
commit ff5d15fbe5
13 arquivos alterados com 171 adições e 225 exclusões
+2
Ver Arquivo
@@ -191,6 +191,7 @@ if env['PLATFORM'] == 'darwin':
'platform_thread_mac.mm',
'scoped_nsautorelease_pool.mm',
'sys_string_conversions_mac.mm',
'test_file_util_mac.cc',
'worker_pool_mac.mm',
])
@@ -207,6 +208,7 @@ if env['PLATFORM'] == 'posix':
'process_posix.cc',
'process_util_linux.cc',
'sys_string_conversions_linux.cc',
'test_file_util_linux.cc',
'worker_pool.cc',
])
+3 -1
Ver Arquivo
@@ -9,11 +9,13 @@
#include <string>
class FilePath;
namespace file_util {
// 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 wchar_t* file);
bool EvictFileFromSystemCache(const FilePath& file);
// Like CopyFileNoCache but recursively copies all files and subdirectories
// in the given input directory to the output directory. Any files in the
+2 -3
Ver Arquivo
@@ -12,9 +12,8 @@
namespace file_util {
bool EvictFileFromSystemCache(const wchar_t* file) {
FilePath fpath = FilePath::FromWStringHack(file);
int fd = open(fpath.value().c_str(), O_RDONLY);
bool EvictFileFromSystemCache(const FilePath& file) {
int fd = open(file.value().c_str(), O_RDONLY);
if (fd < 0)
return false;
if (fdatasync(fd) != 0)
+1 -1
Ver Arquivo
@@ -8,7 +8,7 @@
namespace file_util {
bool EvictFileFromSystemCache(const wchar_t* file) {
bool EvictFileFromSystemCache(const FilePath& file) {
// TODO(port): Implement.
NOTIMPLEMENTED();
return false;
+6 -5
Ver Arquivo
@@ -8,6 +8,7 @@
#include <vector>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/scoped_handle.h"
@@ -17,10 +18,10 @@ namespace file_util {
// our purpose fine since 4K is the page size on x86 as well as x64.
static const ptrdiff_t kPageSize = 4096;
bool EvictFileFromSystemCache(const wchar_t* file) {
bool EvictFileFromSystemCache(const FilePath& file) {
// Request exclusive access to the file and overwrite it with no buffering.
ScopedHandle file_handle(
CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL,
CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL));
if (!file_handle)
return false;
@@ -85,8 +86,8 @@ bool EvictFileFromSystemCache(const wchar_t* file) {
// to open the file again, this time without the FILE_FLAG_NO_BUFFERING
// flag and use SetEndOfFile to mark EOF.
file_handle.Set(NULL);
file_handle.Set(CreateFile(file, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
0, NULL));
file_handle.Set(CreateFile(file.value().c_str(), GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL));
CHECK(SetFilePointer(file_handle, total_bytes, NULL, FILE_BEGIN) !=
INVALID_SET_FILE_POINTER);
CHECK(::SetEndOfFile(file_handle));
@@ -147,7 +148,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());
EvictFileFromSystemCache(FilePath::FromWStringHack(cur_dest_path));
}
} while (FindNextFile(fh, &fd));
+91 -85
Ver Arquivo
@@ -5,25 +5,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits>
#include <set>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/perftimer.h"
#include "base/rand_util.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/test_file_util.h"
#include "chrome/browser/safe_browsing/safe_browsing_database.h"
#include "chrome/browser/safe_browsing/safe_browsing_database_impl.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/sqlite_compiled_statement.h"
#include "chrome/common/sqlite_utils.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
// These tests are slow, especially the ones that create databases. So disable
// them by default.
//#define SAFE_BROWSING_DATABASE_TESTS_ENABLED
#ifdef SAFE_BROWSING_DATABASE_TESTS_ENABLED
namespace {
// Base class for a safebrowsing database. Derived classes can implement
@@ -35,28 +36,27 @@ class Database {
~Database() {
if (db_) {
statement_cache_.Cleanup();
sqlite3_close(db_);
db_ = NULL;
}
}
bool Init(const std::string& name, bool create) {
bool Init(const FilePath& name, bool create) {
// get an empty file for the test DB
std::wstring filename;
FilePath filename;
PathService::Get(base::DIR_TEMP, &filename);
filename.push_back(FilePath::kSeparators[0]);
filename.append(ASCIIToWide(name));
filename = filename.Append(name);
if (create) {
DeleteFile(filename.c_str());
file_util::Delete(filename, false);
} else {
DLOG(INFO) << "evicting " << name << " ...";
file_util::EvictFileFromSystemCache(filename.c_str());
DLOG(INFO) << "evicting " << name.value() << " ...";
file_util::EvictFileFromSystemCache(filename);
DLOG(INFO) << "... evicted";
}
if (sqlite3_open(WideToUTF8(filename).c_str(), &db_) != SQLITE_OK)
const std::string sqlite_path = WideToUTF8(filename.ToWStringHack());
if (sqlite3_open(sqlite_path.c_str(), &db_) != SQLITE_OK)
return false;
statement_cache_.set_db(db_);
@@ -197,7 +197,7 @@ class IndexedWithIDDatabase : public SimpleDatabase {
}
};
}
} // namespace
class SafeBrowsing: public testing::Test {
protected:
@@ -253,7 +253,8 @@ class SafeBrowsing: public testing::Test {
db_name_.append(count_start);
db_name_.append(db_->GetDBSuffix());
ASSERT_TRUE(db_->Init(db_name_, type == WRITE));
FilePath path = FilePath::FromWStringHack(ASCIIToWide(db_name_));
ASSERT_TRUE(db_->Init(path, type == WRITE));
if (type == WRITE) {
WriteEntries(size);
@@ -275,10 +276,9 @@ class SafeBrowsing: public testing::Test {
SQLTransaction transaction(db_->db());
transaction.Begin();
int inc = kint32max / count;
for (int i = 0; i < count; i++) {
int hostkey;
rand_s((unsigned int*)&hostkey);
int hostkey = base::RandInt(std::numeric_limits<int>::min(),
std::numeric_limits<int>::max());
ASSERT_TRUE(db_->Add(hostkey, prefixes, 1));
}
@@ -292,8 +292,8 @@ class SafeBrowsing: public testing::Test {
int64 total_ms = 0;
for (int i = 0; i < count; ++i) {
int key;
rand_s((unsigned int*)&key);
int key = base::RandInt(std::numeric_limits<int>::min(),
std::numeric_limits<int>::max());
PerfTimer timer;
@@ -332,74 +332,75 @@ class SafeBrowsing: public testing::Test {
std::string db_name_;
};
TEST_F(SafeBrowsing, Write_100K) {
TEST_F(SafeBrowsing, DISABLED_Write_100K) {
}
TEST_F(SafeBrowsing, Read_100K) {
TEST_F(SafeBrowsing, DISABLED_Read_100K) {
}
TEST_F(SafeBrowsing, WriteIndexed_100K) {
TEST_F(SafeBrowsing, DISABLED_WriteIndexed_100K) {
}
TEST_F(SafeBrowsing, ReadIndexed_100K) {
TEST_F(SafeBrowsing, DISABLED_ReadIndexed_100K) {
}
TEST_F(SafeBrowsing, WriteIndexed_250K) {
TEST_F(SafeBrowsing, DISABLED_WriteIndexed_250K) {
}
TEST_F(SafeBrowsing, ReadIndexed_250K) {
TEST_F(SafeBrowsing, DISABLED_ReadIndexed_250K) {
}
TEST_F(SafeBrowsing, WriteIndexed_500K) {
TEST_F(SafeBrowsing, DISABLED_WriteIndexed_500K) {
}
TEST_F(SafeBrowsing, ReadIndexed_500K) {
TEST_F(SafeBrowsing, DISABLED_ReadIndexed_500K) {
}
TEST_F(SafeBrowsing, ReadIndexedWithID_250K) {
TEST_F(SafeBrowsing, DISABLED_WriteIndexedWithID_250K) {
}
TEST_F(SafeBrowsing, WriteIndexedWithID_250K) {
TEST_F(SafeBrowsing, DISABLED_ReadIndexedWithID_250K) {
}
TEST_F(SafeBrowsing, ReadIndexedWithID_500K) {
TEST_F(SafeBrowsing, DISABLED_WriteIndexedWithID_500K) {
}
TEST_F(SafeBrowsing, WriteIndexedWithID_500K) {
TEST_F(SafeBrowsing, DISABLED_ReadIndexedWithID_500K) {
}
TEST_F(SafeBrowsing, CountIndexed_250K) {
TEST_F(SafeBrowsing, DISABLED_CountIndexed_250K) {
}
TEST_F(SafeBrowsing, CountIndexed_500K) {
TEST_F(SafeBrowsing, DISABLED_CountIndexed_500K) {
}
TEST_F(SafeBrowsing, CountIndexedWithID_250K) {
TEST_F(SafeBrowsing, DISABLED_CountIndexedWithID_250K) {
}
TEST_F(SafeBrowsing, CountIndexedWithID_500K) {
TEST_F(SafeBrowsing, DISABLED_CountIndexedWithID_500K) {
}
class SafeBrowsingDatabaseTest {
public:
SafeBrowsingDatabaseTest(const std::wstring& name) {
SafeBrowsingDatabaseTest(const FilePath& filename) {
logging::InitLogging(
NULL, logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
logging::LOCK_LOG_FILE,
logging::DELETE_OLD_LOG_FILE);
PathService::Get(base::DIR_TEMP, &filename_);
filename_.push_back(FilePath::kSeparators[0]);
filename_.append(name);
std::wstring tmp_path;
PathService::Get(base::DIR_TEMP, &tmp_path);
path_ = FilePath::FromWStringHack(tmp_path);
path_ = path_.Append(filename);
}
void Create(int size) {
DeleteFile(filename_.c_str());
file_util::Delete(path_, false);
SafeBrowsingDatabase database;
database.set_synchronous();
EXPECT_TRUE(database.Init(filename_));
scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
database->SetSynchronous();
EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
int chunk_id = 0;
int total_host_keys = size;
@@ -413,7 +414,8 @@ class SafeBrowsingDatabaseTest {
for (int j = 0; j < host_keys_per_chunk; ++j) {
SBChunkHost host;
rand_s((unsigned int*)&host.host);
host.host = base::RandInt(std::numeric_limits<int>::min(),
std::numeric_limits<int>::max());
host.entry = SBEntry::Create(SBEntry::ADD_PREFIX, 2);
host.entry->SetPrefixAt(0, 0x2425525);
host.entry->SetPrefixAt(1, 0x1536366);
@@ -422,32 +424,37 @@ class SafeBrowsingDatabaseTest {
}
}
database.InsertChunks("goog-malware", chunks);
database->InsertChunks("goog-malware", chunks);
}
void Read(bool use_bloom_filter) {
int keys_to_read = 500;
file_util::EvictFileFromSystemCache(filename_.c_str());
file_util::EvictFileFromSystemCache(path_);
SafeBrowsingDatabase database;
database.set_synchronous();
EXPECT_TRUE(database.Init(filename_));
scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
database->SetSynchronous();
EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
PerfTimer total_timer;
int64 db_ms = 0;
int keys_from_db = 0;
for (int i = 0; i < keys_to_read; ++i) {
int key;
rand_s((unsigned int*)&key);
int key = base::RandInt(std::numeric_limits<int>::min(),
std::numeric_limits<int>::max());
std::string url = StringPrintf("http://www.%d.com/blah.html", key);
std::string matching_list;
std::vector<SBPrefix> prefix_hits;
std::vector<SBFullHashResult> full_hits;
GURL gurl(url);
if (!use_bloom_filter || database.NeedToCheckUrl(gurl)) {
if (!use_bloom_filter || database->NeedToCheckUrl(gurl)) {
PerfTimer timer;
database.ContainsUrl(gurl, &matching_list, &prefix_hits);
database->ContainsUrl(gurl,
&matching_list,
&prefix_hits,
&full_hits,
base::Time::Now());
int64 time_ms = timer.Elapsed().InMilliseconds();
@@ -460,81 +467,80 @@ class SafeBrowsingDatabaseTest {
int64 total_ms = total_timer.Elapsed().InMilliseconds();
DLOG(INFO) << WideToASCII(file_util::GetFilenameFromPath(filename_)) <<
" read " << keys_to_read << " entries in " << total_ms << " ms. " <<
keys_from_db << " keys were read from the db, with average read taking " <<
DLOG(INFO) << path_.BaseName().value() << " read " << keys_to_read <<
" entries in " << total_ms << " ms. " << keys_from_db <<
" keys were read from the db, with average read taking " <<
db_ms / keys_from_db << " ms";
}
void BuildBloomFilter() {
file_util::EvictFileFromSystemCache(filename_.c_str());
file_util::Delete(SafeBrowsingDatabase::BloomFilterFilename(filename_), false);
file_util::EvictFileFromSystemCache(path_);
file_util::Delete(SafeBrowsingDatabase::BloomFilterFilename(
path_.ToWStringHack()), false);
PerfTimer total_timer;
SafeBrowsingDatabase database;
database.set_synchronous();
EXPECT_TRUE(database.Init(filename_));
scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
database->SetSynchronous();
EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
int64 total_ms = total_timer.Elapsed().InMilliseconds();
DLOG(INFO) << WideToASCII(file_util::GetFilenameFromPath(filename_)) <<
DLOG(INFO) << path_.BaseName().value() <<
" built bloom filter in " << total_ms << " ms.";
}
private:
std::wstring filename_;
FilePath path_;
};
// Adds 100K host records.
TEST(SafeBrowsingDatabase, FillUp100K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing100K");
TEST(SafeBrowsingDatabase, DISABLED_FillUp100K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing100K")));
db.Create(100000);
}
// Adds 250K host records.
TEST(SafeBrowsingDatabase, FillUp250K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
TEST(SafeBrowsingDatabase, DISABLED_FillUp250K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
db.Create(250000);
}
// Adds 500K host records.
TEST(SafeBrowsingDatabase, FillUp500K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
TEST(SafeBrowsingDatabase, DISABLED_FillUp500K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
db.Create(500000);
}
// Reads 500 entries and prints the timing.
TEST(SafeBrowsingDatabase, ReadFrom250K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
TEST(SafeBrowsingDatabase, DISABLED_ReadFrom250K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
db.Read(false);
}
TEST(SafeBrowsingDatabase, ReadFrom500K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
TEST(SafeBrowsingDatabase, DISABLED_ReadFrom500K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
db.Read(false);
}
// Read 500 entries with a bloom filter and print the timing.
TEST(SafeBrowsingDatabase, BloomReadFrom250K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
TEST(SafeBrowsingDatabase, DISABLED_BloomReadFrom250K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
db.Read(true);
}
TEST(SafeBrowsingDatabase, BloomReadFrom500K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
TEST(SafeBrowsingDatabase, DISABLED_BloomReadFrom500K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
db.Read(true);
}
// Test how long bloom filter creation takes.
TEST(SafeBrowsingDatabase, BuildBloomFilter250K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
TEST(SafeBrowsingDatabase, DISABLED_BuildBloomFilter250K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
db.BuildBloomFilter();
}
TEST(SafeBrowsingDatabase, BuildBloomFilter500K) {
SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
TEST(SafeBrowsingDatabase, DISABLED_BuildBloomFilter500K) {
SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
db.BuildBloomFilter();
}
#endif
@@ -89,6 +89,9 @@ class SafeBrowsingDatabase {
virtual std::wstring filename() const { return filename_; }
protected:
friend class SafeBrowsingDatabaseTest;
FRIEND_TEST(SafeBrowsingDatabase, HashCaching);
static std::wstring BloomFilterFilename(const std::wstring& db_filename);
// Load the bloom filter off disk, or generates one if it doesn't exist.
@@ -106,9 +109,6 @@ class SafeBrowsingDatabase {
// Measuring false positive rate. Call this each time we look in the filter.
virtual void IncrementBloomFilterReadCount() {}
// Full hash cache support.
FRIEND_TEST(SafeBrowsingDatabase, HashCaching);
typedef struct HashCacheEntry {
SBFullHash full_hash;
int list_id;
+3 -1
Ver Arquivo
@@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/perftimer.h"
#include "base/shared_memory.h"
@@ -143,7 +144,8 @@ TEST_F(VisitedLink, TestLoad) {
for (int i = 0; i < load_count; i++)
{
// make sure the file has to be re-loaded
file_util::EvictFileFromSystemCache(db_name_.c_str());
file_util::EvictFileFromSystemCache(
FilePath::FromWStringHack(std::wstring(db_name_)));
// cold load (no OS cache, hopefully)
{
-2
Ver Arquivo
@@ -93,7 +93,6 @@ if env['PLATFORM'] != 'win32':
'test/memory_test/memory_test.scons',
'test/mini_installer_test/mini_installer_test.scons',
'test/page_cycler/page_cycler_tests.scons',
'test/perf/perftests.scons',
'test/plugin/plugin_tests.scons',
'test/reliability/reliability_tests.scons',
'test/security_tests/security_tests.scons',
@@ -103,7 +102,6 @@ if env['PLATFORM'] != 'win32':
'test/ui/ui_tests.scons',
'tools/convert_dict/convert_dict.scons',
'tools/crash_service/crash_service.scons',
'tools/perf/flush_cache/flush_cache.scons',
'tools/profiles/generate_profile.scons',
]
sconscript_files = list(set(sconscript_files) - set(remove_files))
+7 -2
Ver Arquivo
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/debug_util.h"
#include "base/message_loop.h"
#include "base/perftimer.h"
#include "base/process_util.h"
@@ -11,7 +14,9 @@
// TODO(darin): share code with base/run_all_perftests.cc
int main(int argc, char **argv) {
base::AtExitManager exit_manager;
base::EnableTerminationOnHeapCorruption();
CommandLine::SetArgcArgv(argc, argv);
chrome::RegisterPathProvider();
MessageLoop main_message_loop;
@@ -43,8 +48,8 @@ int main(int argc, char **argv) {
// Raise to high priority to have more precise measurements. Since we don't
// aim at 1% precision, it is not necessary to run at realtime level.
if (!IsDebuggerPresent()) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
if (!DebugUtil::BeingDebugged()) {
base::RaiseProcessToHighPriority();
}
int result = RUN_ALL_TESTS();
+31 -37
Ver Arquivo
@@ -1,29 +1,22 @@
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
__doc__ = """
Configuration for building the perf_tests{,.exe} executable.
"""
Import('env')
env = env.Clone()
env.ApplySConscript([
'$BASE_DIR/gfx/using_base_gfx.scons',
'$BASE_DIR/using_base.scons',
'$BZIP2_DIR/using_bzip2.scons',
'$CHROME_DIR/third_party/hunspell/using_hunspell.scons',
'$NET_DIR/using_net.scons',
'$CHROME_SRC_DIR/build/using_googleurl.scons',
'$CHROME_SRC_DIR/build/using_v8.scons',
'$GTEST_DIR/../using_gtest.scons',
'$ICU38_DIR/using_icu38.scons',
'$LIBJPEG_DIR/using_libjpeg.scons',
'$LIBPNG_DIR/using_libpng.scons',
'$LIBXML_DIR/using_libxml.scons',
'$LIBXSLT_DIR/using_libxslt.scons',
'$MODP_B64_DIR/using_modp_b64.scons',
'$NET_DIR/using_net.scons',
'$SDCH_DIR/using_sdch.scons',
'$SKIA_DIR/using_skia.scons',
'$ZLIB_DIR/using_zlib.scons',
])
env.Prepend(
@@ -31,35 +24,16 @@ env.Prepend(
'PERF_TEST',
],
LIBS = [
'activex_shim',
'browser',
'browser_views',
'common',
'debugger',
'default_plugin',
'glue',
'JavaScriptCore_pcre',
'plugin',
'port',
'renderer',
'sqlite',
'util',
'v8_snapshot',
'V8Bindings',
'views',
'WebCore',
'WTF',
],
)
if env['PLATFORM'] == 'win32':
env.Prepend(
LIBS = [
'rpcrt4',
'shlwapi',
'winmm',
],
)
if env['PLATFORM'] in ('posix', 'darwin'):
env.SConscript([
'$LIBEVENT_DIR/using_libevent.scons',
], {'env':env})
input_files = [
'perftests.cc',
@@ -71,4 +45,24 @@ input_files = [
'$CHROME_DIR/common/json_value_serializer_perftest.cc',
]
env.ChromeTestProgram('perf_tests', input_files)
if env['PLATFORM'] == 'win32':
env.Prepend(
LIBS = [
'rpcrt4',
'shlwapi',
'winmm',
]
)
if env['PLATFORM'] != 'win32':
# TODO(port): Port these files.
remove_files = [
'url_parse_perftest.cc',
'$CHROME_DIR/browser/visitedlink_master$OBJSUFFIX',
'$CHROME_DIR/browser/visitedlink_perftest.cc',
]
for file in remove_files:
input_files.remove(file)
if env['PLATFORM'] in ('posix', 'win32'):
env.ChromeTestProgram('perf_tests', input_files)
+4 -2
Ver Arquivo
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This little program attempts to flush the disk cache for some files.
// This little program attempts to flush the system cache for some files.
// It's useful for testing Chrome with a cold database.
#include "base/file_path.h"
#include "base/string_piece.h"
#include "base/process_util.h"
#include "base/sys_string_conversions.h"
@@ -20,7 +21,8 @@ int main(int argc, const char* argv[]) {
for (int i = 1; i < argc; ++i) {
std::wstring filename = base::SysNativeMBToWide(argv[i]);
if (!file_util::EvictFileFromSystemCache(filename.c_str())) {
FilePath path = FilePath::FromWStringHack(filename);
if (!file_util::EvictFileFromSystemCache(path)) {
fprintf(stderr, "Failed to evict %s from cache -- is it a directory?\n",
argv[i]);
}
+18 -83
Ver Arquivo
@@ -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()));
FilePath path = FilePath::FromWStringHack(path_wstring);
filename = path;
file_util::AppendToPath(&filename, L"data_0");
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"))));
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()));
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);