Skip to content

Commit

Permalink
Add histograms to track the size of the profile data.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rvargas@google.com committed Jun 11, 2010
1 parent 88fdf66 commit a04876b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
18 changes: 18 additions & 0 deletions base/file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions base/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions base/file_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
63 changes: 58 additions & 5 deletions chrome/browser/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,56 @@ bool IncludeDefaultApps() {
#endif
return false;
}

// Simple task to log the size of the current profile.
class ProfileSizeTask : public Task {
public:
explicit ProfileSizeTask(const FilePath& path) : path_(path) {}
virtual ~ProfileSizeTask() {}

virtual void Run();
private:
FilePath path_;
};

void ProfileSizeTask::Run() {
int64 size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("*"));
int size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.TotalSize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.HistorySize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("History*"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.TotalHistorySize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Cookies"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.CookiesSize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Bookmarks"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.BookmarksSize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Thumbnails"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.ThumbnailsSize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Visited Links"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.VisitedLinksSize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Web Data"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.WebDataSize", size_MB);

size = file_util::ComputeFilesSize(path_, FILE_PATH_LITERAL("Extension*"));
size_MB = static_cast<int>(size / (1024 * 1024));
UMA_HISTOGRAM_COUNTS_10000("Profile.ExtensionSize", size_MB);
}

} // namespace

// A pointer to the request context for the default profile. See comments on
Expand Down Expand Up @@ -262,11 +312,10 @@ class OffTheRecordProfileImpl : public Profile,
}

virtual ~OffTheRecordProfileImpl() {
NotificationService::current()->Notify(
NotificationType::PROFILE_DESTROYED,
Source<Profile>(this),
NotificationService::NoDetails());
CleanupRequestContext(request_context_);
NotificationService::current()->Notify(NotificationType::PROFILE_DESTROYED,
Source<Profile>(this),
NotificationService::NoDetails());
CleanupRequestContext(request_context_);
}

virtual ProfileId GetRuntimeId() {
Expand Down Expand Up @@ -749,6 +798,10 @@ ProfileImpl::ProfileImpl(const FilePath& path)
#endif

pinned_tab_service_.reset(new PinnedTabService(this));

// Log the profile size after a reasonable startup delay.
ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE,
new ProfileSizeTask(path_), 112000);
}

void ProfileImpl::InitExtensions() {
Expand Down

0 comments on commit a04876b

Please sign in to comment.