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

Side by Side Diff: net/disk_cache/disk_cache_perftest.cc

Issue 20134: Extend the IOBuffer to the disk cache. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/perftimer.h" 10 #include "base/perftimer.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/test_file_util.h" 12 #include "base/test_file_util.h"
13 #include "base/timer.h" 13 #include "base/timer.h"
14 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
15 #include "net/disk_cache/block_files.h" 16 #include "net/disk_cache/block_files.h"
16 #include "net/disk_cache/disk_cache.h" 17 #include "net/disk_cache/disk_cache.h"
17 #include "net/disk_cache/disk_cache_test_util.h" 18 #include "net/disk_cache/disk_cache_test_util.h"
18 #include "net/disk_cache/hash.h" 19 #include "net/disk_cache/hash.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/platform_test.h" 21 #include "testing/platform_test.h"
21 22
22 using base::Time; 23 using base::Time;
23 24
(...skipping 10 matching lines...) Expand all
34 int data_len; 35 int data_len;
35 }; 36 };
36 typedef std::vector<TestEntry> TestEntries; 37 typedef std::vector<TestEntry> TestEntries;
37 38
38 const int kMaxSize = 16 * 1024 - 1; 39 const int kMaxSize = 16 * 1024 - 1;
39 40
40 // Creates num_entries on the cache, and writes 200 bytes of metadata and up 41 // Creates num_entries on the cache, and writes 200 bytes of metadata and up
41 // to kMaxSize of data to each entry. 42 // to kMaxSize of data to each entry.
42 int TimeWrite(int num_entries, disk_cache::Backend* cache, 43 int TimeWrite(int num_entries, disk_cache::Backend* cache,
43 TestEntries* entries) { 44 TestEntries* entries) {
44 char buffer1[200]; 45 const int kSize1 = 200;
45 char buffer2[kMaxSize]; 46 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
47 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kMaxSize);
46 48
47 CacheTestFillBuffer(buffer1, sizeof(buffer1), false); 49 CacheTestFillBuffer(buffer1->data(), kSize1, false);
48 CacheTestFillBuffer(buffer2, sizeof(buffer2), false); 50 CacheTestFillBuffer(buffer2->data(), kMaxSize, false);
49 51
50 CallbackTest callback(1); 52 CallbackTest callback(1);
51 g_cache_tests_error = false; 53 g_cache_tests_error = false;
52 g_cache_tests_max_id = 1; 54 g_cache_tests_max_id = 1;
53 g_cache_tests_received = 0; 55 g_cache_tests_received = 0;
54 int expected = 0; 56 int expected = 0;
55 57
56 MessageLoopHelper helper; 58 MessageLoopHelper helper;
57 59
58 PerfTimeLogger timer("Write disk cache entries"); 60 PerfTimeLogger timer("Write disk cache entries");
59 61
60 for (int i = 0; i < num_entries; i++) { 62 for (int i = 0; i < num_entries; i++) {
61 TestEntry entry; 63 TestEntry entry;
62 entry.key = GenerateKey(true); 64 entry.key = GenerateKey(true);
63 entry.data_len = rand() % sizeof(buffer2); 65 entry.data_len = rand() % kMaxSize;
64 entries->push_back(entry); 66 entries->push_back(entry);
65 67
66 disk_cache::Entry* cache_entry; 68 disk_cache::Entry* cache_entry;
67 if (!cache->CreateEntry(entry.key, &cache_entry)) 69 if (!cache->CreateEntry(entry.key, &cache_entry))
68 break; 70 break;
69 int ret = cache_entry->WriteData(0, 0, buffer1, sizeof(buffer1), &callback, 71 int ret = cache_entry->WriteData(0, 0, buffer1, kSize1, &callback, false);
70 false);
71 if (net::ERR_IO_PENDING == ret) 72 if (net::ERR_IO_PENDING == ret)
72 expected++; 73 expected++;
73 else if (sizeof(buffer1) != ret) 74 else if (kSize1 != ret)
74 break; 75 break;
75 76
76 ret = cache_entry->WriteData(1, 0, buffer2, entry.data_len, &callback, 77 ret = cache_entry->WriteData(1, 0, buffer2, entry.data_len, &callback,
77 false); 78 false);
78 if (net::ERR_IO_PENDING == ret) 79 if (net::ERR_IO_PENDING == ret)
79 expected++; 80 expected++;
80 else if (entry.data_len != ret) 81 else if (entry.data_len != ret)
81 break; 82 break;
82 cache_entry->Close(); 83 cache_entry->Close();
83 } 84 }
84 85
85 helper.WaitUntilCacheIoFinished(expected); 86 helper.WaitUntilCacheIoFinished(expected);
86 timer.Done(); 87 timer.Done();
87 88
88 return expected; 89 return expected;
89 } 90 }
90 91
91 // Reads the data and metadata from each entry listed on |entries|. 92 // Reads the data and metadata from each entry listed on |entries|.
92 int TimeRead(int num_entries, disk_cache::Backend* cache, 93 int TimeRead(int num_entries, disk_cache::Backend* cache,
93 const TestEntries& entries, bool cold) { 94 const TestEntries& entries, bool cold) {
94 char buffer1[200]; 95 const int kSize1 = 200;
95 char buffer2[kMaxSize]; 96 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
97 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kMaxSize);
96 98
97 CacheTestFillBuffer(buffer1, sizeof(buffer1), false); 99 CacheTestFillBuffer(buffer1->data(), kSize1, false);
98 CacheTestFillBuffer(buffer2, sizeof(buffer2), false); 100 CacheTestFillBuffer(buffer2->data(), kMaxSize, false);
99 101
100 CallbackTest callback(1); 102 CallbackTest callback(1);
101 g_cache_tests_error = false; 103 g_cache_tests_error = false;
102 g_cache_tests_max_id = 1; 104 g_cache_tests_max_id = 1;
103 g_cache_tests_received = 0; 105 g_cache_tests_received = 0;
104 int expected = 0; 106 int expected = 0;
105 107
106 MessageLoopHelper helper; 108 MessageLoopHelper helper;
107 109
108 const char* message = cold ? "Read disk cache entries (cold)" : 110 const char* message = cold ? "Read disk cache entries (cold)" :
109 "Read disk cache entries (warm)"; 111 "Read disk cache entries (warm)";
110 PerfTimeLogger timer(message); 112 PerfTimeLogger timer(message);
111 113
112 for (int i = 0; i < num_entries; i++) { 114 for (int i = 0; i < num_entries; i++) {
113 disk_cache::Entry* cache_entry; 115 disk_cache::Entry* cache_entry;
114 if (!cache->OpenEntry(entries[i].key, &cache_entry)) 116 if (!cache->OpenEntry(entries[i].key, &cache_entry))
115 break; 117 break;
116 int ret = cache_entry->ReadData(0, 0, buffer1, sizeof(buffer1), &callback); 118 int ret = cache_entry->ReadData(0, 0, buffer1, kSize1, &callback);
117 if (net::ERR_IO_PENDING == ret) 119 if (net::ERR_IO_PENDING == ret)
118 expected++; 120 expected++;
119 else if (sizeof(buffer1) != ret) 121 else if (kSize1 != ret)
120 break; 122 break;
121 123
122 ret = cache_entry->ReadData(1, 0, buffer2, entries[i].data_len, &callback); 124 ret = cache_entry->ReadData(1, 0, buffer2, entries[i].data_len, &callback);
123 if (net::ERR_IO_PENDING == ret) 125 if (net::ERR_IO_PENDING == ret)
124 expected++; 126 expected++;
125 else if (entries[i].data_len != ret) 127 else if (entries[i].data_len != ret)
126 break; 128 break;
127 cache_entry->Close(); 129 cache_entry->Close();
128 } 130 }
129 131
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 entry = 0; 240 entry = 0;
239 241
240 files.DeleteBlock(address[entry], false); 242 files.DeleteBlock(address[entry], false);
241 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), 243 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(),
242 &address[entry])); 244 &address[entry]));
243 } 245 }
244 246
245 timer2.Done(); 247 timer2.Done();
246 MessageLoop::current()->RunAllPending(); 248 MessageLoop::current()->RunAllPending();
247 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698