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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // The following are unique function names for forcing the crash when a thread | 29 // The following are unique function names for forcing the crash when a thread |
30 // is unresponsive. This makes it possible to tell from the callstack alone what | 30 // is unresponsive. This makes it possible to tell from the callstack alone what |
31 // thread was unresponsive. | 31 // thread was unresponsive. |
32 // | 32 // |
33 // We disable optimizations for this block of functions so the compiler doesn't | 33 // We disable optimizations for this block of functions so the compiler doesn't |
34 // merge them all together. | 34 // merge them all together. |
35 | 35 MSVC_DISABLE_OPTIMIZE() |
36 // TODO(eroman): What is the equivalent for other compilers? | |
37 #if defined(COMPILER_MSVC) | |
38 #pragma optimize("", off) | |
39 MSVC_PUSH_DISABLE_WARNING(4748) | 36 MSVC_PUSH_DISABLE_WARNING(4748) |
40 #endif | |
41 | 37 |
42 int* NullPointer() { | 38 int* NullPointer() { |
43 return reinterpret_cast<int*>(NULL); | 39 return reinterpret_cast<int*>(NULL); |
44 } | 40 } |
45 | 41 |
46 void ThreadUnresponsive_UI() { | 42 NOINLINE void ThreadUnresponsive_UI() { |
47 *NullPointer() = __LINE__; | 43 *NullPointer() = __LINE__; |
48 } | 44 } |
49 | 45 |
50 void ThreadUnresponsive_DB() { | 46 NOINLINE void ThreadUnresponsive_DB() { |
51 *NullPointer() = __LINE__; | 47 *NullPointer() = __LINE__; |
52 } | 48 } |
53 | 49 |
54 void ThreadUnresponsive_WEBKIT() { | 50 NOINLINE void ThreadUnresponsive_WEBKIT() { |
55 *NullPointer() = __LINE__; | 51 *NullPointer() = __LINE__; |
56 } | 52 } |
57 | 53 |
58 void ThreadUnresponsive_FILE() { | 54 NOINLINE void ThreadUnresponsive_FILE() { |
59 *NullPointer() = __LINE__; | 55 *NullPointer() = __LINE__; |
60 } | 56 } |
61 | 57 |
62 void ThreadUnresponsive_FILE_USER_BLOCKING() { | 58 NOINLINE void ThreadUnresponsive_FILE_USER_BLOCKING() { |
63 *NullPointer() = __LINE__; | 59 *NullPointer() = __LINE__; |
64 } | 60 } |
65 | 61 |
66 void ThreadUnresponsive_PROCESS_LAUNCHER() { | 62 NOINLINE void ThreadUnresponsive_PROCESS_LAUNCHER() { |
67 *NullPointer() = __LINE__; | 63 *NullPointer() = __LINE__; |
68 } | 64 } |
69 | 65 |
70 void ThreadUnresponsive_CACHE() { | 66 NOINLINE void ThreadUnresponsive_CACHE() { |
71 *NullPointer() = __LINE__; | 67 *NullPointer() = __LINE__; |
72 } | 68 } |
73 | 69 |
74 void ThreadUnresponsive_IO() { | 70 NOINLINE void ThreadUnresponsive_IO() { |
75 *NullPointer() = __LINE__; | 71 *NullPointer() = __LINE__; |
76 } | 72 } |
77 | 73 |
78 #if defined(COMPILER_MSVC) | |
79 MSVC_POP_WARNING() | 74 MSVC_POP_WARNING() |
80 #pragma optimize("", on) | 75 MSVC_ENABLE_OPTIMIZE(); |
81 #endif | |
82 | 76 |
83 void CrashBecauseThreadWasUnresponsive(BrowserThread::ID thread_id) { | 77 void CrashBecauseThreadWasUnresponsive(BrowserThread::ID thread_id) { |
84 base::debug::Alias(&thread_id); | 78 base::debug::Alias(&thread_id); |
85 | 79 |
86 switch (thread_id) { | 80 switch (thread_id) { |
87 case BrowserThread::UI: | 81 case BrowserThread::UI: |
88 return ThreadUnresponsive_UI(); | 82 return ThreadUnresponsive_UI(); |
89 case BrowserThread::DB: | 83 case BrowserThread::DB: |
90 return ThreadUnresponsive_DB(); | 84 return ThreadUnresponsive_DB(); |
91 case BrowserThread::WEBKIT_DEPRECATED: | 85 case BrowserThread::WEBKIT_DEPRECATED: |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 | 918 |
925 #if defined(OS_WIN) | 919 #if defined(OS_WIN) |
926 // On Windows XP, give twice the time for shutdown. | 920 // On Windows XP, give twice the time for shutdown. |
927 if (base::win::GetVersion() <= base::win::VERSION_XP) | 921 if (base::win::GetVersion() <= base::win::VERSION_XP) |
928 actual_duration *= 2; | 922 actual_duration *= 2; |
929 #endif | 923 #endif |
930 | 924 |
931 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 925 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
932 shutdown_watchdog_->Arm(); | 926 shutdown_watchdog_->Arm(); |
933 } | 927 } |
OLD | NEW |