ThreadWatcher - disable optimizations for ThreadWatcher block of
[chromium-blink-merge.git] / chrome / browser / metrics / thread_watcher_report_hang.cc
blobfd23414bb06a356ac0f68aaeadf09a899899bfde
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 #if defined(NDEBUG)
23 base::debug::DumpWithoutCrashing();
24 #else
25 base::debug::BreakDebugger();
26 #endif
29 #if !defined(OS_ANDROID) || !defined(NDEBUG)
30 // TODO(rtenneti): Enabled crashing, after getting data.
31 NOINLINE void StartupHang() {
32 ReportThreadHang();
34 #endif // OS_ANDROID
36 NOINLINE void ShutdownHang() {
37 ReportThreadHang();
40 NOINLINE void ThreadUnresponsive_UI() {
41 ReportThreadHang();
44 NOINLINE void ThreadUnresponsive_DB() {
45 ReportThreadHang();
48 NOINLINE void ThreadUnresponsive_FILE() {
49 ReportThreadHang();
52 NOINLINE void ThreadUnresponsive_FILE_USER_BLOCKING() {
53 ReportThreadHang();
56 NOINLINE void ThreadUnresponsive_PROCESS_LAUNCHER() {
57 ReportThreadHang();
60 NOINLINE void ThreadUnresponsive_CACHE() {
61 ReportThreadHang();
64 NOINLINE void ThreadUnresponsive_IO() {
65 ReportThreadHang();
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.
72 if (thread_id == 0)
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
90 MSVC_POP_WARNING()
91 MSVC_ENABLE_OPTIMIZE();