OLD | NEW |
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 #include "chrome/browser/metrics/thread_watcher.h" | 5 #include "chrome/browser/metrics/thread_watcher.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
| 12 #include "base/debug/dump_without_crashing.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "base/strings/string_tokenizer.h" | 16 #include "base/strings/string_tokenizer.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/metrics/metrics_service.h" | 20 #include "chrome/browser/metrics/metrics_service.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
22 #include "chrome/common/dump_without_crashing.h" | |
23 #include "chrome/common/logging_chrome.h" | 23 #include "chrome/common/logging_chrome.h" |
24 | 24 |
25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
26 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
27 #endif | 27 #endif |
28 | 28 |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // The following are unique function names for forcing the crash when a thread | 33 // The following are unique function names for forcing the crash when a thread |
34 // is unresponsive. This makes it possible to tell from the callstack alone what | 34 // is unresponsive. This makes it possible to tell from the callstack alone what |
35 // thread was unresponsive. | 35 // thread was unresponsive. |
36 // | 36 // |
37 // We disable optimizations for this block of functions so the compiler doesn't | 37 // We disable optimizations for this block of functions so the compiler doesn't |
38 // merge them all together. | 38 // merge them all together. |
39 MSVC_DISABLE_OPTIMIZE() | 39 MSVC_DISABLE_OPTIMIZE() |
40 MSVC_PUSH_DISABLE_WARNING(4748) | 40 MSVC_PUSH_DISABLE_WARNING(4748) |
41 | 41 |
42 #ifndef NDEBUG | 42 #ifndef NDEBUG |
43 int* NullPointer() { | 43 int* NullPointer() { |
44 return reinterpret_cast<int*>(NULL); | 44 return reinterpret_cast<int*>(NULL); |
45 } | 45 } |
46 #endif | 46 #endif |
47 | 47 |
48 void NullPointerCrash(int line_number) { | 48 void NullPointerCrash(int line_number) { |
49 #ifndef NDEBUG | 49 #ifndef NDEBUG |
50 *NullPointer() = line_number; // Crash. | 50 *NullPointer() = line_number; // Crash. |
51 #else | 51 #else |
52 logging::DumpWithoutCrashing(); | 52 base::debug::DumpWithoutCrashing(); |
53 #endif | 53 #endif |
54 } | 54 } |
55 | 55 |
56 NOINLINE void ShutdownCrash() { | 56 NOINLINE void ShutdownCrash() { |
57 NullPointerCrash(__LINE__); | 57 NullPointerCrash(__LINE__); |
58 } | 58 } |
59 | 59 |
60 NOINLINE void ThreadUnresponsive_UI() { | 60 NOINLINE void ThreadUnresponsive_UI() { |
61 NullPointerCrash(__LINE__); | 61 NullPointerCrash(__LINE__); |
62 } | 62 } |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 : base::Watchdog(duration, "Startup watchdog thread", true) { | 854 : base::Watchdog(duration, "Startup watchdog thread", true) { |
855 } | 855 } |
856 | 856 |
857 // Alarm is called if the time expires after an Arm() without someone calling | 857 // Alarm is called if the time expires after an Arm() without someone calling |
858 // Disarm(). When Alarm goes off, in release mode we get the crash dump | 858 // Disarm(). When Alarm goes off, in release mode we get the crash dump |
859 // without crashing and in debug mode we break into the debugger. | 859 // without crashing and in debug mode we break into the debugger. |
860 virtual void Alarm() OVERRIDE { | 860 virtual void Alarm() OVERRIDE { |
861 #ifndef NDEBUG | 861 #ifndef NDEBUG |
862 DCHECK(false); | 862 DCHECK(false); |
863 #else | 863 #else |
864 logging::DumpWithoutCrashing(); | 864 base::debug::DumpWithoutCrashing(); |
865 #endif | 865 #endif |
866 } | 866 } |
867 | 867 |
868 DISALLOW_COPY_AND_ASSIGN(StartupWatchDogThread); | 868 DISALLOW_COPY_AND_ASSIGN(StartupWatchDogThread); |
869 }; | 869 }; |
870 | 870 |
871 // ShutdownWatchDogThread methods and members. | 871 // ShutdownWatchDogThread methods and members. |
872 // | 872 // |
873 // Class for detecting hangs during shutdown. | 873 // Class for detecting hangs during shutdown. |
874 class ShutdownWatchDogThread : public base::Watchdog { | 874 class ShutdownWatchDogThread : public base::Watchdog { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 | 983 |
984 #if defined(OS_WIN) | 984 #if defined(OS_WIN) |
985 // On Windows XP, give twice the time for shutdown. | 985 // On Windows XP, give twice the time for shutdown. |
986 if (base::win::GetVersion() <= base::win::VERSION_XP) | 986 if (base::win::GetVersion() <= base::win::VERSION_XP) |
987 actual_duration *= 2; | 987 actual_duration *= 2; |
988 #endif | 988 #endif |
989 | 989 |
990 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 990 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
991 shutdown_watchdog_->Arm(); | 991 shutdown_watchdog_->Arm(); |
992 } | 992 } |
OLD | NEW |