Revert "[tracing] Use trace thread for gpu process to initialize tracing"
This reverts commit 44d8036a9d
.
Reason for revert: This is likely causing failures in a ChromeOS perfetto test. b/401194534.
Original change's description:
> [tracing] Use trace thread for gpu process to initialize tracing
>
> For non-zygote child gpu thread, start the trace thread in
> ContentMainRunnerImpl() directly.
>
> For zygote child gpu thread, start the trace thread in RunZygote after
> zygote fork and featurelist init.
>
> For Linux & ChromeOS, stop and restart the trace thread when entering
> sandbox. Restarting trace thread has a caveat that delayed tasks would
> will be lost unless we save them.
>
> This is [3/?] CL of enabling tracing prior to sandboxing.
>
> Bug: 380411640
> Change-Id: I89fa94f63a709de0e3da4f8759098c9fff813bee
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180639
> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
> Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org>
> Commit-Queue: Kramer Ge <fangzhoug@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1428704}
Bug: 380411640
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I810beb2c5903951b78d69f30c050f1797c8b28cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6334493
Owners-Override: Scott Haseley <shaseley@google.com>
Commit-Queue: Scott Haseley <shaseley@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1429173}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
ca8fa3d68d
commit
e0d4e34c2c
content
services/tracing/public/cpp
ui/gl
@ -658,18 +658,7 @@ NO_STACK_PROTECTOR int RunZygote(ContentMainDelegate* delegate) {
|
||||
|
||||
MainFunctionParams main_params(command_line);
|
||||
main_params.zygote_child = true;
|
||||
|
||||
if (process_type == switches::kGpuProcess) {
|
||||
// Once Zygote forks and feature list initializes we can start a thread to
|
||||
// begin tracing immediately.
|
||||
// TODO(https://crbug.com/380411640): Enable for more processes other than
|
||||
// GPU process.
|
||||
tracing::EnableStartupTracingIfNeeded(/*with_thread=*/true);
|
||||
tracing::InitTracingPostFeatureList(/*enable_consumer=*/false);
|
||||
main_params.needs_startup_tracing_after_mojo_init = false;
|
||||
} else {
|
||||
main_params.needs_startup_tracing_after_mojo_init = true;
|
||||
}
|
||||
main_params.needs_startup_tracing_after_mojo_init = true;
|
||||
|
||||
// The hang watcher needs to be created once the feature list is available
|
||||
// but before the IO thread is started.
|
||||
@ -899,27 +888,15 @@ int ContentMainRunnerImpl::Initialize(ContentMainParams params) {
|
||||
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC)
|
||||
// A sandboxed process won't be able to allocate the SMB needed for startup
|
||||
// tracing until Mojo IPC support is brought up, at which point the Mojo
|
||||
// broker will transparently broker the SMB creation. Unless the sandboxed
|
||||
// process stops the trace threads when entering sandbox.
|
||||
// TODO(https://crbug.com/380411640): Implement for other processes other than
|
||||
// GPU process.
|
||||
if (process_type != switches::kGpuProcess &&
|
||||
!sandbox::policy::IsUnsandboxedSandboxType(
|
||||
// broker will transparently broker the SMB creation.
|
||||
if (!sandbox::policy::IsUnsandboxedSandboxType(
|
||||
sandbox::policy::SandboxTypeFromCommandLine(command_line))) {
|
||||
enable_startup_tracing = false;
|
||||
needs_startup_tracing_after_mojo_init_ = true;
|
||||
}
|
||||
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC)
|
||||
if (enable_startup_tracing) {
|
||||
if (process_type == switches::kGpuProcess) {
|
||||
// Without Zygote and posix sandbox we can start a thread to begin tracing
|
||||
// immediately.
|
||||
// TODO(https://crbug.com/380411640): Enable for more processes other than
|
||||
// GPU process.
|
||||
tracing::EnableStartupTracingIfNeeded(/*with_thread=*/true);
|
||||
} else {
|
||||
tracing::EnableStartupTracingIfNeeded(/*with_thread=*/false);
|
||||
}
|
||||
tracing::EnableStartupTracingIfNeeded();
|
||||
}
|
||||
TRACE_EVENT0("startup,benchmark,rail", "ContentMainRunnerImpl::Initialize");
|
||||
|
||||
@ -1135,9 +1112,6 @@ NO_STACK_PROTECTOR int ContentMainRunnerImpl::Run() {
|
||||
ContentMainDelegate::InvokedInChildProcess())) {
|
||||
InitializeFieldTrialAndFeatureList();
|
||||
}
|
||||
if (process_type == switches::kGpuProcess) {
|
||||
tracing::InitTracingPostFeatureList(/*enable_consumer=*/false);
|
||||
}
|
||||
if (delegate_->ShouldInitializeMojo(
|
||||
ContentMainDelegate::InvokedInChildProcess())) {
|
||||
InitializeMojoCore();
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "base/task/single_thread_task_executor.h"
|
||||
#include "base/task/thread_pool/thread_pool_instance.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/timer/hi_res_timer_manager.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
@ -45,7 +44,6 @@
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "content/public/common/result_codes.h"
|
||||
#include "content/public/common/zygote/zygote_buildflags.h"
|
||||
#include "content/public/gpu/content_gpu_client.h"
|
||||
#include "gpu/command_buffer/service/gpu_switches.h"
|
||||
#include "gpu/config/gpu_driver_bug_list.h"
|
||||
@ -61,7 +59,6 @@
|
||||
#include "media/gpu/buildflags.h"
|
||||
#include "mojo/public/cpp/bindings/interface_endpoint_client.h"
|
||||
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
|
||||
#include "services/tracing/public/cpp/perfetto/perfetto_traced_process.h"
|
||||
#include "services/tracing/public/cpp/trace_startup.h"
|
||||
#include "services/tracing/public/cpp/trace_startup_config.h"
|
||||
#include "third_party/angle/src/gpu_info_util/SystemInfo.h"
|
||||
@ -209,8 +206,11 @@ void LoadMetalShaderCacheIfNecessary() {
|
||||
|
||||
// Main function for starting the Gpu process.
|
||||
int GpuMain(MainFunctionParams parameters) {
|
||||
TRACE_EVENT("gpu,startup", "GpuMain");
|
||||
if (tracing::TraceStartupConfig::GetInstance().IsEnabled()) {
|
||||
gl::StartupTrace::Startup();
|
||||
}
|
||||
|
||||
TRACE_EVENT0("gpu", "GpuMain");
|
||||
base::CurrentProcess::GetInstance().SetProcessType(
|
||||
base::CurrentProcessType::PROCESS_GPU);
|
||||
|
||||
@ -324,6 +324,7 @@ int GpuMain(MainFunctionParams parameters) {
|
||||
base::MessagePumpType::DEFAULT);
|
||||
#endif
|
||||
}
|
||||
gl::StartupTrace::GetInstance()->BindToCurrentThread();
|
||||
|
||||
base::PlatformThread::SetName("CrGpuMain");
|
||||
mojo::InterfaceEndpointClient::SetThreadNameSuffixForMetrics("GpuMain");
|
||||
@ -449,6 +450,7 @@ int GpuMain(MainFunctionParams parameters) {
|
||||
}
|
||||
|
||||
DCHECK(tracing::IsTracingInitialized());
|
||||
gl::StartupTrace::StarupDone();
|
||||
|
||||
{
|
||||
TRACE_EVENT0("gpu", "Run Message Loop");
|
||||
@ -472,14 +474,6 @@ bool StartSandboxLinux(gpu::GpuWatchdogThread* watchdog_thread,
|
||||
sandbox::policy::SandboxLinux::GetInstance()->StopThread(watchdog_thread);
|
||||
}
|
||||
|
||||
base::Thread* trace_thread =
|
||||
tracing::IsTracingInitialized()
|
||||
? tracing::PerfettoTracedProcess::GetTraceThread()
|
||||
: nullptr;
|
||||
if (trace_thread) {
|
||||
sandbox::policy::SandboxLinux::GetInstance()->StopThread(trace_thread);
|
||||
}
|
||||
|
||||
// SandboxLinux::InitializeSandbox() must always be called
|
||||
// with only one thread.
|
||||
sandbox::policy::SandboxLinux::Options sandbox_options;
|
||||
@ -529,10 +523,6 @@ bool StartSandboxLinux(gpu::GpuWatchdogThread* watchdog_thread,
|
||||
watchdog_thread->Start();
|
||||
}
|
||||
|
||||
if (trace_thread) {
|
||||
tracing::PerfettoTracedProcess::RestartThreadInSandbox();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
||||
|
@ -47,15 +47,17 @@ using base::trace_event::TraceLog;
|
||||
} // namespace
|
||||
|
||||
bool g_tracing_initialized_after_featurelist = false;
|
||||
bool g_tracing_with_thread = false;
|
||||
|
||||
bool IsTracingInitialized() {
|
||||
return g_tracing_initialized_after_featurelist;
|
||||
}
|
||||
|
||||
void EnableStartupTracingIfNeeded(bool with_thread) {
|
||||
void EnableStartupTracingIfNeeded() {
|
||||
RegisterTracedValueProtoWriter();
|
||||
|
||||
// Create the PerfettoTracedProcess.
|
||||
PerfettoTracedProcess::MaybeCreateInstance();
|
||||
|
||||
// Initialize the client library's TrackRegistry to support trace points
|
||||
// during startup tracing. We don't setup the client library completely here
|
||||
// yet, because we don't have field trials loaded yet (which influence which
|
||||
@ -64,14 +66,6 @@ void EnableStartupTracingIfNeeded(bool with_thread) {
|
||||
// setting up the client library?
|
||||
perfetto::internal::TrackRegistry::InitializeInstance();
|
||||
|
||||
// Create the PerfettoTracedProcess.
|
||||
if (with_thread) {
|
||||
g_tracing_with_thread = true;
|
||||
PerfettoTracedProcess::MaybeCreateInstanceWithThread();
|
||||
} else {
|
||||
PerfettoTracedProcess::MaybeCreateInstance();
|
||||
}
|
||||
|
||||
// Ensure TraceLog is initialized first.
|
||||
// https://crbug.com/764357
|
||||
TraceLog::GetInstance();
|
||||
@ -112,9 +106,7 @@ void InitTracingPostFeatureList(bool enable_consumer) {
|
||||
DCHECK(base::FeatureList::GetInstance());
|
||||
|
||||
// Create the PerfettoTracedProcess.
|
||||
if (!g_tracing_with_thread) {
|
||||
PerfettoTracedProcess::MaybeCreateInstance();
|
||||
}
|
||||
PerfettoTracedProcess::MaybeCreateInstance();
|
||||
PerfettoTracedProcess::Get().OnThreadPoolAvailable(enable_consumer);
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
tracing::EnableETWExport();
|
||||
|
@ -35,8 +35,7 @@ bool COMPONENT_EXPORT(TRACING_CPP) IsTracingInitialized();
|
||||
// TODO(eseckler): Consider allocating the SMB in parent processes outside the
|
||||
// sandbox and supply it via the command line. Then, we can revert to call this
|
||||
// earlier and from fewer places again.
|
||||
void COMPONENT_EXPORT(TRACING_CPP)
|
||||
EnableStartupTracingIfNeeded(bool with_thread = false);
|
||||
void COMPONENT_EXPORT(TRACING_CPP) EnableStartupTracingIfNeeded();
|
||||
|
||||
// Enable startup tracing for the current process with the provided config. Sets
|
||||
// up ProducerClient and trace event and/or sampler profiler data sources, and
|
||||
|
@ -77,6 +77,20 @@ class GL_EXPORT StartupTrace {
|
||||
|
||||
} // namespace gl
|
||||
|
||||
#define GPU_STARTUP_TRACE_EVENT(name) TRACE_EVENT("gpu,startup", name);
|
||||
// Generate a unique variable name with a given prefix.
|
||||
#define GPU_STARTUP_TRACE_INTERNAL_CONCAT2(a, b) a##b
|
||||
#define GPU_STARTUP_TRACE_INTERNAL_CONCAT(a, b) \
|
||||
GPU_STARTUP_TRACE_INTERNAL_CONCAT2(a, b)
|
||||
#define GPU_STARTUP_TRACE_UID(prefix) \
|
||||
GPU_STARTUP_TRACE_INTERNAL_CONCAT(prefix, __LINE__)
|
||||
|
||||
#define GPU_STARTUP_TRACE_EVENT(name) \
|
||||
gl::StartupTrace::ScopedStage GPU_STARTUP_TRACE_UID(scoped_gpu_trace){0}; \
|
||||
if (gl::StartupTrace::IsEnabled()) { \
|
||||
GPU_STARTUP_TRACE_UID(scoped_gpu_trace) = \
|
||||
gl::StartupTrace::GetInstance()->AddStage(name); \
|
||||
} else { \
|
||||
TRACE_EVENT0("gpu,startup", name); \
|
||||
}
|
||||
|
||||
#endif // UI_GL_STARTUP_TRACE_H_
|
||||
|
Reference in New Issue
Block a user