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() {
23 base::debug::DumpWithoutCrashing();
25 base::debug::BreakDebugger();
29 #if !defined(OS_ANDROID) || !defined(NDEBUG)
30 // TODO(rtenneti): Enabled crashing, after getting data.
31 NOINLINE
void StartupHang() {
36 NOINLINE
void ShutdownHang() {
40 NOINLINE
void ThreadUnresponsive_UI() {
44 NOINLINE
void ThreadUnresponsive_DB() {
48 NOINLINE
void ThreadUnresponsive_FILE() {
52 NOINLINE
void ThreadUnresponsive_FILE_USER_BLOCKING() {
56 NOINLINE
void ThreadUnresponsive_PROCESS_LAUNCHER() {
60 NOINLINE
void ThreadUnresponsive_CACHE() {
64 NOINLINE
void ThreadUnresponsive_IO() {
68 NOINLINE
void CrashBecauseThreadWasUnresponsive(int thread_id
) {
69 // TODO(rtenneti): The following is a temporary change to check thread_id
70 // numbers explicitly so that we will have minimum code. Will change after the
71 // test run to use content::BrowserThread::ID enum.
73 return ThreadUnresponsive_UI();
74 else if (thread_id
== 1)
75 return ThreadUnresponsive_DB();
76 else if (thread_id
== 2)
77 return ThreadUnresponsive_FILE();
78 else if (thread_id
== 3)
79 return ThreadUnresponsive_FILE_USER_BLOCKING();
80 else if (thread_id
== 4)
81 return ThreadUnresponsive_PROCESS_LAUNCHER();
82 else if (thread_id
== 5)
83 return ThreadUnresponsive_CACHE();
84 else if (thread_id
== 6)
85 return ThreadUnresponsive_IO();
88 } // namespace metrics
91 MSVC_ENABLE_OPTIMIZE();