OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Performs basic inspection of the disk cache files with minimal disruption | 5 // Performs basic inspection of the disk cache files with minimal disruption |
6 // to the actual files (they still may change if an error is detected on the | 6 // to the actual files (they still may change if an error is detected on the |
7 // files). | 7 // files). |
8 | 8 |
9 #include "net/tools/dump_cache/dump_files.h" | 9 #include "net/tools/dump_cache/dump_files.h" |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 scoped_ptr<int32[]> buffer(new int32[length]); | 78 scoped_ptr<int32[]> buffer(new int32[length]); |
79 if (!file->Read(buffer.get(), length, offset)) | 79 if (!file->Read(buffer.get(), length, offset)) |
80 return; | 80 return; |
81 | 81 |
82 printf("Stats:\nSignatrure: 0x%x\n", buffer[0]); | 82 printf("Stats:\nSignatrure: 0x%x\n", buffer[0]); |
83 printf("Total size: %d\n", buffer[1]); | 83 printf("Total size: %d\n", buffer[1]); |
84 for (int i = 0; i < disk_cache::Stats::kDataSizesLength; i++) | 84 for (int i = 0; i < disk_cache::Stats::kDataSizesLength; i++) |
85 printf("Size(%d): %d\n", i, buffer[i + 2]); | 85 printf("Size(%d): %d\n", i, buffer[i + 2]); |
86 | 86 |
87 int64* counters = reinterpret_cast<int64*>( | 87 int64* counters = reinterpret_cast<int64*>( |
88 buffer.get() + 2 + disk_cache::Stats::kDataSizesLength); | 88 buffer.get() + 2 + disk_cache::Stats::kDataSizesLength); |
89 for (int i = 0; i < disk_cache::Stats::MAX_COUNTER; i++) | 89 for (int i = 0; i < disk_cache::Stats::MAX_COUNTER; i++) |
90 printf("Count(%d): %" PRId64 "\n", i, *counters++); | 90 printf("Count(%d): %" PRId64 "\n", i, *counters++); |
91 printf("-------------------------\n\n"); | 91 printf("-------------------------\n\n"); |
92 } | 92 } |
93 | 93 |
94 // Dumps the contents of the Index-file header. | 94 // Dumps the contents of the Index-file header. |
95 void DumpIndexHeader(const base::FilePath& name, | 95 void DumpIndexHeader(const base::FilePath& name, |
96 disk_cache::CacheAddr* stats_addr) { | 96 disk_cache::CacheAddr* stats_addr) { |
97 disk_cache::IndexHeader header; | 97 disk_cache::IndexHeader header; |
98 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header))) | 98 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header))) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 149 } |
150 | 150 |
151 // Simple class that interacts with the set of cache files. | 151 // Simple class that interacts with the set of cache files. |
152 class CacheDumper { | 152 class CacheDumper { |
153 public: | 153 public: |
154 explicit CacheDumper(const base::FilePath& path) | 154 explicit CacheDumper(const base::FilePath& path) |
155 : path_(path), | 155 : path_(path), |
156 block_files_(path), | 156 block_files_(path), |
157 index_(NULL), | 157 index_(NULL), |
158 current_hash_(0), | 158 current_hash_(0), |
159 next_addr_(0) { | 159 next_addr_(0) {} |
160 } | |
161 | 160 |
162 bool Init(); | 161 bool Init(); |
163 | 162 |
164 // Reads an entry from disk. Return false when all entries have been already | 163 // Reads an entry from disk. Return false when all entries have been already |
165 // returned. | 164 // returned. |
166 bool GetEntry(disk_cache::EntryStore* entry); | 165 bool GetEntry(disk_cache::EntryStore* entry); |
167 | 166 |
168 // Loads a specific block from the block files. | 167 // Loads a specific block from the block files. |
169 bool LoadEntry(disk_cache::CacheAddr addr, disk_cache::EntryStore* entry); | 168 bool LoadEntry(disk_cache::CacheAddr addr, disk_cache::EntryStore* entry); |
170 bool LoadRankings(disk_cache::CacheAddr addr, | 169 bool LoadRankings(disk_cache::CacheAddr addr, |
(...skipping 11 matching lines...) Expand all Loading... |
182 }; | 181 }; |
183 | 182 |
184 bool CacheDumper::Init() { | 183 bool CacheDumper::Init() { |
185 if (!block_files_.Init(false)) { | 184 if (!block_files_.Init(false)) { |
186 printf("Unable to init block files\n"); | 185 printf("Unable to init block files\n"); |
187 return false; | 186 return false; |
188 } | 187 } |
189 | 188 |
190 base::FilePath index_name(path_.Append(kIndexName)); | 189 base::FilePath index_name(path_.Append(kIndexName)); |
191 index_file_ = new disk_cache::MappedFile; | 190 index_file_ = new disk_cache::MappedFile; |
192 index_ = reinterpret_cast<disk_cache::Index*>( | 191 index_ = |
193 index_file_->Init(index_name, 0)); | 192 reinterpret_cast<disk_cache::Index*>(index_file_->Init(index_name, 0)); |
194 if (!index_) { | 193 if (!index_) { |
195 printf("Unable to map index\n"); | 194 printf("Unable to map index\n"); |
196 return false; | 195 return false; |
197 } | 196 } |
198 | 197 |
199 return true; | 198 return true; |
200 } | 199 } |
201 | 200 |
202 bool CacheDumper::GetEntry(disk_cache::EntryStore* entry) { | 201 bool CacheDumper::GetEntry(disk_cache::EntryStore* entry) { |
203 if (dumped_entries_.find(next_addr_) != dumped_entries_.end()) { | 202 if (dumped_entries_.find(next_addr_) != dumped_entries_.end()) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 331 |
333 return version; | 332 return version; |
334 } | 333 } |
335 | 334 |
336 // Dumps the headers of all files. | 335 // Dumps the headers of all files. |
337 int DumpHeaders(const base::FilePath& input_path) { | 336 int DumpHeaders(const base::FilePath& input_path) { |
338 base::FilePath index_name(input_path.Append(kIndexName)); | 337 base::FilePath index_name(input_path.Append(kIndexName)); |
339 disk_cache::CacheAddr stats_addr = 0; | 338 disk_cache::CacheAddr stats_addr = 0; |
340 DumpIndexHeader(index_name, &stats_addr); | 339 DumpIndexHeader(index_name, &stats_addr); |
341 | 340 |
342 base::FileEnumerator iter(input_path, false, | 341 base::FileEnumerator iter(input_path, |
| 342 false, |
343 base::FileEnumerator::FILES, | 343 base::FileEnumerator::FILES, |
344 FILE_PATH_LITERAL("data_*")); | 344 FILE_PATH_LITERAL("data_*")); |
345 for (base::FilePath file = iter.Next(); !file.empty(); file = iter.Next()) | 345 for (base::FilePath file = iter.Next(); !file.empty(); file = iter.Next()) |
346 DumpBlockHeader(file); | 346 DumpBlockHeader(file); |
347 | 347 |
348 DumpStats(input_path, stats_addr); | 348 DumpStats(input_path, stats_addr); |
349 return 0; | 349 return 0; |
350 } | 350 } |
351 | 351 |
352 // Dumps all entries from the cache. | 352 // Dumps all entries from the cache. |
(...skipping 11 matching lines...) Expand all Loading... |
364 DumpEntry(entry); | 364 DumpEntry(entry); |
365 disk_cache::RankingsNode rankings; | 365 disk_cache::RankingsNode rankings; |
366 if (dumper.LoadRankings(entry.rankings_node, &rankings)) | 366 if (dumper.LoadRankings(entry.rankings_node, &rankings)) |
367 DumpRankings(rankings); | 367 DumpRankings(rankings); |
368 } | 368 } |
369 | 369 |
370 printf("Done.\n"); | 370 printf("Done.\n"); |
371 | 371 |
372 return 0; | 372 return 0; |
373 } | 373 } |
OLD | NEW |