summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 19:11:17 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 19:11:17 +0000
commitb7e1aab1f34b1082db8613892889d9753d8af356 (patch)
tree5ec06035f89ab6f73eee729d167c1664273fe85d /net/tools
parent3eaa821c9f557f0b7f9bdb635a8d66f16147c50d (diff)
downloadchromium_src-b7e1aab1f34b1082db8613892889d9753d8af356.zip
chromium_src-b7e1aab1f34b1082db8613892889d9753d8af356.tar.gz
chromium_src-b7e1aab1f34b1082db8613892889d9753d8af356.tar.bz2
Disk cache: Update the dump_cache tool to show the Stats record.
BUG=none TEST=none TBR=gavinp@chromium.org original review https://codereview.chromium.org/11888014 Review URL: https://codereview.chromium.org/12021026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178343 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r--net/tools/dump_cache/dump_files.cc50
1 files changed, 48 insertions, 2 deletions
diff --git a/net/tools/dump_cache/dump_files.cc b/net/tools/dump_cache/dump_files.cc
index 3ce890a..f181e7a 100644
--- a/net/tools/dump_cache/dump_files.cc
+++ b/net/tools/dump_cache/dump_files.cc
@@ -14,11 +14,13 @@
#include <string>
#include "base/file_util.h"
+#include "base/format_macros.h"
#include "base/message_loop.h"
#include "net/base/file_stream.h"
#include "net/disk_cache/block_files.h"
#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/mapped_file.h"
+#include "net/disk_cache/stats.h"
#include "net/disk_cache/storage_block.h"
#include "net/disk_cache/storage_block-inl.h"
@@ -51,8 +53,46 @@ int GetMajorVersionFromFile(const FilePath& name) {
return header.version >> 16;
}
+// Dumps the contents of the Stats record.
+void DumpStats(const FilePath& path, disk_cache::CacheAddr addr) {
+ // 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)) {
+ printf("Unable to init block files\n");
+ return;
+ }
+
+ disk_cache::Addr address(addr);
+ disk_cache::MappedFile* file = block_files.GetFile(address);
+ if (!file)
+ return;
+
+ size_t length = (2 + disk_cache::Stats::kDataSizesLength) * sizeof(int32) +
+ disk_cache::Stats::MAX_COUNTER * sizeof(int64);
+
+ size_t offset = address.start_block() * address.BlockSize() +
+ disk_cache::kBlockHeaderSize;
+
+ scoped_ptr<int32[]> buffer(new int32[length]);
+ if (!file->Read(buffer.get(), length, offset))
+ return;
+
+ printf("Stats:\nSignatrure: 0x%x\n", buffer[0]);
+ printf("Total size: %d\n", buffer[1]);
+ for (int i = 0; i < disk_cache::Stats::kDataSizesLength; i++)
+ printf("Size(%d): %d\n", i, buffer[i + 2]);
+
+ int64* counters = reinterpret_cast<int64*>(
+ buffer.get() + 2 + disk_cache::Stats::kDataSizesLength);
+ for (int i = 0; i < disk_cache::Stats::MAX_COUNTER; i++)
+ printf("Count(%d): %" PRId64 "\n", i, *counters++);
+ printf("-------------------------\n\n");
+}
+
// Dumps the contents of the Index-file header.
-void DumpIndexHeader(const FilePath& name) {
+void DumpIndexHeader(const FilePath& name, disk_cache::CacheAddr* stats_addr) {
disk_cache::IndexHeader header;
if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header)))
return;
@@ -67,6 +107,7 @@ void DumpIndexHeader(const FilePath& name) {
printf("table length: %d\n", header.table_len);
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]);
@@ -76,6 +117,8 @@ void DumpIndexHeader(const FilePath& name) {
printf("operation: %d\n", header.lru.operation);
printf("operation list: %d\n", header.lru.operation_list);
printf("-------------------------\n\n");
+
+ *stats_addr = header.stats;
}
// Dumps the contents of a block-file header.
@@ -292,13 +335,16 @@ int GetMajorVersion(const FilePath& input_path) {
// Dumps the headers of all files.
int DumpHeaders(const FilePath& input_path) {
FilePath index_name(input_path.Append(kIndexName));
- DumpIndexHeader(index_name);
+ disk_cache::CacheAddr stats_addr = 0;
+ DumpIndexHeader(index_name, &stats_addr);
file_util::FileEnumerator iter(input_path, false,
file_util::FileEnumerator::FILES,
FILE_PATH_LITERAL("data_*"));
for (FilePath file = iter.Next(); !file.empty(); file = iter.Next())
DumpBlockHeader(file);
+
+ DumpStats(input_path, stats_addr);
return 0;
}