0

Remove use_perfetto_client_library build flag in /services/tracing/public/cpp/stack_sampling

This flag was introduced to provide a smooth transition from legacy
tracing macros to Perfetto tracing SDK. Now the transition is complete,
and the flag is unconditionally set to true on all platforms. So we can
remove the flag and the code that is disabled by it.

This CL was uploaded by git cl split.

R=agarwaltushar@google.com

Bug: 42050015, 336718643
Change-Id: Ie5275ea71aa4242b89e8e9294eefd90d1ed9c3d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5506054
Auto-Submit: Mikhail Khokhlov <khokhlov@google.com>
Reviewed-by: Tushar Agarwal <agarwaltushar@google.com>
Commit-Queue: Mikhail Khokhlov <khokhlov@google.com>
Cr-Commit-Position: refs/heads/main@{#1295368}
This commit is contained in:
Mikhail Khokhlov
2024-05-02 11:16:34 +00:00
committed by Chromium LUCI CQ
parent 2540c146fa
commit c376b351b7
2 changed files with 3 additions and 157 deletions
services/tracing/public/cpp/stack_sampling

@ -203,10 +203,8 @@ class TracingSamplerProfilerDataSource
static uint32_t GetIncrementalStateResetID() {
return incremental_state_reset_id_.load(std::memory_order_relaxed);
}
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
using DataSourceProxy =
PerfettoTracedProcess::DataSourceProxy<TracingSamplerProfilerDataSource>;
#endif
static void ResetForTesting() {
if (!g_sampler_profiler_ds_for_test)
@ -216,11 +214,9 @@ class TracingSamplerProfilerDataSource
}
void RegisterDataSource() {
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
perfetto::DataSourceDescriptor dsd;
dsd.set_name(mojom::kSamplerProfilerSourceName);
DataSourceProxy::Register(dsd, this);
#endif
}
private:
@ -255,9 +251,7 @@ class TracingSamplerProfilerDataSource
static std::atomic<uint32_t> incremental_state_reset_id_;
};
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
using DataSourceProxy = TracingSamplerProfilerDataSource::DataSourceProxy;
#endif
// static
std::atomic<uint32_t>
@ -770,6 +764,8 @@ void TracingSamplerProfiler::SetAuxUnwinderFactoryOnMainThread(
g_main_thread_instance->SetAuxUnwinderFactory(factory);
}
// TODO(b/336718643): Remove unused code after removing use_perfetto_client_library build
// flag.
// static
void TracingSamplerProfiler::StartTracingForTesting(
PerfettoProducer* producer) {
@ -913,17 +909,14 @@ void TracingSamplerProfiler::StopTracing() {
} // namespace tracing
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS_WITH_ATTRS(
COMPONENT_EXPORT(TRACING_CPP),
tracing::TracingSamplerProfilerDataSource::DataSourceProxy);
#endif // BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
// This should go after PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS_WITH_ATTRS
// to avoid instantiation of type() template method before specialization.
std::unique_ptr<perfetto::TraceWriterBase>
tracing::TracingSamplerProfilerDataSource::CreateTraceWriter() {
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
perfetto::internal::DataSourceStaticState* static_state =
perfetto::DataSourceHelper<DataSourceProxy>::type().static_state();
// DataSourceProxy disallows multiple instances, so our instance will always
@ -933,8 +926,4 @@ tracing::TracingSamplerProfilerDataSource::CreateTraceWriter() {
return perfetto::internal::TracingMuxer::Get()->CreateTraceWriter(
static_state, data_source_config_.target_buffer(), instance_state,
perfetto::BufferExhaustedPolicy::kDrop);
#else
lock_.AssertAcquired();
return producer_->CreateTraceWriter(data_source_config_.target_buffer());
#endif
}

@ -55,9 +55,7 @@ using ::testing::Invoke;
using ::testing::Return;
using PacketVector = TestProducerClient::PacketVector;
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
std::unique_ptr<perfetto::TracingSession> g_tracing_session;
#endif
#if BUILDFLAG(ENABLE_LOADER_LOCK_SAMPLING)
@ -89,13 +87,7 @@ class LoaderLockEventAnalyzer {
#endif // BUILDFLAG(ENABLE_LOADER_LOCK_SAMPLING)
class TracingSampleProfilerTest
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
: public testing::Test
#else
: public TracingUnitTest
#endif // !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
{
class TracingSampleProfilerTest : public testing::Test {
public:
TracingSampleProfilerTest() = default;
@ -106,9 +98,6 @@ class TracingSampleProfilerTest
~TracingSampleProfilerTest() override = default;
void SetUp() override {
#if !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
TracingUnitTest::SetUp();
#endif
#if BUILDFLAG(ENABLE_LOADER_LOCK_SAMPLING)
// Override the default LoaderLockSampler because in production it is
@ -122,35 +111,18 @@ class TracingSampleProfilerTest
events_stack_received_count_ = 0u;
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
PerfettoTracedProcess::GetTaskRunner()->ResetTaskRunnerForTesting(
base::SingleThreadTaskRunner::GetCurrentDefault());
TracingSamplerProfiler::ResetDataSourceForTesting();
#else
auto perfetto_wrapper = std::make_unique<base::tracing::PerfettoTaskRunner>(
base::SingleThreadTaskRunner::GetCurrentDefault());
producer_ =
std::make_unique<TestProducerClient>(std::move(perfetto_wrapper),
/*log_only_main_thread=*/false);
#endif
}
void TearDown() override {
#if !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
producer_.reset();
#endif
#if BUILDFLAG(ENABLE_LOADER_LOCK_SAMPLING)
LoaderLockSamplingThread::SetLoaderLockSamplerForTesting(nullptr);
#endif
#if !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
TracingUnitTest::TearDown();
#endif
}
void BeginTrace() {
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
perfetto::TraceConfig trace_config;
trace_config.add_buffers()->set_size_kb(1024);
auto* ds_cfg = trace_config.add_data_sources()->mutable_config();
@ -163,14 +135,10 @@ class TracingSampleProfilerTest
g_tracing_session->StartBlocking();
// Make sure TraceEventMetadataSource::StartTracingImpl gets run.
base::RunLoop().RunUntilIdle();
#else
TracingSamplerProfiler::StartTracingForTesting(producer_.get());
#endif
}
void WaitForEvents() { base::PlatformThread::Sleep(base::Milliseconds(200)); }
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
void EnsureTraceStopped() {
if (!g_tracing_session)
return;
@ -195,24 +163,14 @@ class TracingSampleProfilerTest
finalized_packets_.push_back(std::move(proto));
}
}
#endif
const PacketVector& GetFinalizedPackets() {
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
EnsureTraceStopped();
return finalized_packets_;
#else // !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
return producer_->finalized_packets();
#endif // !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
}
void EndTracing() {
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
EnsureTraceStopped();
#else
TracingSamplerProfiler::StopTracingForTesting();
base::RunLoop().RunUntilIdle();
#endif
auto& packets = GetFinalizedPackets();
for (auto& packet : packets) {
if (packet->has_streaming_profile_packet()) {
@ -242,23 +200,15 @@ class TracingSampleProfilerTest
return profile_sequence_id;
}
#if !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
TestProducerClient* producer() const { return producer_.get(); }
#endif
protected:
// We want our singleton torn down after each test.
base::ShadowingAtExitManager at_exit_manager_;
base::trace_event::TraceResultBuffer trace_buffer_;
#if BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
base::test::TaskEnvironment task_environment_;
base::test::TracingEnvironment tracing_environment_;
std::vector<std::unique_ptr<perfetto::protos::TracePacket>>
finalized_packets_;
#else // !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
std::unique_ptr<tracing::TestProducerClient> producer_;
#endif // !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
// Number of stack sampling events received.
size_t events_stack_received_count_ = 0;
@ -574,97 +524,4 @@ TEST_F(TracingProfileBuilderTest, InvalidModule) {
base::TimeTicks());
}
#if !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
TEST_F(TracingProfileBuilderTest, TransformELFModuleIDToSymbolServerFormat) {
base::TestModule module;
// See explanation for the module_id mangling in
// base::TransformModuleIDToSymbolServerFormat implementation.
module.set_id("7F0715C286F8B16C10E4AD349CDA3B9B56C7A773");
TracingSamplerProfiler::TracingProfileBuilder profile_builder(
base::PlatformThreadId(), std::make_unique<TestTraceWriter>(producer()),
false);
profile_builder.OnSampleCompleted({base::Frame(0x1010, &module)},
base::TimeTicks());
producer()->FlushPacketIfPossible();
bool found_build_id = false;
EXPECT_GT(producer()->GetFinalizedPacketCount(), 0u);
for (unsigned i = 0; i < producer()->GetFinalizedPacketCount(); ++i) {
const perfetto::protos::TracePacket* packet =
producer()->GetFinalizedPacket(i);
if (!packet->has_interned_data() ||
packet->interned_data().build_ids_size() == 0) {
return;
}
found_build_id = true;
EXPECT_EQ(packet->interned_data().build_ids(0).str(),
"C215077FF8866CB110E4AD349CDA3B9B0");
}
EXPECT_TRUE(found_build_id);
}
#endif
#if BUILDFLAG(IS_ANDROID) && \
(ANDROID_ARM64_UNWINDING_SUPPORTED || ANDROID_CFI_UNWINDING_SUPPORTED)
TEST_F(TracingProfileBuilderTest, FullPathForJavaModulesWithMissingBuildId) {
base::NativeLibrary other_library = base::LoadOtherLibrary();
uintptr_t addr = base::GetAddressInOtherLibrary(other_library);
int non_zero_base_address = 1;
base::TestModule module(non_zero_base_address);
module.set_id("");
module.set_debug_basename(base::FilePath("other_library.so"));
TracingSamplerProfiler::TracingProfileBuilder profile_builder(
base::PlatformThreadId(), std::make_unique<TestTraceWriter>(producer()),
false);
profile_builder.OnSampleCompleted({base::Frame(addr, &module)},
base::TimeTicks());
producer()->FlushPacketIfPossible();
EXPECT_GT(producer()->GetFinalizedPacketCount(), 0u);
bool has_full_path = false;
for (size_t i = 0; i < producer()->GetFinalizedPacketCount(); ++i) {
const perfetto::protos::TracePacket* packet =
producer()->GetFinalizedPacket(i);
for (const auto& mapping : packet->interned_data().mapping_paths()) {
// Full path should start from leading '/'.
if (base::StartsWith(mapping.str(), "/")) {
has_full_path = true;
break;
}
}
}
EXPECT_TRUE(has_full_path);
}
#endif
TEST_F(TracingProfileBuilderTest, SetPidFromTraceLog) {
constexpr int kExpectedPid = 1234;
TraceLog::GetInstance()->SetProcessID(kExpectedPid);
TracingSamplerProfiler::TracingProfileBuilder profile_builder(
base::PlatformThreadId(), std::make_unique<TestTraceWriter>(producer()),
/*should_enable_filtering=*/false);
profile_builder.OnSampleCompleted(
{base::Frame(/*instruction_pointer=*/0, /*module=*/nullptr)},
base::TimeTicks());
EXPECT_GT(producer()->GetFinalizedPacketCount(), 0u);
bool found_pid = false;
for (const std::unique_ptr<TracePacket>& packet :
producer()->finalized_packets()) {
if (packet->thread_descriptor().has_pid()) {
found_pid = true;
EXPECT_EQ(packet->thread_descriptor().pid(), kExpectedPid);
}
}
EXPECT_TRUE(found_pid);
}
#endif // !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
} // namespace tracing