Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: net/tools/dump_cache/dump_files.cc

Issue 11299239: Adding a simple class for dumping the contents of a cache. Use this new class in dump_cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/tools/dump_cache/dump_files.h ('k') | net/tools/dump_cache/simple_cache_dumper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10
9 #include <stdio.h> 11 #include <stdio.h>
10 12
11 #include <set> 13 #include <set>
12 #include <string> 14 #include <string>
13 15
14 #include "base/file_util.h" 16 #include "base/file_util.h"
15 #include "base/message_loop.h" 17 #include "base/message_loop.h"
16 #include "net/base/file_stream.h" 18 #include "net/base/file_stream.h"
17 #include "net/disk_cache/block_files.h" 19 #include "net/disk_cache/block_files.h"
18 #include "net/disk_cache/disk_format.h" 20 #include "net/disk_cache/disk_format.h"
19 #include "net/disk_cache/mapped_file.h" 21 #include "net/disk_cache/mapped_file.h"
20 #include "net/disk_cache/storage_block.h" 22 #include "net/disk_cache/storage_block.h"
21 #include "net/disk_cache/storage_block-inl.h" 23 #include "net/disk_cache/storage_block-inl.h"
22 24
23 namespace { 25 namespace {
24 26
25 const wchar_t kIndexName[] = L"index"; 27 const FilePath::CharType kIndexName[] = FILE_PATH_LITERAL("index");
26 28
27 // Reads the |header_size| bytes from the beginning of file |name|. 29 // Reads the |header_size| bytes from the beginning of file |name|.
28 bool ReadHeader(const FilePath& name, char* header, int header_size) { 30 bool ReadHeader(const FilePath& name, char* header, int header_size) {
29 net::FileStream file(NULL); 31 net::FileStream file(NULL);
30 file.OpenSync(name, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); 32 file.OpenSync(name, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
31 if (!file.IsOpen()) { 33 if (!file.IsOpen()) {
32 printf("Unable to open file %ls\n", name.value().c_str()); 34 printf("Unable to open file %s\n", name.MaybeAsASCII().c_str());
33 return false; 35 return false;
34 } 36 }
35 37
36 int read = file.ReadSync(header, header_size); 38 int read = file.ReadSync(header, header_size);
37 if (read != header_size) { 39 if (read != header_size) {
38 printf("Unable to read file %ls\n", name.value().c_str()); 40 printf("Unable to read file %s\n", name.MaybeAsASCII().c_str());
39 return false; 41 return false;
40 } 42 }
41 return true; 43 return true;
42 } 44 }
43 45
44 int GetMajorVersionFromFile(const FilePath& name) { 46 int GetMajorVersionFromFile(const FilePath& name) {
45 disk_cache::IndexHeader header; 47 disk_cache::IndexHeader header;
46 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header))) 48 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header)))
47 return 0; 49 return 0;
48 50
(...skipping 26 matching lines...) Expand all
75 printf("operation list: %d\n", header.lru.operation_list); 77 printf("operation list: %d\n", header.lru.operation_list);
76 printf("-------------------------\n\n"); 78 printf("-------------------------\n\n");
77 } 79 }
78 80
79 // Dumps the contents of a block-file header. 81 // Dumps the contents of a block-file header.
80 void DumpBlockHeader(const FilePath& name) { 82 void DumpBlockHeader(const FilePath& name) {
81 disk_cache::BlockFileHeader header; 83 disk_cache::BlockFileHeader header;
82 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header))) 84 if (!ReadHeader(name, reinterpret_cast<char*>(&header), sizeof(header)))
83 return; 85 return;
84 86
85 printf("Block file: %ls\n", name.BaseName().value().c_str()); 87 printf("Block file: %s\n", name.BaseName().MaybeAsASCII().c_str());
86 printf("magic: %x\n", header.magic); 88 printf("magic: %x\n", header.magic);
87 printf("version: %d.%d\n", header.version >> 16, header.version & 0xffff); 89 printf("version: %d.%d\n", header.version >> 16, header.version & 0xffff);
88 printf("file id: %d\n", header.this_file); 90 printf("file id: %d\n", header.this_file);
89 printf("next file id: %d\n", header.next_file); 91 printf("next file id: %d\n", header.next_file);
90 printf("entry size: %d\n", header.entry_size); 92 printf("entry size: %d\n", header.entry_size);
91 printf("current entries: %d\n", header.num_entries); 93 printf("current entries: %d\n", header.num_entries);
92 printf("max entries: %d\n", header.max_entries); 94 printf("max entries: %d\n", header.max_entries);
93 printf("updating: %d\n", header.updating); 95 printf("updating: %d\n", header.updating);
94 printf("empty sz 1: %d\n", header.empty[0]); 96 printf("empty sz 1: %d\n", header.empty[0]);
95 printf("empty sz 2: %d\n", header.empty[1]); 97 printf("empty sz 2: %d\n", header.empty[1]);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 263
262 // ----------------------------------------------------------------------- 264 // -----------------------------------------------------------------------
263 265
264 int GetMajorVersion(const FilePath& input_path) { 266 int GetMajorVersion(const FilePath& input_path) {
265 FilePath index_name(input_path.Append(kIndexName)); 267 FilePath index_name(input_path.Append(kIndexName));
266 268
267 int version = GetMajorVersionFromFile(index_name); 269 int version = GetMajorVersionFromFile(index_name);
268 if (!version) 270 if (!version)
269 return 0; 271 return 0;
270 272
271 FilePath data_name(input_path.Append(L"data_0")); 273 FilePath data_name(input_path.Append(FILE_PATH_LITERAL("data_0")));
272 if (version != GetMajorVersionFromFile(data_name)) 274 if (version != GetMajorVersionFromFile(data_name))
273 return 0; 275 return 0;
274 276
275 data_name = input_path.Append(L"data_1"); 277 data_name = input_path.Append(FILE_PATH_LITERAL("data_1"));
276 if (version != GetMajorVersionFromFile(data_name)) 278 if (version != GetMajorVersionFromFile(data_name))
277 return 0; 279 return 0;
278 280
281 data_name = input_path.Append(FILE_PATH_LITERAL("data_2"));
282 if (version != GetMajorVersionFromFile(data_name))
283 return 0;
284
285 data_name = input_path.Append(FILE_PATH_LITERAL("data_3"));
286 if (version != GetMajorVersionFromFile(data_name))
287 return 0;
288
279 return version; 289 return version;
280 } 290 }
281 291
282 // Dumps the headers of all files. 292 // Dumps the headers of all files.
283 int DumpHeaders(const FilePath& input_path) { 293 int DumpHeaders(const FilePath& input_path) {
284 FilePath index_name(input_path.Append(kIndexName)); 294 FilePath index_name(input_path.Append(kIndexName));
285 DumpIndexHeader(index_name); 295 DumpIndexHeader(index_name);
286 296
287 file_util::FileEnumerator iter(input_path, false, 297 file_util::FileEnumerator iter(input_path, false,
288 file_util::FileEnumerator::FILES, L"data_*"); 298 file_util::FileEnumerator::FILES,
299 FILE_PATH_LITERAL("data_*"));
289 for (FilePath file = iter.Next(); !file.empty(); file = iter.Next()) 300 for (FilePath file = iter.Next(); !file.empty(); file = iter.Next())
290 DumpBlockHeader(file); 301 DumpBlockHeader(file);
291 return 0; 302 return 0;
292 } 303 }
293 304
294 // Dumps all entries from the cache. 305 // Dumps all entries from the cache.
295 int DumpContents(const FilePath& input_path) { 306 int DumpContents(const FilePath& input_path) {
296 DumpHeaders(input_path); 307 DumpHeaders(input_path);
297 308
298 // We need a message loop, although we really don't run any task. 309 // We need a message loop, although we really don't run any task.
299 MessageLoop loop(MessageLoop::TYPE_IO); 310 MessageLoop loop(MessageLoop::TYPE_IO);
300 CacheDumper dumper(input_path); 311 CacheDumper dumper(input_path);
301 if (!dumper.Init()) 312 if (!dumper.Init())
302 return -1; 313 return -1;
303 314
304 disk_cache::EntryStore entry; 315 disk_cache::EntryStore entry;
305 while (dumper.GetEntry(&entry)) { 316 while (dumper.GetEntry(&entry)) {
306 DumpEntry(entry); 317 DumpEntry(entry);
307 disk_cache::RankingsNode rankings; 318 disk_cache::RankingsNode rankings;
308 if (dumper.LoadRankings(entry.rankings_node, &rankings)) 319 if (dumper.LoadRankings(entry.rankings_node, &rankings))
309 DumpRankings(rankings); 320 DumpRankings(rankings);
310 } 321 }
311 322
312 printf("Done.\n"); 323 printf("Done.\n");
313 324
314 return 0; 325 return 0;
315 } 326 }
OLDNEW
« no previous file with comments | « net/tools/dump_cache/dump_files.h ('k') | net/tools/dump_cache/simple_cache_dumper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698