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 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/files/file.h" | 17 #include "base/files/file.h" |
18 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
20 #include "base/format_macros.h" | 20 #include "base/format_macros.h" |
| 21 #include "base/macros.h" |
21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "net/disk_cache/blockfile/block_files.h" | 25 #include "net/disk_cache/blockfile/block_files.h" |
25 #include "net/disk_cache/blockfile/disk_format.h" | 26 #include "net/disk_cache/blockfile/disk_format.h" |
26 #include "net/disk_cache/blockfile/mapped_file.h" | 27 #include "net/disk_cache/blockfile/mapped_file.h" |
27 #include "net/disk_cache/blockfile/stats.h" | 28 #include "net/disk_cache/blockfile/stats.h" |
28 #include "net/disk_cache/blockfile/storage_block-inl.h" | 29 #include "net/disk_cache/blockfile/storage_block-inl.h" |
29 #include "net/disk_cache/blockfile/storage_block.h" | 30 #include "net/disk_cache/blockfile/storage_block.h" |
30 #include "net/url_request/view_cache_helper.h" | 31 #include "net/url_request/view_cache_helper.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if (!block_files.Init(false)) { | 67 if (!block_files.Init(false)) { |
67 printf("Unable to init block files\n"); | 68 printf("Unable to init block files\n"); |
68 return; | 69 return; |
69 } | 70 } |
70 | 71 |
71 disk_cache::Addr address(addr); | 72 disk_cache::Addr address(addr); |
72 disk_cache::MappedFile* file = block_files.GetFile(address); | 73 disk_cache::MappedFile* file = block_files.GetFile(address); |
73 if (!file) | 74 if (!file) |
74 return; | 75 return; |
75 | 76 |
76 size_t length = (2 + disk_cache::Stats::kDataSizesLength) * sizeof(int32) + | 77 size_t length = (2 + disk_cache::Stats::kDataSizesLength) * sizeof(int32_t) + |
77 disk_cache::Stats::MAX_COUNTER * sizeof(int64); | 78 disk_cache::Stats::MAX_COUNTER * sizeof(int64_t); |
78 | 79 |
79 size_t offset = address.start_block() * address.BlockSize() + | 80 size_t offset = address.start_block() * address.BlockSize() + |
80 disk_cache::kBlockHeaderSize; | 81 disk_cache::kBlockHeaderSize; |
81 | 82 |
82 scoped_ptr<int32[]> buffer(new int32[length]); | 83 scoped_ptr<int32_t[]> buffer(new int32_t[length]); |
83 if (!file->Read(buffer.get(), length, offset)) | 84 if (!file->Read(buffer.get(), length, offset)) |
84 return; | 85 return; |
85 | 86 |
86 printf("Stats:\nSignatrure: 0x%x\n", buffer[0]); | 87 printf("Stats:\nSignatrure: 0x%x\n", buffer[0]); |
87 printf("Total size: %d\n", buffer[1]); | 88 printf("Total size: %d\n", buffer[1]); |
88 for (int i = 0; i < disk_cache::Stats::kDataSizesLength; i++) | 89 for (int i = 0; i < disk_cache::Stats::kDataSizesLength; i++) |
89 printf("Size(%d): %d\n", i, buffer[i + 2]); | 90 printf("Size(%d): %d\n", i, buffer[i + 2]); |
90 | 91 |
91 int64* counters = reinterpret_cast<int64*>( | 92 int64_t* counters = reinterpret_cast<int64_t*>( |
92 buffer.get() + 2 + disk_cache::Stats::kDataSizesLength); | 93 buffer.get() + 2 + disk_cache::Stats::kDataSizesLength); |
93 for (int i = 0; i < disk_cache::Stats::MAX_COUNTER; i++) | 94 for (int i = 0; i < disk_cache::Stats::MAX_COUNTER; i++) |
94 printf("Count(%d): %" PRId64 "\n", i, *counters++); | 95 printf("Count(%d): %" PRId64 "\n", i, *counters++); |
95 printf("-------------------------\n\n"); | 96 printf("-------------------------\n\n"); |
96 } | 97 } |
97 | 98 |
98 // Dumps the contents of the Index-file header. | 99 // Dumps the contents of the Index-file header. |
99 void DumpIndexHeader(const base::FilePath& name, | 100 void DumpIndexHeader(const base::FilePath& name, |
100 disk_cache::CacheAddr* stats_addr) { | 101 disk_cache::CacheAddr* stats_addr) { |
101 disk_cache::IndexHeader header; | 102 disk_cache::IndexHeader header; |
102 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header))) | 103 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header))) |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 size_t offset = address.start_block() * address.BlockSize() + | 300 size_t offset = address.start_block() * address.BlockSize() + |
300 disk_cache::kBlockHeaderSize; | 301 disk_cache::kBlockHeaderSize; |
301 if (!file->Read(buffer.get(), size, offset)) | 302 if (!file->Read(buffer.get(), size, offset)) |
302 return false; | 303 return false; |
303 | 304 |
304 base::StringAppendF(out, "0x%x:\n", addr); | 305 base::StringAppendF(out, "0x%x:\n", addr); |
305 net::ViewCacheHelper::HexDump(buffer.get(), size, out); | 306 net::ViewCacheHelper::HexDump(buffer.get(), size, out); |
306 return true; | 307 return true; |
307 } | 308 } |
308 | 309 |
309 std::string ToLocalTime(int64 time_us) { | 310 std::string ToLocalTime(int64_t time_us) { |
310 base::Time time = base::Time::FromInternalValue(time_us); | 311 base::Time time = base::Time::FromInternalValue(time_us); |
311 base::Time::Exploded e; | 312 base::Time::Exploded e; |
312 time.LocalExplode(&e); | 313 time.LocalExplode(&e); |
313 return base::StringPrintf("%d/%d/%d %d:%d:%d.%d", e.year, e.month, | 314 return base::StringPrintf("%d/%d/%d %d:%d:%d.%d", e.year, e.month, |
314 e.day_of_month, e.hour, e.minute, e.second, | 315 e.day_of_month, e.hour, e.minute, e.second, |
315 e.millisecond); | 316 e.millisecond); |
316 } | 317 } |
317 | 318 |
318 void DumpEntry(disk_cache::CacheAddr addr, | 319 void DumpEntry(disk_cache::CacheAddr addr, |
319 const disk_cache::EntryStore& entry, | 320 const disk_cache::EntryStore& entry, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // We need a message loop, although we really don't run any task. | 484 // We need a message loop, although we really don't run any task. |
484 base::MessageLoopForIO loop; | 485 base::MessageLoopForIO loop; |
485 CacheDumper dumper(input_path); | 486 CacheDumper dumper(input_path); |
486 if (!dumper.Init()) | 487 if (!dumper.Init()) |
487 return -1; | 488 return -1; |
488 | 489 |
489 printf("list, addr, next, prev, entry\n"); | 490 printf("list, addr, next, prev, entry\n"); |
490 | 491 |
491 const int kMaxLength = 1 * 1000 * 1000; | 492 const int kMaxLength = 1 * 1000 * 1000; |
492 for (int i = 0; i < 5; i++) { | 493 for (int i = 0; i < 5; i++) { |
493 int32 size = header.lru.sizes[i]; | 494 int32_t size = header.lru.sizes[i]; |
494 if (size < 0 || size > kMaxLength) { | 495 if (size < 0 || size > kMaxLength) { |
495 printf("Wrong size %d\n", size); | 496 printf("Wrong size %d\n", size); |
496 size = kMaxLength; | 497 size = kMaxLength; |
497 } | 498 } |
498 | 499 |
499 disk_cache::CacheAddr addr = header.lru.tails[i]; | 500 disk_cache::CacheAddr addr = header.lru.tails[i]; |
500 int count = 0; | 501 int count = 0; |
501 for (; size && addr; size--) { | 502 for (; size && addr; size--) { |
502 count++; | 503 count++; |
503 disk_cache::RankingsNode rankings; | 504 disk_cache::RankingsNode rankings; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 disk_cache::BlockFileHeader header; | 590 disk_cache::BlockFileHeader header; |
590 if (!ReadHeader(file, reinterpret_cast<char*>(&header), sizeof(header))) | 591 if (!ReadHeader(file, reinterpret_cast<char*>(&header), sizeof(header))) |
591 return -1; | 592 return -1; |
592 | 593 |
593 std::string out; | 594 std::string out; |
594 net::ViewCacheHelper::HexDump(reinterpret_cast<char*>(&header.allocation_map), | 595 net::ViewCacheHelper::HexDump(reinterpret_cast<char*>(&header.allocation_map), |
595 sizeof(header.allocation_map), &out); | 596 sizeof(header.allocation_map), &out); |
596 printf("%s\n", out.c_str()); | 597 printf("%s\n", out.c_str()); |
597 return 0; | 598 return 0; |
598 } | 599 } |
OLD | NEW |