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

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

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 3 years, 11 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
« no previous file with comments | « net/test/gtest_util.h ('k') | remoting/client/plugin/chromoting_instance.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 // 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 class MessageListener : logging::LogMessageListener {
388 size_t message_start, const std::string& str) { 388 public:
389 const size_t kMaxMessageLen = 48; 389 void OnMessage(int severity,
390 char message[kMaxMessageLen]; 390 const char* file,
391 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1); 391 int line,
392 size_t message_start,
393 const std::string& str) override {
394 const size_t kMaxMessageLen = 48;
395 char message[kMaxMessageLen];
396 size_t len = std::min(str.length() - message_start, kMaxMessageLen - 1);
392 397
393 memcpy(message, str.c_str() + message_start, len); 398 memcpy(message, str.c_str() + message_start, len);
394 message[len] = '\0'; 399 message[len] = '\0';
395 #if !defined(DISK_CACHE_TRACE_TO_LOG) 400 #if !defined(DISK_CACHE_TRACE_TO_LOG)
396 disk_cache::Trace("%s", message); 401 disk_cache::Trace("%s", message);
397 #endif 402 #endif
398 return false; 403 }
399 } 404 };
400 405
401 // ----------------------------------------------------------------------- 406 // -----------------------------------------------------------------------
402 407
403 #if defined(OS_WIN) 408 #if defined(OS_WIN)
404 // {B9A153D4-31C3-48e4-9ABF-D54383F14A0D} 409 // {B9A153D4-31C3-48e4-9ABF-D54383F14A0D}
405 const GUID kStressCacheTraceProviderName = { 410 const GUID kStressCacheTraceProviderName = {
406 0xb9a153d4, 0x31c3, 0x48e4, 411 0xb9a153d4, 0x31c3, 0x48e4,
407 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } }; 412 { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } };
408 #endif 413 #endif
409 414
410 int main(int argc, const char* argv[]) { 415 int main(int argc, const char* argv[]) {
411 // Setup an AtExitManager so Singleton objects will be destructed. 416 // Setup an AtExitManager so Singleton objects will be destructed.
412 base::AtExitManager at_exit_manager; 417 base::AtExitManager at_exit_manager;
413 418
414 if (argc < 2) 419 if (argc < 2)
415 return MasterCode(); 420 return MasterCode();
416 421
417 logging::SetLogAssertHandler(CrashHandler); 422 logging::SetLogAssertHandler(CrashHandler);
418 logging::SetLogMessageHandler(MessageHandler); 423 MessageListener listener;
419 424
420 #if defined(OS_WIN) 425 #if defined(OS_WIN)
421 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName); 426 logging::LogEventProvider::Initialize(kStressCacheTraceProviderName);
422 #else 427 #else
423 base::CommandLine::Init(argc, argv); 428 base::CommandLine::Init(argc, argv);
424 logging::LoggingSettings settings; 429 logging::LoggingSettings settings;
425 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 430 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
426 logging::InitLogging(settings); 431 logging::InitLogging(settings);
427 #endif 432 #endif
428 433
429 // Some time for the memory manager to flush stuff. 434 // Some time for the memory manager to flush stuff.
430 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); 435 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3));
431 base::MessageLoopForIO message_loop; 436 base::MessageLoopForIO message_loop;
432 437
433 char* end; 438 char* end;
434 long int iteration = strtol(argv[1], &end, 0); 439 long int iteration = strtol(argv[1], &end, 0);
435 440
436 if (!StartCrashThread()) { 441 if (!StartCrashThread()) {
437 printf("failed to start thread\n"); 442 printf("failed to start thread\n");
438 return kError; 443 return kError;
439 } 444 }
440 445
441 StressTheCache(iteration); 446 StressTheCache(iteration);
442 return 0; 447 return 0;
443 } 448 }
OLDNEW
« no previous file with comments | « net/test/gtest_util.h ('k') | remoting/client/plugin/chromoting_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698