tracing: Enable startup tracing in zygote children after mojo is up
We're refactoring startup tracing in Chrome, see design doc[1]. With the new startup tracing architecture, each process needs to allocate a shared memory buffer when enabling startup tracing. In zygote child processes, this is only possible after mojo's IPC support is brought up, because the mojo broker has to create the buffer on the process's behalf (the zygote sandbox prevents the child processes from doing this themselves). To prepare for the startup tracing refactor, this patch moves startup tracing initialization for zygote child processes from ContentMainRunner to their respective main functions, until after mojo is brought up by the respective ChildThreadImpl subclass. We should only lose minimal tracing data due to this change (from the early part of the respective main function), and only from zygote children (primarily renderer + utility processes) on Linux/ChromeOS. [1] https://docs.google.com/document/d/1FygJQbD29vMkfVfT7m0Lb1u1zZZU1VgXAPi_R0uBoTw/edit?usp=sharing Bug: 1006753 Change-Id: I59c21b2b383c755925dc5ff0c19160985e089800 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2038574 Reviewed-by: Avi Drissman <avi@chromium.org> Reviewed-by: Sami Kyöstilä <skyostil@chromium.org> Commit-Queue: Eric Seckler <eseckler@chromium.org> Cr-Commit-Position: refs/heads/master@{#739869}
This commit is contained in:
content
app
ppapi_plugin
renderer
utility
@ -481,10 +481,6 @@ int RunZygote(ContentMainDelegate* delegate) {
|
||||
command_line.GetSwitchValueASCII(switches::kProcessType);
|
||||
ContentClientInitializer::Set(process_type, delegate);
|
||||
|
||||
#if !defined(OS_ANDROID)
|
||||
tracing::EnableStartupTracingIfNeeded();
|
||||
#endif // !OS_ANDROID
|
||||
|
||||
MainFunctionParams main_params(command_line);
|
||||
main_params.zygote_child = true;
|
||||
|
||||
|
@ -7,4 +7,5 @@ include_rules = [
|
||||
"+ppapi/proxy",
|
||||
"+services/service_manager/public/cpp",
|
||||
"+services/service_manager/sandbox",
|
||||
"+services/tracing/public",
|
||||
]
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "ipc/ipc_sender.h"
|
||||
#include "ppapi/proxy/plugin_globals.h"
|
||||
#include "ppapi/proxy/proxy_module.h"
|
||||
#include "services/tracing/public/cpp/trace_startup.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
@ -132,6 +133,15 @@ int PpapiPluginMain(const MainFunctionParams& parameters) {
|
||||
parameters.command_line,
|
||||
false /* Not a broker */));
|
||||
|
||||
#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
|
||||
// Startup tracing is usually enabled earlier, but if we forked from a zygote,
|
||||
// we can only enable it after mojo IPC support is brought up by PpapiThread,
|
||||
// because the mojo broker has to create the tracing SMB on our behalf due to
|
||||
// the zygote sandbox.
|
||||
if (parameters.zygote_child)
|
||||
tracing::EnableStartupTracingIfNeeded();
|
||||
#endif // OS_POSIX && !OS_ANDROID && !!OS_MACOSX
|
||||
|
||||
#if defined(OS_WIN)
|
||||
if (!base::win::IsUser32AndGdi32Available())
|
||||
gfx::win::InitializeDirectWrite();
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "ppapi/buildflags/buildflags.h"
|
||||
#include "services/service_manager/sandbox/switches.h"
|
||||
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
|
||||
#include "services/tracing/public/cpp/trace_startup.h"
|
||||
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
|
||||
#include "third_party/webrtc_overrides/init_webrtc.h" // nogncheck
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
@ -98,7 +99,7 @@ std::unique_ptr<base::MessagePump> CreateMainThreadMessagePump() {
|
||||
int RendererMain(const MainFunctionParams& parameters) {
|
||||
// Don't use the TRACE_EVENT0 macro because the tracing infrastructure doesn't
|
||||
// expect synchronous events around the main loop of a thread.
|
||||
TRACE_EVENT_ASYNC_BEGIN0("startup", "RendererMain", 0);
|
||||
TRACE_EVENT_ASYNC_BEGIN1("startup", "RendererMain", 0, "zygote_child", false);
|
||||
|
||||
base::trace_event::TraceLog::GetInstance()->set_process_name("Renderer");
|
||||
base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
|
||||
@ -191,6 +192,18 @@ int RendererMain(const MainFunctionParams& parameters) {
|
||||
new RenderThreadImpl(run_loop.QuitClosure(),
|
||||
std::move(main_thread_scheduler));
|
||||
|
||||
#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
|
||||
// Startup tracing is usually enabled earlier, but if we forked from a
|
||||
// zygote, we can only enable it after mojo IPC support is brought up
|
||||
// initialized by RenderThreadImpl, because the mojo broker has to create
|
||||
// the tracing SMB on our behalf due to the zygote sandbox.
|
||||
if (parameters.zygote_child) {
|
||||
tracing::EnableStartupTracingIfNeeded();
|
||||
TRACE_EVENT_ASYNC_BEGIN1("startup", "RendererMain", 0, "zygote_child",
|
||||
true);
|
||||
}
|
||||
#endif // OS_POSIX && !OS_ANDROID && !!OS_MACOSX
|
||||
|
||||
// Setup tracing sampler profiler as early as possible.
|
||||
auto tracing_sampler_profiler =
|
||||
tracing::TracingSamplerProfiler::CreateOnMainThread();
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "content/public/common/sandbox_init.h"
|
||||
#include "content/utility/utility_thread_impl.h"
|
||||
#include "services/service_manager/sandbox/sandbox.h"
|
||||
#include "services/tracing/public/cpp/trace_startup.h"
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
#include "content/utility/soda/soda_sandbox_hook_linux.h"
|
||||
@ -110,6 +111,15 @@ int UtilityMain(const MainFunctionParams& parameters) {
|
||||
utility_process.set_main_thread(
|
||||
new UtilityThreadImpl(run_loop.QuitClosure()));
|
||||
|
||||
#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
|
||||
// Startup tracing is usually enabled earlier, but if we forked from a zygote,
|
||||
// we can only enable it after mojo IPC support is brought up initialized by
|
||||
// UtilityThreadImpl, because the mojo broker has to create the tracing SMB on
|
||||
// our behalf due to the zygote sandbox.
|
||||
if (parameters.zygote_child)
|
||||
tracing::EnableStartupTracingIfNeeded();
|
||||
#endif // OS_POSIX && !OS_ANDROID && !!OS_MACOSX
|
||||
|
||||
// Both utility process and service utility process would come
|
||||
// here, but the later is launched without connection to service manager, so
|
||||
// there has no base::PowerMonitor be created(See ChildThreadImpl::Init()).
|
||||
|
Reference in New Issue
Block a user