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

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

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

Powered by Google App Engine
This is Rietveld 408576698