Commit 71c9d0a0 authored by Stephen Nusko's avatar Stephen Nusko Committed by Commit Bot

Ensure every process calls InitTracingAfterThreadPoolStart.


This adds a global CHECK that ensures we hopefully won't miss new processes as
they are added.

This enables all processes to initialize system tracing as early as possible.

Bug: 979576
Change-Id: Id9d841dad5980cf82e46586238fe682722558cea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1748886
Commit-Queue: Stephen Nusko <nuskos@chromium.org>
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Auto-Submit: Stephen Nusko <nuskos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686469}
parent 05ada90e
...@@ -909,10 +909,10 @@ int ContentMainRunnerImpl::RunServiceManager(MainFunctionParams& main_params, ...@@ -909,10 +909,10 @@ int ContentMainRunnerImpl::RunServiceManager(MainFunctionParams& main_params,
StartBrowserThreadPool(); StartBrowserThreadPool();
} }
tracing::InitTracingPostThreadPoolStart();
BrowserTaskExecutor::PostFeatureListSetup(); BrowserTaskExecutor::PostFeatureListSetup();
tracing::InitTracingPostThreadPoolStartAndFeatureList();
delegate_->PostTaskSchedulerStart(); delegate_->PostTaskSchedulerStart();
if (should_start_service_manager_only) if (should_start_service_manager_only)
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/child/child_thread_impl.h" #include "content/child/child_thread_impl.h"
#include "services/tracing/public/cpp/trace_startup.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
namespace content { namespace content {
...@@ -51,6 +52,7 @@ ChildProcess::ChildProcess(base::ThreadPriority io_thread_priority, ...@@ -51,6 +52,7 @@ ChildProcess::ChildProcess(base::ThreadPriority io_thread_priority,
DCHECK(base::ThreadPoolInstance::Get()); DCHECK(base::ThreadPoolInstance::Get());
initialized_thread_pool_ = true; initialized_thread_pool_ = true;
} }
tracing::InitTracingPostThreadPoolStartAndFeatureList();
// We can't recover from failing to start the IO thread. // We can't recover from failing to start the IO thread.
base::Thread::Options thread_options(base::MessagePumpType::IO, 0); base::Thread::Options thread_options(base::MessagePumpType::IO, 0);
......
...@@ -11,6 +11,7 @@ include_rules = [ ...@@ -11,6 +11,7 @@ include_rules = [
"+services/audio/public/mojom", "+services/audio/public/mojom",
"+services/network", "+services/network",
"+services/service_manager", "+services/service_manager",
"+services/tracing/public/cpp",
"+testing/android/native_test/native_browser_test_support.h", "+testing/android/native_test/native_browser_test_support.h",
"+ui/ozone/public", "+ui/ozone/public",
"+ui/views/test", "+ui/views/test",
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "services/network/public/mojom/network_service_test.mojom.h" #include "services/network/public/mojom/network_service_test.mojom.h"
#include "services/service_manager/embedder/switches.h" #include "services/service_manager/embedder/switches.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "services/tracing/public/cpp/trace_startup.h"
#include "ui/base/platform_window_defaults.h" #include "ui/base/platform_window_defaults.h"
#include "ui/compositor/compositor_switches.h" #include "ui/compositor/compositor_switches.h"
#include "ui/display/display_switches.h" #include "ui/display/display_switches.h"
...@@ -412,6 +413,7 @@ void BrowserTestBase::SetUp() { ...@@ -412,6 +413,7 @@ void BrowserTestBase::SetUp() {
StartBrowserThreadPool(); StartBrowserThreadPool();
BrowserTaskExecutor::PostFeatureListSetup(); BrowserTaskExecutor::PostFeatureListSetup();
tracing::InitTracingPostThreadPoolStartAndFeatureList();
delegate->PostTaskSchedulerStart(); delegate->PostTaskSchedulerStart();
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "services/tracing/public/cpp/perfetto/dummy_producer.h" #include "services/tracing/public/cpp/perfetto/dummy_producer.h"
#include "services/tracing/public/cpp/perfetto/producer_client.h" #include "services/tracing/public/cpp/perfetto/producer_client.h"
#include "services/tracing/public/cpp/trace_startup.h"
#include "services/tracing/public/cpp/tracing_features.h" #include "services/tracing/public/cpp/tracing_features.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -79,6 +80,7 @@ PerfettoTracedProcess::PerfettoTracedProcess() ...@@ -79,6 +80,7 @@ PerfettoTracedProcess::PerfettoTracedProcess()
PerfettoTracedProcess::PerfettoTracedProcess(const char* system_socket) PerfettoTracedProcess::PerfettoTracedProcess(const char* system_socket)
: producer_client_(std::make_unique<ProducerClient>(GetTaskRunner())) { : producer_client_(std::make_unique<ProducerClient>(GetTaskRunner())) {
CHECK(IsTracingInitialized());
DETACH_FROM_SEQUENCE(sequence_checker_); DETACH_FROM_SEQUENCE(sequence_checker_);
// All communication with the system Perfetto service should occur on a single // All communication with the system Perfetto service should occur on a single
// sequence. To ensure we set up the socket correctly we construct the // sequence. To ensure we set up the socket correctly we construct the
...@@ -143,6 +145,7 @@ PerfettoTaskRunner* PerfettoTracedProcess::GetTaskRunner() { ...@@ -143,6 +145,7 @@ PerfettoTaskRunner* PerfettoTracedProcess::GetTaskRunner() {
void PerfettoTracedProcess::ResetTaskRunnerForTesting( void PerfettoTracedProcess::ResetTaskRunnerForTesting(
scoped_refptr<base::SequencedTaskRunner> task_runner) { scoped_refptr<base::SequencedTaskRunner> task_runner) {
GetTaskRunner()->ResetTaskRunnerForTesting(task_runner); GetTaskRunner()->ResetTaskRunnerForTesting(task_runner);
InitTracingPostThreadPoolStartAndFeatureList();
// Detaching the sequence_checker_ must happen after we reset the task runner. // Detaching the sequence_checker_ must happen after we reset the task runner.
// This is because the Get() could call the constructor (if this is the first // This is because the Get() could call the constructor (if this is the first
// call to Get()) which would then PostTask which would create races if we // call to Get()) which would then PostTask which would create races if we
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "services/tracing/public/cpp/perfetto/traced_value_proto_writer.h" #include "services/tracing/public/cpp/perfetto/traced_value_proto_writer.h"
#include "services/tracing/public/cpp/perfetto/track_event_thread_local_event_sink.h" #include "services/tracing/public/cpp/perfetto/track_event_thread_local_event_sink.h"
#include "services/tracing/public/cpp/trace_event_args_whitelist.h" #include "services/tracing/public/cpp/trace_event_args_whitelist.h"
#include "services/tracing/public/cpp/trace_startup.h"
#include "services/tracing/public/mojom/constants.mojom.h" #include "services/tracing/public/mojom/constants.mojom.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_arbiter.h" #include "third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_arbiter.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/startup_trace_writer.h" #include "third_party/perfetto/include/perfetto/ext/tracing/core/startup_trace_writer.h"
...@@ -287,6 +288,7 @@ void TraceEventDataSource::SetupStartupTracing(bool privacy_filtering_enabled) { ...@@ -287,6 +288,7 @@ void TraceEventDataSource::SetupStartupTracing(bool privacy_filtering_enabled) {
} }
void TraceEventDataSource::OnTaskSchedulerAvailable() { void TraceEventDataSource::OnTaskSchedulerAvailable() {
CHECK(IsTracingInitialized());
{ {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
if (!startup_writer_registry_) if (!startup_writer_registry_)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/task/thread_pool/thread_pool.h"
#include "base/trace_event/trace_log.h" #include "base/trace_event/trace_log.h"
#include "components/tracing/common/trace_startup_config.h" #include "components/tracing/common/trace_startup_config.h"
#include "components/tracing/common/trace_to_console.h" #include "components/tracing/common/trace_to_console.h"
...@@ -15,12 +16,17 @@ ...@@ -15,12 +16,17 @@
#include "services/tracing/public/cpp/tracing_features.h" #include "services/tracing/public/cpp/tracing_features.h"
namespace tracing { namespace tracing {
namespace { namespace {
using base::trace_event::TraceConfig; using base::trace_event::TraceConfig;
using base::trace_event::TraceLog; using base::trace_event::TraceLog;
} // namespace } // namespace
bool g_tracing_initialized_after_threadpool_and_featurelist = false;
bool IsTracingInitialized() {
return g_tracing_initialized_after_threadpool_and_featurelist;
}
void EnableStartupTracingIfNeeded() { void EnableStartupTracingIfNeeded() {
const base::CommandLine& command_line = const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
...@@ -66,7 +72,17 @@ void EnableStartupTracingIfNeeded() { ...@@ -66,7 +72,17 @@ void EnableStartupTracingIfNeeded() {
} }
} }
void InitTracingPostThreadPoolStart() { void InitTracingPostThreadPoolStartAndFeatureList() {
if (g_tracing_initialized_after_threadpool_and_featurelist) {
return;
}
g_tracing_initialized_after_threadpool_and_featurelist = true;
// TODO(nuskos): We should switch these to DCHECK once we're reasonably
// confident we've ensured this is called properly in all processes. Probably
// after M78 release has been cut (since we'll verify in the rollout of M78).
CHECK(base::ThreadPoolInstance::Get());
CHECK(base::FeatureList::GetInstance());
// Below are the things tracing must do once per process.
TraceEventDataSource::GetInstance()->OnTaskSchedulerAvailable(); TraceEventDataSource::GetInstance()->OnTaskSchedulerAvailable();
if (base::FeatureList::IsEnabled(features::kEnablePerfettoSystemTracing)) { if (base::FeatureList::IsEnabled(features::kEnablePerfettoSystemTracing)) {
// To ensure System tracing connects we have to initialize the process wide // To ensure System tracing connects we have to initialize the process wide
......
...@@ -9,14 +9,19 @@ ...@@ -9,14 +9,19 @@
namespace tracing { namespace tracing {
// If startup tracing command line flags are specified for the process, enables // Returns true if InitTracingPostThreadPoolStartAndFeatureList has been called
// for this process.
bool COMPONENT_EXPORT(TRACING_CPP) IsTracingInitialized();
// TraceLog with config based on the command line flags. Also hooks up service // TraceLog with config based on the command line flags. Also hooks up service
// callbacks in TraceLog if necessary. The latter is required when the perfetto // callbacks in TraceLog if necessary. The latter is required when the perfetto
// tracing backend is used. // tracing backend is used.
void COMPONENT_EXPORT(TRACING_CPP) EnableStartupTracingIfNeeded(); void COMPONENT_EXPORT(TRACING_CPP) EnableStartupTracingIfNeeded();
// Initialize tracing components that require task runners. // Initialize tracing components that require task runners. Will switch
void COMPONENT_EXPORT(TRACING_CPP) InitTracingPostThreadPoolStart(); // IsTracingInitialized() to return true.
void COMPONENT_EXPORT(TRACING_CPP)
InitTracingPostThreadPoolStartAndFeatureList();
} // namespace tracing } // namespace tracing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment