Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / metrics / thread_watcher_report_hang.cc
blobf0cd6c2dc85bd75bf189c349dda2955bedb27935
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/thread_watcher_report_hang.h"
7 // We disable optimizations for the whole file so the compiler doesn't merge
8 // them all together.
9 MSVC_DISABLE_OPTIMIZE()
10 MSVC_PUSH_DISABLE_WARNING(4748)
12 #include "base/debug/debugger.h"
13 #include "base/debug/dump_without_crashing.h"
14 #include "build/build_config.h"
16 namespace metrics {
18 // The following are unique function names for forcing the crash when a thread
19 // is unresponsive. This makes it possible to tell from the callstack alone what
20 // thread was unresponsive.
21 NOINLINE void ReportThreadHang() {
22 volatile const char* inhibit_comdat = __FUNCTION__;
23 ALLOW_UNUSED_LOCAL(inhibit_comdat);
24 #if defined(NDEBUG)
25 base::debug::DumpWithoutCrashing();
26 #else
27 base::debug::BreakDebugger();
28 #endif
31 #if !defined(OS_ANDROID) || !defined(NDEBUG)
32 // TODO(rtenneti): Enabled crashing, after getting data.
33 NOINLINE void StartupHang() {
34 volatile int inhibit_comdat = __LINE__;
35 ALLOW_UNUSED_LOCAL(inhibit_comdat);
36 ReportThreadHang();
38 #endif // OS_ANDROID
40 NOINLINE void ShutdownHang() {
41 volatile int inhibit_comdat = __LINE__;
42 ALLOW_UNUSED_LOCAL(inhibit_comdat);
43 ReportThreadHang();
46 NOINLINE void ThreadUnresponsive_UI() {
47 volatile int inhibit_comdat = __LINE__;
48 ALLOW_UNUSED_LOCAL(inhibit_comdat);
49 ReportThreadHang();
52 NOINLINE void ThreadUnresponsive_DB() {
53 volatile int inhibit_comdat = __LINE__;
54 ALLOW_UNUSED_LOCAL(inhibit_comdat);
55 ReportThreadHang();
58 NOINLINE void ThreadUnresponsive_FILE() {
59 volatile int inhibit_comdat = __LINE__;
60 ALLOW_UNUSED_LOCAL(inhibit_comdat);
61 ReportThreadHang();
64 NOINLINE void ThreadUnresponsive_FILE_USER_BLOCKING() {
65 volatile int inhibit_comdat = __LINE__;
66 ALLOW_UNUSED_LOCAL(inhibit_comdat);
67 ReportThreadHang();
70 NOINLINE void ThreadUnresponsive_PROCESS_LAUNCHER() {
71 volatile int inhibit_comdat = __LINE__;
72 ALLOW_UNUSED_LOCAL(inhibit_comdat);
73 ReportThreadHang();
76 NOINLINE void ThreadUnresponsive_CACHE() {
77 volatile int inhibit_comdat = __LINE__;
78 ALLOW_UNUSED_LOCAL(inhibit_comdat);
79 ReportThreadHang();
82 NOINLINE void ThreadUnresponsive_IO() {
83 volatile int inhibit_comdat = __LINE__;
84 ALLOW_UNUSED_LOCAL(inhibit_comdat);
85 ReportThreadHang();
88 NOINLINE void CrashBecauseThreadWasUnresponsive(int thread_id) {
89 // TODO(rtenneti): The following is a temporary change to check thread_id
90 // numbers explicitly so that we will have minimum code. Will change after the
91 // test run to use content::BrowserThread::ID enum.
92 if (thread_id == 0)
93 return ThreadUnresponsive_UI();
94 else if (thread_id == 1)
95 return ThreadUnresponsive_DB();
96 else if (thread_id == 2)
97 return ThreadUnresponsive_FILE();
98 else if (thread_id == 3)
99 return ThreadUnresponsive_FILE_USER_BLOCKING();
100 else if (thread_id == 4)
101 return ThreadUnresponsive_PROCESS_LAUNCHER();
102 else if (thread_id == 5)
103 return ThreadUnresponsive_CACHE();
104 else if (thread_id == 6)
105 return ThreadUnresponsive_IO();
108 } // namespace metrics
110 MSVC_POP_WARNING()
111 MSVC_ENABLE_OPTIMIZE();