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 // TODO(rtenneti): Enabled crashing, after getting data.
33 NOINLINE
void StartupHang() {
34 volatile int inhibit_comdat
= __LINE__
;
35 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
40 NOINLINE
void ShutdownHang() {
41 volatile int inhibit_comdat
= __LINE__
;
42 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
46 NOINLINE
void ThreadUnresponsive_UI() {
47 volatile int inhibit_comdat
= __LINE__
;
48 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
52 NOINLINE
void ThreadUnresponsive_DB() {
53 volatile int inhibit_comdat
= __LINE__
;
54 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
58 NOINLINE
void ThreadUnresponsive_FILE() {
59 volatile int inhibit_comdat
= __LINE__
;
60 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
64 NOINLINE
void ThreadUnresponsive_FILE_USER_BLOCKING() {
65 volatile int inhibit_comdat
= __LINE__
;
66 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
70 NOINLINE
void ThreadUnresponsive_PROCESS_LAUNCHER() {
71 volatile int inhibit_comdat
= __LINE__
;
72 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
76 NOINLINE
void ThreadUnresponsive_CACHE() {
77 volatile int inhibit_comdat
= __LINE__
;
78 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
82 NOINLINE
void ThreadUnresponsive_IO() {
83 volatile int inhibit_comdat
= __LINE__
;
84 ALLOW_UNUSED_LOCAL(inhibit_comdat
);
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.
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
111 MSVC_ENABLE_OPTIMIZE();