Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 22836004: Chrome tracing for system-wide performance stats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@asvalue
Patch Set: changed GetCurrent to Sample Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/browser_main_loop.h" 5 #include "content/browser/browser_main_loop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/file_util.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
14 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
15 #include "base/path_service.h"
16 #include "base/pending_task.h" 14 #include "base/pending_task.h"
17 #include "base/power_monitor/power_monitor.h" 15 #include "base/power_monitor/power_monitor.h"
18 #include "base/power_monitor/power_monitor_device_source.h" 16 #include "base/power_monitor/power_monitor_device_source.h"
19 #include "base/process/process_metrics.h" 17 #include "base/process/process_metrics.h"
20 #include "base/run_loop.h" 18 #include "base/run_loop.h"
21 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
22 #include "base/system_monitor/system_monitor.h" 20 #include "base/system_monitor/system_monitor.h"
23 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
24 #include "base/timer/hi_res_timer_manager.h" 22 #include "base/timer/hi_res_timer_manager.h"
23 #include "base/debug/trace_event_system_stats_monitor.h"
25 #include "content/browser/browser_thread_impl.h" 24 #include "content/browser/browser_thread_impl.h"
26 #include "content/browser/device_orientation/device_motion_service.h" 25 #include "content/browser/device_orientation/device_motion_service.h"
27 #include "content/browser/download/save_file_manager.h" 26 #include "content/browser/download/save_file_manager.h"
28 #include "content/browser/gamepad/gamepad_service.h" 27 #include "content/browser/gamepad/gamepad_service.h"
29 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 28 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
30 #include "content/browser/gpu/gpu_data_manager_impl.h" 29 #include "content/browser/gpu/gpu_data_manager_impl.h"
31 #include "content/browser/gpu/gpu_process_host.h" 30 #include "content/browser/gpu/gpu_process_host.h"
32 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 31 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
33 #include "content/browser/histogram_synchronizer.h" 32 #include "content/browser/histogram_synchronizer.h"
34 #include "content/browser/loader/resource_dispatcher_host_impl.h" 33 #include "content/browser/loader/resource_dispatcher_host_impl.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 #endif 115 #endif
117 116
118 namespace content { 117 namespace content {
119 namespace { 118 namespace {
120 119
121 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 120 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
122 void SetupSandbox(const CommandLine& parsed_command_line) { 121 void SetupSandbox(const CommandLine& parsed_command_line) {
123 TRACE_EVENT0("startup", "SetupSandbox"); 122 TRACE_EVENT0("startup", "SetupSandbox");
124 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this 123 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this
125 // code en masse out of chrome_main for now. 124 // code en masse out of chrome_main for now.
126 base::FilePath sandbox_binary; 125 const char* sandbox_binary = NULL;
127 bool env_chrome_devel_sandbox_set = false;
128 struct stat st; 126 struct stat st;
129 127
128 // In Chromium branded builds, developers can set an environment variable to
129 // use the development sandbox. See
130 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
131 if (stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid())
132 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX");
133
134 #if defined(LINUX_SANDBOX_PATH)
135 if (!sandbox_binary)
136 sandbox_binary = LINUX_SANDBOX_PATH;
137 #endif
138
130 const bool want_setuid_sandbox = 139 const bool want_setuid_sandbox =
131 !parsed_command_line.HasSwitch(switches::kNoSandbox) && 140 !parsed_command_line.HasSwitch(switches::kNoSandbox) &&
132 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); 141 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox);
133 142
134 if (want_setuid_sandbox) { 143 if (want_setuid_sandbox) {
135 base::FilePath exe_dir;
136 if (PathService::Get(base::DIR_EXE, &exe_dir)) {
137 base::FilePath sandbox_candidate = exe_dir.AppendASCII("chrome-sandbox");
138 if (base::PathExists(sandbox_candidate))
139 sandbox_binary = sandbox_candidate;
140 }
141
142 // In user-managed builds, including development builds, an environment
143 // variable is required to enable the sandbox. See
144 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
145 if (sandbox_binary.empty() &&
146 stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) {
147 const char* devel_sandbox_path = getenv("CHROME_DEVEL_SANDBOX");
148 if (devel_sandbox_path) {
149 env_chrome_devel_sandbox_set = true;
150 sandbox_binary = base::FilePath(devel_sandbox_path);
151 }
152 }
153
154 static const char no_suid_error[] = "Running without the SUID sandbox! See " 144 static const char no_suid_error[] = "Running without the SUID sandbox! See "
155 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " 145 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment "
156 "for more information on developing with the sandbox on."; 146 "for more information on developing with the sandbox on.";
157 if (sandbox_binary.empty()) { 147 if (!sandbox_binary) {
158 if (!env_chrome_devel_sandbox_set) { 148 // This needs to be fatal. Talk to security@chromium.org if you feel
159 // This needs to be fatal. Talk to security@chromium.org if you feel 149 // otherwise.
160 // otherwise. 150 LOG(FATAL) << no_suid_error;
161 LOG(FATAL) << no_suid_error; 151 }
162 } 152 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as
153 // opposed to a non existing one) is not fatal yet. This is needed because
154 // of existing bots and scripts. Fix it (crbug.com/245376).
155 if (sandbox_binary && *sandbox_binary == '\0')
156 LOG(ERROR) << no_suid_error;
157 }
163 158
164 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as 159 std::string sandbox_cmd;
165 // opposed to a non existing one) is not fatal yet. This is needed 160 if (want_setuid_sandbox && sandbox_binary) {
166 // because of existing bots and scripts. Fix it (crbug.com/245376). 161 sandbox_cmd = sandbox_binary;
167 LOG(ERROR) << no_suid_error;
168 }
169 } 162 }
170 163
171 // Tickle the sandbox host and zygote host so they fork now. 164 // Tickle the sandbox host and zygote host so they fork now.
172 RenderSandboxHostLinux::GetInstance()->Init(sandbox_binary.value()); 165 RenderSandboxHostLinux::GetInstance()->Init(sandbox_cmd);
173 ZygoteHostImpl::GetInstance()->Init(sandbox_binary.value()); 166 ZygoteHostImpl::GetInstance()->Init(sandbox_cmd);
174 } 167 }
175 #endif 168 #endif
176 169
177 #if defined(OS_LINUX) || defined(OS_OPENBSD) 170 #if defined(OS_LINUX) || defined(OS_OPENBSD)
178 static void GLibLogHandler(const gchar* log_domain, 171 static void GLibLogHandler(const gchar* log_domain,
179 GLogLevelFlags log_level, 172 GLogLevelFlags log_level,
180 const gchar* message, 173 const gchar* message,
181 gpointer userdata) { 174 gpointer userdata) {
182 if (!log_domain) 175 if (!log_domain)
183 log_domain = "<unknown>"; 176 log_domain = "<unknown>";
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl()); 475 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl());
483 } 476 }
484 #endif 477 #endif
485 478
486 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) { 479 if (parsed_command_line_.HasSwitch(switches::kMemoryMetrics)) {
487 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:MemoryObserver") 480 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:MemoryObserver")
488 memory_observer_.reset(new MemoryObserver()); 481 memory_observer_.reset(new MemoryObserver());
489 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get()); 482 base::MessageLoop::current()->AddTaskObserver(memory_observer_.get());
490 } 483 }
491 484
485 system_stats_monitor_.reset(new base::debug::TraceEventSystemStatsMonitor(
486 base::MessageLoop::current()->message_loop_proxy()));
492 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) 487 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED)
493 trace_memory_controller_.reset(new base::debug::TraceMemoryController( 488 trace_memory_controller_.reset(new base::debug::TraceMemoryController(
494 base::MessageLoop::current()->message_loop_proxy(), 489 base::MessageLoop::current()->message_loop_proxy(),
495 ::HeapProfilerWithPseudoStackStart, 490 ::HeapProfilerWithPseudoStackStart,
496 ::HeapProfilerStop, 491 ::HeapProfilerStop,
497 ::GetHeapProfile)); 492 ::GetHeapProfile));
498 #endif 493 #endif
499 } 494 }
500 495
501 int BrowserMainLoop::PreCreateThreads() { 496 int BrowserMainLoop::PreCreateThreads() {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 base::ThreadRestrictions::SetIOAllowed(true); 682 base::ThreadRestrictions::SetIOAllowed(true);
688 BrowserThread::PostTask( 683 BrowserThread::PostTask(
689 BrowserThread::IO, FROM_HERE, 684 BrowserThread::IO, FROM_HERE,
690 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 685 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
691 true)); 686 true));
692 687
693 if (parts_) 688 if (parts_)
694 parts_->PostMainMessageLoopRun(); 689 parts_->PostMainMessageLoopRun();
695 690
696 trace_memory_controller_.reset(); 691 trace_memory_controller_.reset();
692 system_stats_monitor_.reset();
697 693
698 #if !defined(OS_IOS) 694 #if !defined(OS_IOS)
699 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to 695 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to
700 // delete related objects on the GPU thread. This must be done before 696 // delete related objects on the GPU thread. This must be done before
701 // stopping the GPU thread. The GPU thread will close IPC channels to renderer 697 // stopping the GPU thread. The GPU thread will close IPC channels to renderer
702 // processes so this has to happen before stopping the IO thread. 698 // processes so this has to happen before stopping the IO thread.
703 GpuProcessHostUIShim::DestroyAll(); 699 GpuProcessHostUIShim::DestroyAll();
704 700
705 // Cancel pending requests and prevent new requests. 701 // Cancel pending requests and prevent new requests.
706 if (resource_dispatcher_host_) 702 if (resource_dispatcher_host_)
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 if (parameters_.ui_task) 964 if (parameters_.ui_task)
969 base::MessageLoopForUI::current()->PostTask(FROM_HERE, 965 base::MessageLoopForUI::current()->PostTask(FROM_HERE,
970 *parameters_.ui_task); 966 *parameters_.ui_task);
971 967
972 base::RunLoop run_loop; 968 base::RunLoop run_loop;
973 run_loop.Run(); 969 run_loop.Run();
974 #endif 970 #endif
975 } 971 }
976 972
977 } // namespace content 973 } // namespace content
OLDNEW
« base/debug/trace_event_system_stats_monitor.cc ('K') | « content/browser/browser_main_loop.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698