Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / tools / perf / clear_system_cache / clear_system_cache_main.cc
blob7b26055c90250c08e53d4e607b7783c97f5f4e96
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // A utility to clear the operating system's cache for a file or directory.
6 //
7 // USAGE: clear_system_cache [--recurse] <files or directories>
9 #include <stdio.h>
11 #include "base/basictypes.h"
12 #include "base/command_line.h"
13 #include "base/files/file_enumerator.h"
14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h"
16 #include "base/logging.h"
17 #include "base/test/test_file_util.h"
19 void ClearCacheForFile(const base::FilePath& path) {
20 VLOG(1) << "Clearing " << path.MaybeAsASCII();
21 base::EvictFileFromSystemCache(path);
24 int main(int argc, const char* argv[]) {
25 base::CommandLine::Init(argc, argv);
26 const base::CommandLine& parsed_command_line =
27 *base::CommandLine::ForCurrentProcess();
28 bool should_recurse = parsed_command_line.HasSwitch("recurse");
29 const base::CommandLine::StringVector& args = parsed_command_line.GetArgs();
31 if (args.size() < 1) {
32 printf("USAGE: %s [--recurse] <files or directories>\n", argv[0]);
33 return 1;
36 for (size_t i = 0; i < args.size(); ++i) {
37 base::FilePath path(args[i]);
38 if (!base::PathExists(path)) {
39 LOG(ERROR) << "Couldn't find " << path.MaybeAsASCII();
40 return 1;
43 if (base::DirectoryExists(path)) {
44 base::FileEnumerator enumerator(path, should_recurse,
45 base::FileEnumerator::FILES);
46 for (base::FilePath next = enumerator.Next(); !next.empty();
47 next = enumerator.Next()) {
48 ClearCacheForFile(next);
50 } else {
51 ClearCacheForFile(path);
55 return 0;