| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "app/gfx/gl/gl_context.h" | 8 #include "app/gfx/gl/gl_context.h" |
| 9 #include "app/gfx/gl/gl_implementation.h" | 9 #include "app/gfx/gl/gl_implementation.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/metrics/field_trial.h" | |
| 13 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 14 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 15 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/env_vars.h" | 16 #include "chrome/common/env_vars.h" |
| 18 #include "chrome/common/main_function_params.h" | 17 #include "chrome/common/main_function_params.h" |
| 19 #include "chrome/gpu/gpu_config.h" | 18 #include "chrome/gpu/gpu_config.h" |
| 20 #include "chrome/gpu/gpu_process.h" | 19 #include "chrome/gpu/gpu_process.h" |
| 21 #include "chrome/gpu/gpu_thread.h" | 20 #include "chrome/gpu/gpu_thread.h" |
| 22 #include "chrome/gpu/gpu_watchdog_thread.h" | 21 #include "chrome/gpu/gpu_watchdog_thread.h" |
| 23 | 22 |
| 24 #if defined(USE_LINUX_BREAKPAD) | 23 #if defined(USE_LINUX_BREAKPAD) |
| 25 #include "chrome/app/breakpad_linux.h" | 24 #include "chrome/app/breakpad_linux.h" |
| 26 #endif | 25 #endif |
| 27 | 26 |
| 28 #if defined(OS_MACOSX) | 27 #if defined(OS_MACOSX) |
| 29 #include "chrome/common/sandbox_mac.h" | 28 #include "chrome/common/sandbox_mac.h" |
| 30 #endif | 29 #endif |
| 31 | 30 |
| 32 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 33 #include "app/win_util.h" | 32 #include "app/win_util.h" |
| 34 #endif | 33 #endif |
| 35 | 34 |
| 36 #if defined(USE_X11) | 35 #if defined(USE_X11) |
| 37 #include "gfx/gtk_util.h" | 36 #include "gfx/gtk_util.h" |
| 38 #endif | 37 #endif |
| 39 | 38 |
| 40 // 1% per watchdog trial group. | 39 const int kGpuTimeout = 10000; |
| 41 const int kFieldTrialSize = 1; | |
| 42 | |
| 43 // 5 - 20 seconds timeout. | |
| 44 const int kMinGpuTimeout = 5; | |
| 45 const int kMaxGpuTimeout = 20; | |
| 46 | 40 |
| 47 namespace { | 41 namespace { |
| 48 | 42 |
| 49 bool InitializeGpuSandbox() { | 43 bool InitializeGpuSandbox() { |
| 50 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
| 51 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess(); | 45 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess(); |
| 52 SandboxInitWrapper sandbox_wrapper; | 46 SandboxInitWrapper sandbox_wrapper; |
| 53 return sandbox_wrapper.InitializeSandbox(*parsed_command_line, | 47 return sandbox_wrapper.InitializeSandbox(*parsed_command_line, |
| 54 switches::kGpuProcess); | 48 switches::kGpuProcess); |
| 55 #else | 49 #else |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 111 |
| 118 // Do this soon before running the message loop so accurate | 112 // Do this soon before running the message loop so accurate |
| 119 // initialization time is recorded in the GPU info. Don't do it before | 113 // initialization time is recorded in the GPU info. Don't do it before |
| 120 // starting the watchdog thread since it can take a significant amount of | 114 // starting the watchdog thread since it can take a significant amount of |
| 121 // time to collect GPU information in GpuThread::Init. | 115 // time to collect GPU information in GpuThread::Init. |
| 122 GpuProcess gpu_process; | 116 GpuProcess gpu_process; |
| 123 GpuThread* gpu_thread = new GpuThread; | 117 GpuThread* gpu_thread = new GpuThread; |
| 124 gpu_thread->Init(start_time); | 118 gpu_thread->Init(start_time); |
| 125 gpu_process.set_main_thread(gpu_thread); | 119 gpu_process.set_main_thread(gpu_thread); |
| 126 | 120 |
| 127 // Only enable this experimental feaure for a subset of users. | |
| 128 scoped_refptr<base::FieldTrial> watchdog_trial( | |
| 129 new base::FieldTrial("GpuWatchdogTrial", 100)); | |
| 130 int watchdog_timeout = 0; | |
| 131 for (int i = kMinGpuTimeout; i <= kMaxGpuTimeout; ++i) { | |
| 132 int group = watchdog_trial->AppendGroup(StringPrintf("%dsecs", i), | |
| 133 kFieldTrialSize); | |
| 134 if (group == watchdog_trial->group()) { | |
| 135 watchdog_timeout = i; | |
| 136 break; | |
| 137 } | |
| 138 } | |
| 139 | 121 |
| 140 // In addition to disabling the watchdog if the command line switch is | 122 // In addition to disabling the watchdog if the command line switch is |
| 141 // present, disable it in two other cases. OSMesa is expected to run very | 123 // present, disable it in two other cases. OSMesa is expected to run very |
| 142 // slowly. Also disable the watchdog on valgrind because the code is expected | 124 // slowly. Also disable the watchdog on valgrind because the code is expected |
| 143 // to run slowly in that case. | 125 // to run slowly in that case. |
| 144 bool enable_watchdog = | 126 bool enable_watchdog = |
| 145 watchdog_timeout != 0 && | |
| 146 !command_line.HasSwitch(switches::kDisableGpuWatchdog) && | 127 !command_line.HasSwitch(switches::kDisableGpuWatchdog) && |
| 147 gfx::GetGLImplementation() != gfx::kGLImplementationOSMesaGL && | 128 gfx::GetGLImplementation() != gfx::kGLImplementationOSMesaGL && |
| 148 !RunningOnValgrind(); | 129 !RunningOnValgrind(); |
| 149 | 130 |
| 150 // Disable the watchdog in debug builds because they tend to only be run by | 131 // Disable the watchdog in debug builds because they tend to only be run by |
| 151 // developers who will not appreciate the watchdog killing the GPU process. | 132 // developers who will not appreciate the watchdog killing the GPU process. |
| 152 #ifndef NDEBUG | 133 #ifndef NDEBUG |
| 153 enable_watchdog = false; | 134 enable_watchdog = false; |
| 154 #endif | 135 #endif |
| 155 | 136 |
| 137 // Disable the watchdog for Windows. It tends to abort when the GPU process |
| 138 // is not hung but still taking a long time to do something. Instead, the |
| 139 // browser process displays a dialog when it notices that the child window |
| 140 // is hung giving the user an opportunity to terminate it. This is the |
| 141 // same mechanism used to abort hung plugins. |
| 142 #if defined(OS_WIN) |
| 143 enable_watchdog = false; |
| 144 #endif |
| 145 |
| 156 // Start the GPU watchdog only after anything that is expected to be time | 146 // Start the GPU watchdog only after anything that is expected to be time |
| 157 // consuming has completed, otherwise the process is liable to be aborted. | 147 // consuming has completed, otherwise the process is liable to be aborted. |
| 158 scoped_refptr<GpuWatchdogThread> watchdog_thread; | 148 scoped_refptr<GpuWatchdogThread> watchdog_thread; |
| 159 if (enable_watchdog) { | 149 if (enable_watchdog) { |
| 160 watchdog_thread = new GpuWatchdogThread(watchdog_timeout * 1000); | 150 watchdog_thread = new GpuWatchdogThread(kGpuTimeout); |
| 161 watchdog_thread->Start(); | 151 watchdog_thread->Start(); |
| 162 } | 152 } |
| 163 | 153 |
| 164 main_message_loop.Run(); | 154 main_message_loop.Run(); |
| 165 | 155 |
| 166 if (enable_watchdog) | 156 if (enable_watchdog) |
| 167 watchdog_thread->Stop(); | 157 watchdog_thread->Stop(); |
| 168 | 158 |
| 169 return 0; | 159 return 0; |
| 170 } | 160 } |
| OLD | NEW |