diff options
author | simonjam@chromium.org <simonjam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 17:05:44 +0000 |
---|---|---|
committer | simonjam@chromium.org <simonjam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 17:05:44 +0000 |
commit | 02d8fd6784371a691ec48c15b0abd8e0235533d3 (patch) | |
tree | 146cc148497fa5b9efdb2e2275ff2a934cacbc64 /tools | |
parent | c371abb6456360e99689c16861b0a019170179a8 (diff) | |
download | chromium_src-02d8fd6784371a691ec48c15b0abd8e0235533d3.zip chromium_src-02d8fd6784371a691ec48c15b0abd8e0235533d3.tar.gz chromium_src-02d8fd6784371a691ec48c15b0abd8e0235533d3.tar.bz2 |
Add a tool for clearing the system cache for a directory.
This is a wrapper around existing functionality in
base/test/test_file_util.h.
This will be used in the cold startup Telemetry tests.
BUG=None
Review URL: https://chromiumcodereview.appspot.com/20399002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213941 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/clear_system_cache/clear_system_cache.gyp | 23 | ||||
-rw-r--r-- | tools/perf/clear_system_cache/clear_system_cache_main.cc | 55 |
2 files changed, 78 insertions, 0 deletions
diff --git a/tools/perf/clear_system_cache/clear_system_cache.gyp b/tools/perf/clear_system_cache/clear_system_cache.gyp new file mode 100644 index 0000000..cf6299a --- /dev/null +++ b/tools/perf/clear_system_cache/clear_system_cache.gyp @@ -0,0 +1,23 @@ +# Copyright 2013 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. + +{ + 'variables': { + 'chromium_code': 1, + }, + 'targets' : [ + { + 'target_name': 'clear_system_cache', + 'type': 'executable', + 'toolsets': ['target'], + 'dependencies': [ + '../../../base/base.gyp:base', + '../../../base/base.gyp:test_support_base', + ], + 'sources': [ + 'clear_system_cache_main.cc', + ], + }, + ], +} diff --git a/tools/perf/clear_system_cache/clear_system_cache_main.cc b/tools/perf/clear_system_cache/clear_system_cache_main.cc new file mode 100644 index 0000000..9f48c61 --- /dev/null +++ b/tools/perf/clear_system_cache/clear_system_cache_main.cc @@ -0,0 +1,55 @@ +// Copyright 2013 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. + +// A utility to clear the operating system's cache for a file or directory. +// +// USAGE: clear_system_cache [--recurse] <files or directories> + +#include <stdio.h> + +#include "base/basictypes.h" +#include "base/command_line.h" +#include "base/file_util.h" +#include "base/files/file_enumerator.h" +#include "base/files/file_path.h" +#include "base/logging.h" +#include "base/test/test_file_util.h" + +void ClearCacheForFile(const base::FilePath& path) { + VLOG(1) << "Clearing " << path.MaybeAsASCII(); + file_util::EvictFileFromSystemCache(path); +} + +int main(int argc, const char* argv[]) { + CommandLine::Init(argc, argv); + const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); + bool should_recurse = parsed_command_line.HasSwitch("recurse"); + const CommandLine::StringVector& args = parsed_command_line.GetArgs(); + + if (args.size() < 1) { + printf("USAGE: %s [--recurse] <files or directories>\n", argv[0]); + return 1; + } + + for (size_t i = 0; i < args.size(); ++i) { + base::FilePath path(args[i]); + if (!base::PathExists(path)) { + LOG(ERROR) << "Couldn't find " << path.MaybeAsASCII(); + return 1; + } + + if (base::DirectoryExists(path)) { + base::FileEnumerator enumerator(path, should_recurse, + base::FileEnumerator::FILES); + for (base::FilePath next = enumerator.Next(); !next.empty(); + next = enumerator.Next()) { + ClearCacheForFile(next); + } + } else { + ClearCacheForFile(path); + } + } + + return 0; +} |