summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 22:53:43 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 22:53:43 +0000
commita04876b90cb1e55881844ff22a74e06bf4641071 (patch)
tree2188de20f7b57b371c045232e1b888bc676afaf6 /base
parent88fdf6604b4136a8d914703a10869951f846d3c1 (diff)
downloadchromium_src-a04876b90cb1e55881844ff22a74e06bf4641071.zip
chromium_src-a04876b90cb1e55881844ff22a74e06bf4641071.tar.gz
chromium_src-a04876b90cb1e55881844ff22a74e06bf4641071.tar.bz2
Add histograms to track the size of the profile data.
BUG=16705 TEST=FileUtilTest.FileAndDirectorySize Review URL: http://codereview.chromium.org/2778006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_util.cc18
-rw-r--r--base/file_util.h9
-rw-r--r--base/file_util_unittest.cc6
3 files changed, 33 insertions, 0 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index b24ffde..5ce4456 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -268,6 +268,24 @@ int64 ComputeDirectorySize(const FilePath& root_path) {
return running_size;
}
+int64 ComputeFilesSize(const FilePath& directory,
+ const FilePath::StringType& pattern) {
+ int64 running_size = 0;
+ FileEnumerator file_iter(directory, false, FileEnumerator::FILES, pattern);
+ for (FilePath current = file_iter.Next(); !current.empty();
+ current = file_iter.Next()) {
+ FileEnumerator::FindInfo info;
+ file_iter.GetFindInfo(&info);
+#if defined(OS_WIN)
+ LARGE_INTEGER li = { info.nFileSizeLow, info.nFileSizeHigh };
+ running_size += li.QuadPart;
+#else
+ running_size += info.stat.st_size;
+#endif
+ }
+ return running_size;
+}
+
///////////////////////////////////////////////
// MemoryMappedFile
diff --git a/base/file_util.h b/base/file_util.h
index 04afdec..b2e176b 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -82,6 +82,15 @@ int CountFilesCreatedAfter(const FilePath& path,
// particularly speedy in any platform.
int64 ComputeDirectorySize(const FilePath& root_path);
+// Returns the total number of bytes used by all files matching the provided
+// |pattern|, on this |directory| (without recursion). If the path does not
+// exist the function returns 0.
+//
+// This function is implemented using the FileEnumerator class so it is not
+// particularly speedy in any platform.
+int64 ComputeFilesSize(const FilePath& directory,
+ const FilePath::StringType& pattern);
+
// Deletes the given path, whether it's a file or a directory.
// If it's a directory, it's perfectly happy to delete all of the
// directory's contents. Passing true to recursive deletes
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 219b63d..39e5398 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -463,6 +463,12 @@ TEST_F(FileUtilTest, FileAndDirectorySize) {
int64 computed_size = file_util::ComputeDirectorySize(test_dir_);
EXPECT_EQ(size_f1 + size_f2 + 3, computed_size);
+
+ computed_size = file_util::ComputeFilesSize(test_dir_, FPL("The file*"));
+ EXPECT_EQ(size_f1, computed_size);
+
+ computed_size = file_util::ComputeFilesSize(test_dir_, FPL("bla*"));
+ EXPECT_EQ(0, computed_size);
}
TEST_F(FileUtilTest, NormalizeFilePathBasic) {