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

Side by Side Diff: net/tools/stress_cache/stress_cache.cc

Issue 2497833002: support multiple log message handlers in base/logging.h (Closed)
Patch Set: Created 4 years, 1 month 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
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 377
378 RunSoon(thread->task_runner()); 378 RunSoon(thread->task_runner());
379 return true; 379 return true;
380 } 380 }
381 381
382 void CrashHandler(const std::string& str) { 382 void CrashHandler(const std::string& str) {
383 g_crashing = true; 383 g_crashing = true;
384 base::debug::BreakDebugger(); 384 base::debug::BreakDebugger();
385 } 385 }
386 386
387 bool MessageHandler(int severity, const char* file, int line, 387 bool MessageHandler(int severity,
388 size_t message_start, const std::string& str) { 388 const std::string& file,
389 int line,
390 const std::string& str) {
389 const size_t kMaxMessageLen = 48; 391 const size_t kMaxMessageLen = 48;
390 char message[kMaxMessageLen]; 392 char message[kMaxMessageLen];
391 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); 393 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1);
392 394
393 memcpy(message, str.c_str() + message_start, len); 395 memcpy(message, str.c_str() + message_start, len);
394 message[len] = '\0'; 396 message[len] = '\0';
395 #if !defined(DISK_CACHE_TRACE_TO_LOG) 397 #if !defined(DISK_CACHE_TRACE_TO_LOG)
396 disk_cache::Trace("%s", message); 398 disk_cache::Trace("%s", message);
397 #endif 399 #endif
398 return false; 400 return false;
399 } 401 }
400 402
401 // ----------------------------------------------------------------------- 403 // -----------------------------------------------------------------------
402 404
403 #if defined(OS_WIN) 405 #if defined(OS_WIN)
404 // {B9A153D4-31C3-48e4-9ABF-D54383F14A0D} 406 // {B9A153D4-31C3-48e4-9ABF-D54383F14A0D}
405 const GUID kStressCacheTraceProviderName = { 407 const GUID kStressCacheTraceProviderName = {
406 0xb9a153d4, 0x31c3, 0x48e4, 408 0xb9a153d4, 0x31c3, 0x48e4,
407 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; 409 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } };
408 #endif 410 #endif
409 411
410 int main(int argc, const char* argv[]) { 412 int main(int argc, const char* argv[]) {
411 // Setup an AtExitManager so Singleton objects will be destructed. 413 // Setup an AtExitManager so Singleton objects will be destructed.
412 base::AtExitManager at_exit_manager; 414 base::AtExitManager at_exit_manager;
413 415
414 if (argc < 2) 416 if (argc < 2)
415 return MasterCode(); 417 return MasterCode();
416 418
417 logging::SetLogAssertHandler(CrashHandler); 419 logging::SetLogAssertHandler(CrashHandler);
418 logging::SetLogMessageHandler(MessageHandler); 420 logging::AddLogMessageHandler(MessageHandler);
419 421
420 #if defined(OS_WIN) 422 #if defined(OS_WIN)
421 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); 423 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName);
422 #else 424 #else
423 base::CommandLine::Init(argc, argv); 425 base::CommandLine::Init(argc, argv);
424 logging::LoggingSettings settings; 426 logging::LoggingSettings settings;
425 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 427 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
426 logging::InitLogging(settings); 428 logging::InitLogging(settings);
427 #endif 429 #endif
428 430
429 // Some time for the memory manager to flush stuff. 431 // Some time for the memory manager to flush stuff.
430 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); 432 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3));
431 base::MessageLoopForIO message_loop; 433 base::MessageLoopForIO message_loop;
432 434
433 char* end; 435 char* end;
434 long int iteration = strtol(argv[1], &end, 0); 436 long int iteration = strtol(argv[1], &end, 0);
435 437
436 if (!StartCrashThread()) { 438 if (!StartCrashThread()) {
437 printf("failed to start thread\n"); 439 printf("failed to start thread\n");
438 return kError; 440 return kError;
439 } 441 }
440 442
441 StressTheCache(iteration); 443 StressTheCache(iteration);
442 return 0; 444 return 0;
443 } 445 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/crash_report/breakpad_helper.mm ('k') | remoting/client/plugin/chromoting_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698