Index: net/tools/dump_cache/dump_files.cc |
=================================================================== |
--- net/tools/dump_cache/dump_files.cc (revision 199883) |
+++ net/tools/dump_cache/dump_files.cc (working copy) |
@@ -24,12 +24,20 @@ |
#include "net/disk_cache/storage_block.h" |
#include "net/disk_cache/storage_block-inl.h" |
+namespace disk_cache { |
+typedef StorageBlock<EntryStore> CacheEntryBlock; |
+typedef StorageBlock<RankingsNode> CacheRankingsBlock; |
+} |
+ |
namespace { |
const base::FilePath::CharType kIndexName[] = FILE_PATH_LITERAL("index"); |
// Reads the |header_size| bytes from the beginning of file |name|. |
bool ReadHeader(const base::FilePath& name, char* header, int header_size) { |
+ if (name.value().back() == FILE_PATH_LITERAL('d')) |
+ return false; |
+ |
net::FileStream file(NULL); |
file.OpenSync(name, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
if (!file.IsOpen()) { |
@@ -54,12 +62,15 @@ |
} |
// Dumps the contents of the Stats record. |
-void DumpStats(const base::FilePath& path, disk_cache::CacheAddr addr) { |
+void DumpStats(const base::FilePath& path, disk_cache::CacheAddr addr, |
+ int version) { |
// We need a message loop, although we really don't run any task. |
MessageLoop loop(MessageLoop::TYPE_IO); |
disk_cache::BlockFiles block_files(path); |
- if (!block_files.Init(false)) { |
+ int num_files = (version == 2) ? disk_cache::kFirstAdditionalBlockFile : |
+ disk_cache::kFirstAdditionalBlockFileV3; |
+ if (!block_files.Init(false, num_files)) { |
printf("Unable to init block files\n"); |
return; |
} |
@@ -91,12 +102,12 @@ |
printf("-------------------------\n\n"); |
} |
-// Dumps the contents of the Index-file header. |
-void DumpIndexHeader(const base::FilePath& name, |
- disk_cache::CacheAddr* stats_addr) { |
+// Dumps the contents of the Index-file header. Returns the major version. |
+int DumpIndexHeader(const base::FilePath& name, |
+ disk_cache::CacheAddr* stats_addr) { |
disk_cache::IndexHeader header; |
if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header))) |
- return; |
+ return 0; |
printf("Index file:\n"); |
printf("magic: %x\n", header.magic); |
@@ -109,17 +120,23 @@ |
printf("last crash: %d\n", header.crash); |
printf("experiment: %d\n", header.experiment); |
printf("stats: %x\n", header.stats); |
- for (int i = 0; i < 5; i++) { |
- printf("head %d: 0x%x\n", i, header.lru.heads[i]); |
- printf("tail %d: 0x%x\n", i, header.lru.tails[i]); |
- printf("size %d: 0x%x\n", i, header.lru.sizes[i]); |
+ |
+ if (header.version >> 16 == 2) { |
+ for (int i = 0; i < 5; i++) { |
+ printf("head %d: 0x%x\n", i, header.lru.heads[i]); |
+ printf("tail %d: 0x%x\n", i, header.lru.tails[i]); |
+ printf("size %d: 0x%x\n", i, header.lru.sizes[i]); |
+ } |
+ printf("transaction: 0x%x\n", header.lru.transaction); |
+ printf("operation: %d\n", header.lru.operation); |
+ printf("operation list: %d\n", header.lru.operation_list); |
+ } else { |
+ DumpIndexHeaderPart2(&header); |
} |
- printf("transaction: 0x%x\n", header.lru.transaction); |
- printf("operation: %d\n", header.lru.operation); |
- printf("operation list: %d\n", header.lru.operation_list); |
printf("-------------------------\n\n"); |
*stats_addr = header.stats; |
+ return header.version >> 16; |
} |
// Dumps the contents of a block-file header. |
@@ -182,7 +199,7 @@ |
}; |
bool CacheDumper::Init() { |
- if (!block_files_.Init(false)) { |
+ if (!block_files_.Init(false, disk_cache::kFirstAdditionalBlockFile)) { |
printf("Unable to init block files\n"); |
return false; |
} |
@@ -337,7 +354,7 @@ |
int DumpHeaders(const base::FilePath& input_path) { |
base::FilePath index_name(input_path.Append(kIndexName)); |
disk_cache::CacheAddr stats_addr = 0; |
- DumpIndexHeader(index_name, &stats_addr); |
+ int version = DumpIndexHeader(index_name, &stats_addr); |
file_util::FileEnumerator iter(input_path, false, |
file_util::FileEnumerator::FILES, |
@@ -345,12 +362,12 @@ |
for (base::FilePath file = iter.Next(); !file.empty(); file = iter.Next()) |
DumpBlockHeader(file); |
- DumpStats(input_path, stats_addr); |
+ DumpStats(input_path, stats_addr, version); |
return 0; |
} |
// Dumps all entries from the cache. |
-int DumpContents(const base::FilePath& input_path) { |
+int DumpContentsV2(const base::FilePath& input_path) { |
DumpHeaders(input_path); |
// We need a message loop, although we really don't run any task. |