[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}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
9a1b229f41
commit
44d8036a9d
content
services/tracing/public/cpp
ui/gl
@ -47,17 +47,15 @@ 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() {
|
||||
void EnableStartupTracingIfNeeded(bool with_thread) {
|
||||
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
|
||||
@ -66,6 +64,14 @@ void EnableStartupTracingIfNeeded() {
|
||||
// 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();
|
||||
@ -106,7 +112,9 @@ void InitTracingPostFeatureList(bool enable_consumer) {
|
||||
DCHECK(base::FeatureList::GetInstance());
|
||||
|
||||
// Create the PerfettoTracedProcess.
|
||||
PerfettoTracedProcess::MaybeCreateInstance();
|
||||
if (!g_tracing_with_thread) {
|
||||
PerfettoTracedProcess::MaybeCreateInstance();
|
||||
}
|
||||
PerfettoTracedProcess::Get().OnThreadPoolAvailable(enable_consumer);
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
tracing::EnableETWExport();
|
||||
|
@ -35,7 +35,8 @@ 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();
|
||||
void COMPONENT_EXPORT(TRACING_CPP)
|
||||
EnableStartupTracingIfNeeded(bool with_thread = false);
|
||||
|
||||
// Enable startup tracing for the current process with the provided config. Sets
|
||||
// up ProducerClient and trace event and/or sampler profiler data sources, and
|
||||
|
Reference in New Issue
Block a user