Chromium Code Reviews| Index: net/disk_cache/block_files.cc |
| =================================================================== |
| --- net/disk_cache/block_files.cc (revision 52189) |
| +++ net/disk_cache/block_files.cc (working copy) |
| @@ -172,8 +172,8 @@ |
| if (init_) |
| return false; |
| - block_files_.resize(kFirstAdditionlBlockFile); |
| - for (int i = 0; i < kFirstAdditionlBlockFile; i++) { |
| + block_files_.resize(kFirstAdditionalBlockFile); |
| + for (int i = 0; i < kFirstAdditionalBlockFile; i++) { |
| if (create_files) |
| if (!CreateBlockFile(i, static_cast<FileType>(i + 1), true)) |
| return false; |
| @@ -200,11 +200,21 @@ |
| block_files_.clear(); |
| } |
| -FilePath BlockFiles::Name(int index) { |
| - // The file format allows for 256 files. |
| - DCHECK(index < 256 || index >= 0); |
| - std::string tmp = StringPrintf("%s%d", kBlockName, index); |
| - return path_.AppendASCII(tmp); |
| +void BlockFiles::ReportStats() { |
| + int used_blocks[kFirstAdditionalBlockFile]; |
| + int load[kFirstAdditionalBlockFile]; |
| + for (int i = 0; i < kFirstAdditionalBlockFile; i++) { |
| + GetFileStats(i, &used_blocks[i], &load[i]); |
| + } |
| + UMA_HISTOGRAM_COUNTS("Blocks_0", used_blocks[0]); |
| + UMA_HISTOGRAM_COUNTS("Blocks_1", used_blocks[1]); |
| + UMA_HISTOGRAM_COUNTS("Blocks_2", used_blocks[2]); |
| + UMA_HISTOGRAM_COUNTS("Blocks_3", used_blocks[3]); |
| + |
| + UMA_HISTOGRAM_ENUMERATION("BlockLoad_0", load[0], 101); |
| + UMA_HISTOGRAM_ENUMERATION("BlockLoad_1", load[1], 101); |
| + UMA_HISTOGRAM_ENUMERATION("BlockLoad_2", load[2], 101); |
| + UMA_HISTOGRAM_ENUMERATION("BlockLoad_3", load[3], 101); |
| } |
| bool BlockFiles::CreateBlockFile(int index, FileType file_type, bool force) { |
| @@ -241,7 +251,8 @@ |
| return false; |
| } |
| - if (file->GetLength() < static_cast<size_t>(kBlockHeaderSize)) { |
| + size_t file_len = file->GetLength(); |
|
gavinp
2010/07/15 15:03:48
nit: const
rvargas (doing something else)
2010/07/15 18:31:50
What do you mean?
if you mean const size_t file_l
|
| + if (file_len < static_cast<size_t>(kBlockHeaderSize)) { |
| LOG(ERROR) << "File too small " << name.value(); |
| return false; |
| } |
| @@ -258,6 +269,13 @@ |
| return false; |
| } |
| + if (index == 0) { |
| + // Load the links file into memory with a single read. |
| + scoped_array<char> buf(new char[file_len]); |
| + if (!file->Read(buf.get(), file_len, 0)) |
| + return false; |
| + } |
| + |
| DCHECK(!block_files_[index]); |
| file.swap(&block_files_[index]); |
| return true; |
| @@ -356,7 +374,7 @@ |
| } |
| int BlockFiles::CreateNextBlockFile(FileType block_type) { |
| - for (int i = kFirstAdditionlBlockFile; i <= kMaxBlockFile; i++) { |
| + for (int i = kFirstAdditionalBlockFile; i <= kMaxBlockFile; i++) { |
| if (CreateBlockFile(i, block_type, false)) |
| return i; |
| } |
| @@ -485,4 +503,42 @@ |
| return true; |
| } |
| +// We are interested in the total number of block used by this file type, and |
| +// the max number of blocks that we can store (reported as the percentage of |
| +// used blocks). In order to find out the number of used blocks, we have to |
| +// substract the empty blocks from the total blocks for each file in the chain. |
| +void BlockFiles::GetFileStats(int index, int* used_count, int* load) { |
| + int max_blocks = 0; |
| + *used_count = 0; |
| + *load = 0; |
| + for (;;) { |
| + if (!block_files_[index] && !OpenBlockFile(index)) |
| + return; |
| + |
| + BlockFileHeader* header = |
| + reinterpret_cast<BlockFileHeader*>(block_files_[index]->buffer()); |
| + |
| + max_blocks += header->max_entries; |
| + int used = header->max_entries; |
| + for (int i = 0; i < 4; i++) { |
| + used -= header->empty[i] * (i + 1); |
|
nsylvain
2010/07/15 05:47:04
What does header->empty[i] contain? This looks a l
rvargas (doing something else)
2010/07/15 18:31:50
empty is an array of 4 slots that keeps the number
|
| + DCHECK_GE(used, 0); |
| + } |
| + *used_count += used; |
| + |
| + if (!header->next_file) |
| + break; |
| + index = header->next_file; |
| + } |
| + if (max_blocks) |
| + *load = *used_count * 100 / max_blocks; |
| +} |
| + |
| +FilePath BlockFiles::Name(int index) { |
| + // The file format allows for 256 files. |
| + DCHECK(index < 256 || index >= 0); |
| + std::string tmp = StringPrintf("%s%d", kBlockName, index); |
| + return path_.AppendASCII(tmp); |
| +} |
| + |
| } // namespace disk_cache |