Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: tools/perf/clear_system_cache/clear_system_cache_main.cc

Issue 20399002: Add a tool for clearing the system cache for a directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/perf/clear_system_cache/clear_system_cache.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/clear_system_cache/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 0000000000000000000000000000000000000000..e3b78799977cbea1ee58397ef018d748444a9322
--- /dev/null
+++ b/tools/perf/clear_system_cache/clear_system_cache_main.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 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;
+}
« no previous file with comments | « tools/perf/clear_system_cache/clear_system_cache.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698