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
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"
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
);
25 base::debug::DumpWithoutCrashing();
27 base::debug::BreakDebugger();
31 #if !defined(OS_ANDROID) || !defined(NDEBUG)
32 NOINLINE
void StartupHang() {
33 volatile int inhibit_comdat
= __LINE__
;
34 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
35 // TODO(rtenneti): http://crbug.com/440885 enable crashing after fixing false
36 // positive startup hang data.
37 // ReportThreadHang();
41 NOINLINE
void ShutdownHang() {
42 volatile int inhibit_comdat
= __LINE__
;
43 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
47 NOINLINE
void ThreadUnresponsive_UI() {
48 volatile int inhibit_comdat
= __LINE__
;
49 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
53 NOINLINE
void ThreadUnresponsive_DB() {
54 volatile int inhibit_comdat
= __LINE__
;
55 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
59 NOINLINE
void ThreadUnresponsive_FILE() {
60 volatile int inhibit_comdat
= __LINE__
;
61 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
65 NOINLINE
void ThreadUnresponsive_FILE_USER_BLOCKING() {
66 volatile int inhibit_comdat
= __LINE__
;
67 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
71 NOINLINE
void ThreadUnresponsive_PROCESS_LAUNCHER() {
72 volatile int inhibit_comdat
= __LINE__
;
73 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
77 NOINLINE
void ThreadUnresponsive_CACHE() {
78 volatile int inhibit_comdat
= __LINE__
;
79 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
83 NOINLINE
void ThreadUnresponsive_IO() {
84 volatile int inhibit_comdat
= __LINE__
;
85 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
89 NOINLINE
void CrashBecauseThreadWasUnresponsive(int thread_id
) {
90 // TODO(rtenneti): The following is a temporary change to check thread_id
91 // numbers explicitly so that we will have minimum code. Will change after the
92 // test run to use content::BrowserThread::ID enum.
94 return ThreadUnresponsive_UI();
95 else if (thread_id
== 1)
96 return ThreadUnresponsive_DB();
97 else if (thread_id
== 2)
98 return ThreadUnresponsive_FILE();
99 else if (thread_id
== 3)
100 return ThreadUnresponsive_FILE_USER_BLOCKING();
101 else if (thread_id
== 4)
102 return ThreadUnresponsive_PROCESS_LAUNCHER();
103 else if (thread_id
== 5)
104 return ThreadUnresponsive_CACHE();
105 else if (thread_id
== 6)
106 return ThreadUnresponsive_IO();
109 } // namespace metrics
112 MSVC_ENABLE_OPTIMIZE();