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

Side by Side Diff: net/disk_cache/blockfile/stress_cache.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 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 // This is a simple application that stress-tests the crash recovery of the disk 5 // This is a simple application that stress-tests the crash recovery of the disk
6 // cache. The main application starts a copy of itself on a loop, checking the 6 // cache. The main application starts a copy of itself on a loop, checking the
7 // exit code of the child process. When the child dies in an unexpected way, 7 // exit code of the child process. When the child dies in an unexpected way,
8 // the main application quits. 8 // the main application quits.
9 9
10 // The child application has two threads: one to exercise the cache in an 10 // The child application has two threads: one to exercise the cache in an
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 key[size - 1] = '\0'; 96 key[size - 1] = '\0';
97 return std::string(key); 97 return std::string(key);
98 } 98 }
99 99
100 // This thread will loop forever, adding and removing entries from the cache. 100 // This thread will loop forever, adding and removing entries from the cache.
101 // iteration is the current crash cycle, so the entries on the cache are marked 101 // iteration is the current crash cycle, so the entries on the cache are marked
102 // to know which instance of the application wrote them. 102 // to know which instance of the application wrote them.
103 void StressTheCache(int iteration) { 103 void StressTheCache(int iteration) {
104 int cache_size = 0x2000000; // 32MB. 104 int cache_size = 0x2000000; // 32MB.
105 uint32 mask = 0xfff; // 4096 entries. 105 uint32 mask = 0xfff; // 4096 entries.
106 106
107 base::FilePath path; 107 base::FilePath path;
108 PathService::Get(base::DIR_TEMP, &path); 108 PathService::Get(base::DIR_TEMP, &path);
109 path = path.AppendASCII("cache_test_stress"); 109 path = path.AppendASCII("cache_test_stress");
110 110
111 base::Thread cache_thread("CacheThread"); 111 base::Thread cache_thread("CacheThread");
112 if (!cache_thread.StartWithOptions( 112 if (!cache_thread.StartWithOptions(
113 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) 113 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
114 return; 114 return;
115 115
116 disk_cache::BackendImpl* cache = 116 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(
117 new disk_cache::BackendImpl(path, mask, 117 path, mask, cache_thread.message_loop_proxy().get(), NULL);
118 cache_thread.message_loop_proxy().get(),
119 NULL);
120 cache->SetMaxSize(cache_size); 118 cache->SetMaxSize(cache_size);
121 cache->SetFlags(disk_cache::kNoLoadProtection); 119 cache->SetFlags(disk_cache::kNoLoadProtection);
122 120
123 net::TestCompletionCallback cb; 121 net::TestCompletionCallback cb;
124 int rv = cache->Init(cb.callback()); 122 int rv = cache->Init(cb.callback());
125 123
126 if (cb.GetResult(rv) != net::OK) { 124 if (cb.GetResult(rv) != net::OK) {
127 printf("Unable to initialize cache.\n"); 125 printf("Unable to initialize cache.\n");
128 return; 126 return;
129 } 127 }
130 printf("Iteration %d, initial entries: %d\n", iteration, 128 printf(
131 cache->GetEntryCount()); 129 "Iteration %d, initial entries: %d\n", iteration, cache->GetEntryCount());
132 130
133 int seed = static_cast<int>(Time::Now().ToInternalValue()); 131 int seed = static_cast<int>(Time::Now().ToInternalValue());
134 srand(seed); 132 srand(seed);
135 133
136 // kNumKeys is meant to be enough to have about 3x or 4x iterations before 134 // kNumKeys is meant to be enough to have about 3x or 4x iterations before
137 // the process crashes. 135 // the process crashes.
138 #ifdef NDEBUG 136 #ifdef NDEBUG
139 const int kNumKeys = 4000; 137 const int kNumKeys = 4000;
140 #else 138 #else
141 const int kNumKeys = 1200; 139 const int kNumKeys = 1200;
142 #endif 140 #endif
143 const int kNumEntries = 30; 141 const int kNumEntries = 30;
144 std::string keys[kNumKeys]; 142 std::string keys[kNumKeys];
145 disk_cache::Entry* entries[kNumEntries] = {0}; 143 disk_cache::Entry* entries[kNumEntries] = {0};
146 144
147 for (int i = 0; i < kNumKeys; i++) { 145 for (int i = 0; i < kNumKeys; i++) {
(...skipping 13 matching lines...) Expand all
161 if (entries[slot]) 159 if (entries[slot])
162 entries[slot]->Close(); 160 entries[slot]->Close();
163 161
164 net::TestCompletionCallback cb; 162 net::TestCompletionCallback cb;
165 rv = cache->OpenEntry(keys[key], &entries[slot], cb.callback()); 163 rv = cache->OpenEntry(keys[key], &entries[slot], cb.callback());
166 if (cb.GetResult(rv) != net::OK) { 164 if (cb.GetResult(rv) != net::OK) {
167 rv = cache->CreateEntry(keys[key], &entries[slot], cb.callback()); 165 rv = cache->CreateEntry(keys[key], &entries[slot], cb.callback());
168 CHECK_EQ(net::OK, cb.GetResult(rv)); 166 CHECK_EQ(net::OK, cb.GetResult(rv));
169 } 167 }
170 168
171 base::snprintf(buffer->data(), kSize, 169 base::snprintf(buffer->data(),
172 "i: %d iter: %d, size: %d, truncate: %d ", i, iteration, 170 kSize,
173 size, truncate ? 1 : 0); 171 "i: %d iter: %d, size: %d, truncate: %d ",
174 rv = entries[slot]->WriteData(0, 0, buffer.get(), size, cb.callback(), 172 i,
175 truncate); 173 iteration,
174 size,
175 truncate ? 1 : 0);
176 rv = entries[slot]->WriteData(
177 0, 0, buffer.get(), size, cb.callback(), truncate);
176 CHECK_EQ(size, cb.GetResult(rv)); 178 CHECK_EQ(size, cb.GetResult(rv));
177 179
178 if (rand() % 100 > 80) { 180 if (rand() % 100 > 80) {
179 key = rand() % kNumKeys; 181 key = rand() % kNumKeys;
180 net::TestCompletionCallback cb2; 182 net::TestCompletionCallback cb2;
181 rv = cache->DoomEntry(keys[key], cb2.callback()); 183 rv = cache->DoomEntry(keys[key], cb2.callback());
182 cb2.GetResult(rv); 184 cb2.GetResult(rv);
183 } 185 }
184 186
185 if (!(i % 100)) 187 if (!(i % 100))
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 230
229 RunSoon(thread->message_loop()); 231 RunSoon(thread->message_loop());
230 return true; 232 return true;
231 } 233 }
232 234
233 void CrashHandler(const std::string& str) { 235 void CrashHandler(const std::string& str) {
234 g_crashing = true; 236 g_crashing = true;
235 base::debug::BreakDebugger(); 237 base::debug::BreakDebugger();
236 } 238 }
237 239
238 bool MessageHandler(int severity, const char* file, int line, 240 bool MessageHandler(int severity,
239 size_t message_start, const std::string& str) { 241 const char* file,
242 int line,
243 size_t message_start,
244 const std::string& str) {
240 const size_t kMaxMessageLen = 48; 245 const size_t kMaxMessageLen = 48;
241 char message[kMaxMessageLen]; 246 char message[kMaxMessageLen];
242 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); 247 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1);
243 248
244 memcpy(message, str.c_str() + message_start, len); 249 memcpy(message, str.c_str() + message_start, len);
245 message[len] = '\0'; 250 message[len] = '\0';
246 #if !defined(DISK_CACHE_TRACE_TO_LOG) 251 #if !defined(DISK_CACHE_TRACE_TO_LOG)
247 disk_cache::Trace("%s", message); 252 disk_cache::Trace("%s", message);
248 #endif 253 #endif
249 return false; 254 return false;
250 } 255 }
251 256
252 // ----------------------------------------------------------------------- 257 // -----------------------------------------------------------------------
253 258
254 #if defined(OS_WIN) 259 #if defined(OS_WIN)
255 // {B9A153D4-31C3-48e4-9ABF-D54383F14A0D} 260 // {B9A153D4-31C3-48e4-9ABF-D54383F14A0D}
256 const GUID kStressCacheTraceProviderName = { 261 const GUID kStressCacheTraceProviderName = {
257 0xb9a153d4, 0x31c3, 0x48e4, 262 0xb9a153d4,
258 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; 263 0x31c3,
264 0x48e4,
265 {0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd}};
259 #endif 266 #endif
260 267
261 int main(int argc, const char* argv[]) { 268 int main(int argc, const char* argv[]) {
262 // Setup an AtExitManager so Singleton objects will be destructed. 269 // Setup an AtExitManager so Singleton objects will be destructed.
263 base::AtExitManager at_exit_manager; 270 base::AtExitManager at_exit_manager;
264 271
265 if (argc < 2) 272 if (argc < 2)
266 return MasterCode(); 273 return MasterCode();
267 274
268 logging::SetLogAssertHandler(CrashHandler); 275 logging::SetLogAssertHandler(CrashHandler);
(...skipping 16 matching lines...) Expand all
285 long int iteration = strtol(argv[1], &end, 0); 292 long int iteration = strtol(argv[1], &end, 0);
286 293
287 if (!StartCrashThread()) { 294 if (!StartCrashThread()) {
288 printf("failed to start thread\n"); 295 printf("failed to start thread\n");
289 return kError; 296 return kError;
290 } 297 }
291 298
292 StressTheCache(iteration); 299 StressTheCache(iteration);
293 return 0; 300 return 0;
294 } 301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698