Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / metrics / thread_watcher_report_hang.cc
blobde6b20041fac1f4463bb20b16cdb5a33470f4e14
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 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();
39 #endif // OS_ANDROID
41 NOINLINE void ShutdownHang() {
42 volatile int inhibit_comdat = __LINE__;
43 ALLOW_UNUSED_LOCAL(inhibit_comdat);
44 ReportThreadHang();
47 NOINLINE void ThreadUnresponsive_UI() {
48 volatile int inhibit_comdat = __LINE__;
49 ALLOW_UNUSED_LOCAL(inhibit_comdat);
50 ReportThreadHang();
53 NOINLINE void ThreadUnresponsive_DB() {
54 volatile int inhibit_comdat = __LINE__;
55 ALLOW_UNUSED_LOCAL(inhibit_comdat);
56 ReportThreadHang();
59 NOINLINE void ThreadUnresponsive_FILE() {
60 volatile int inhibit_comdat = __LINE__;
61 ALLOW_UNUSED_LOCAL(inhibit_comdat);
62 ReportThreadHang();
65 NOINLINE void ThreadUnresponsive_FILE_USER_BLOCKING() {
66 volatile int inhibit_comdat = __LINE__;
67 ALLOW_UNUSED_LOCAL(inhibit_comdat);
68 ReportThreadHang();
71 NOINLINE void ThreadUnresponsive_PROCESS_LAUNCHER() {
72 volatile int inhibit_comdat = __LINE__;
73 ALLOW_UNUSED_LOCAL(inhibit_comdat);
74 ReportThreadHang();
77 NOINLINE void ThreadUnresponsive_CACHE() {
78 volatile int inhibit_comdat = __LINE__;
79 ALLOW_UNUSED_LOCAL(inhibit_comdat);
80 ReportThreadHang();
83 NOINLINE void ThreadUnresponsive_IO() {
84 volatile int inhibit_comdat = __LINE__;
85 ALLOW_UNUSED_LOCAL(inhibit_comdat);
86 ReportThreadHang();
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.
93 if (thread_id == 0)
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
111 MSVC_POP_WARNING()
112 MSVC_ENABLE_OPTIMIZE();