From 3adb5e1aa1c0b42d08946ef01a3269f8d99cba27 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 14 May 2021 17:20:02 +0100 Subject: Allow to specify which heaps to disable. Change-Id: I25725452c49ceb6410d4571d4d8460cb6ba9aa7e --- protos/perfetto/config/perfetto_config.proto | 6 ++++++ .../config/profiling/heapprofd_config.proto | 6 ++++++ protos/perfetto/trace/perfetto_trace.proto | 6 ++++++ src/profiling/memory/heapprofd_producer.cc | 12 +++++++++++ .../memory/heapprofd_producer_unittest.cc | 13 ++++++++++++ src/profiling/memory/wire_protocol_unittest.cc | 11 +++++++++++ .../perfetto/trace_processor/metrics.descriptor | 23 +++++++++++++--------- 7 files changed, 68 insertions(+), 9 deletions(-) diff --git a/protos/perfetto/config/perfetto_config.proto b/protos/perfetto/config/perfetto_config.proto index 529adc798..d088e9b84 100644 --- a/protos/perfetto/config/perfetto_config.proto +++ b/protos/perfetto/config/perfetto_config.proto @@ -621,6 +621,12 @@ message HeapprofdConfig { // Introduced in Android 12. repeated string heaps = 20; + // Which heaps not to sample, e.g. "libc.malloc". This is useful when used in + // combination with all_heaps; + // + // Introduced in Android 12. + repeated string exclude_heaps = 27; + optional bool stream_allocations = 23; // If given, needs to be the same length as heaps and gives the sampling diff --git a/protos/perfetto/config/profiling/heapprofd_config.proto b/protos/perfetto/config/profiling/heapprofd_config.proto index 2d8654c65..00dd6929c 100644 --- a/protos/perfetto/config/profiling/heapprofd_config.proto +++ b/protos/perfetto/config/profiling/heapprofd_config.proto @@ -81,6 +81,12 @@ message HeapprofdConfig { // Introduced in Android 12. repeated string heaps = 20; + // Which heaps not to sample, e.g. "libc.malloc". This is useful when used in + // combination with all_heaps; + // + // Introduced in Android 12. + repeated string exclude_heaps = 27; + optional bool stream_allocations = 23; // If given, needs to be the same length as heaps and gives the sampling diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto index 76638d83f..36313affd 100644 --- a/protos/perfetto/trace/perfetto_trace.proto +++ b/protos/perfetto/trace/perfetto_trace.proto @@ -621,6 +621,12 @@ message HeapprofdConfig { // Introduced in Android 12. repeated string heaps = 20; + // Which heaps not to sample, e.g. "libc.malloc". This is useful when used in + // combination with all_heaps; + // + // Introduced in Android 12. + repeated string exclude_heaps = 27; + optional bool stream_allocations = 23; // If given, needs to be the same length as heaps and gives the sampling diff --git a/src/profiling/memory/heapprofd_producer.cc b/src/profiling/memory/heapprofd_producer.cc index 3403d3773..dfc69222c 100644 --- a/src/profiling/memory/heapprofd_producer.cc +++ b/src/profiling/memory/heapprofd_producer.cc @@ -149,6 +149,9 @@ bool HeapprofdConfigToClientConfiguration( cli_config->adaptive_sampling_max_sampling_interval_bytes = heapprofd_config.adaptive_sampling_max_sampling_interval_bytes(); size_t n = 0; + const std::vector& exclude_heaps = heapprofd_config.exclude_heaps(); + // heaps[i] and heaps_interval[i] represent that the heap named in heaps[i] + // should be sampled with sampling interval of heap_interval[i]. std::vector heaps = heapprofd_config.heaps(); std::vector heap_intervals = heapprofd_config.heap_sampling_intervals(); @@ -169,6 +172,15 @@ bool HeapprofdConfigToClientConfiguration( PERFETTO_ELOG("zero sampling interval."); return false; } + if (!exclude_heaps.empty()) { + // For disabled heaps, we add explicit entries but with sampling interval + // 0. The consumer of the sampling intervals in ClientConfiguration, + // GetSamplingInterval in wire_protocol.h, uses 0 to signal a heap is + // disabled, either because it isn't enabled (all_heaps is not set, and the + // heap isn't named), or because we explicitely set it here. + heaps.insert(heaps.end(), exclude_heaps.cbegin(), exclude_heaps.cend()); + heap_intervals.insert(heap_intervals.end(), exclude_heaps.size(), 0u); + } if (heaps.size() > base::ArraySize(cli_config->heaps)) { heaps.resize(base::ArraySize(cli_config->heaps)); PERFETTO_ELOG("Too many heaps requested. Truncating."); diff --git a/src/profiling/memory/heapprofd_producer_unittest.cc b/src/profiling/memory/heapprofd_producer_unittest.cc index b1ee3f8a6..fa08e95f9 100644 --- a/src/profiling/memory/heapprofd_producer_unittest.cc +++ b/src/profiling/memory/heapprofd_producer_unittest.cc @@ -226,5 +226,18 @@ TEST(HeapprofdConfigToClientConfigurationTest, AllHeapsAndExplicit) { EXPECT_EQ(cli_config.default_interval, 4096u); } +TEST(HeapprofdConfigToClientConfigurationTest, AllHeapsAndDisabled) { + HeapprofdConfig cfg; + cfg.set_all_heaps(true); + cfg.set_sampling_interval_bytes(4096); + cfg.add_exclude_heaps("foo"); + ClientConfiguration cli_config; + ASSERT_TRUE(HeapprofdConfigToClientConfiguration(cfg, &cli_config)); + EXPECT_EQ(cli_config.num_heaps, 1u); + EXPECT_STREQ(cli_config.heaps[0].name, "foo"); + EXPECT_EQ(cli_config.heaps[0].interval, 0u); + EXPECT_EQ(cli_config.default_interval, 4096u); +} + } // namespace profiling } // namespace perfetto diff --git a/src/profiling/memory/wire_protocol_unittest.cc b/src/profiling/memory/wire_protocol_unittest.cc index 69df58fce..3f7e494dd 100644 --- a/src/profiling/memory/wire_protocol_unittest.cc +++ b/src/profiling/memory/wire_protocol_unittest.cc @@ -160,6 +160,17 @@ TEST(GetHeapSamplingInterval, SelectedAndDefault) { EXPECT_EQ(GetHeapSamplingInterval(cli_config, "else"), 1u); } +TEST(GetHeapSamplingInterval, DisabledAndDefault) { + ClientConfiguration cli_config{}; + cli_config.all_heaps = true; + cli_config.num_heaps = 1; + cli_config.default_interval = 1; + memcpy(cli_config.heaps[0].name, "something", sizeof("something")); + cli_config.heaps[0].interval = 0u; + EXPECT_EQ(GetHeapSamplingInterval(cli_config, "something"), 0u); + EXPECT_EQ(GetHeapSamplingInterval(cli_config, "else"), 1u); +} + } // namespace } // namespace profiling } // namespace perfetto diff --git a/src/trace_processor/python/perfetto/trace_processor/metrics.descriptor b/src/trace_processor/python/perfetto/trace_processor/metrics.descriptor index 2670372e1..b5e2561d5 100644 --- a/src/trace_processor/python/perfetto/trace_processor/metrics.descriptor +++ b/src/trace_processor/python/perfetto/trace_processor/metrics.descriptor @@ -357,8 +357,8 @@ PowerRails name ( RnameN energy_data ( 2-.perfetto.protos.AndroidPowerRails.EnergyDataR energyData -ä -4protos/perfetto/metrics/android/startup_metric.protoperfetto.protos6protos/perfetto/metrics/android/process_metadata.proto"â +Í" +4protos/perfetto/metrics/android/startup_metric.protoperfetto.protos6protos/perfetto/metrics/android/process_metadata.proto"Ë! AndroidStartupMetricG startup ( 2-.perfetto.protos.AndroidStartupMetric.StartupRstartupà TaskStateBreakdown$ @@ -409,7 +409,10 @@ HscMetricsN Activity name ( Rname method ( Rmethod& -ts_method_start (R tsMethodStartJ¯ +ts_method_start (R tsMethodStartJt +BinderTransactionG +duration ( 2+.perfetto.protos.AndroidStartupMetric.SliceRduration +thread ( Rthread¯ OptimizationStatus odex_status ( R odexStatus- @@ -419,7 +422,7 @@ odexStatus- EventTimestamps' intent_received (RintentReceived first_frame (R -firstFrameÀ +firstFrame³ Startup startup_id ( R startupId! @@ -427,7 +430,8 @@ startup_id ( R startupId! process_name ( R processNameN activities ( 2..perfetto.protos.AndroidStartupMetric.ActivityR -activities, +activitiesq +long_binder_transactions ( 27.perfetto.protos.AndroidStartupMetric.BinderTransactionRlongBinderTransactions, zygote_new_process (RzygoteNewProcessC activity_hosting_process_count ( RactivityHostingProcessCount` event_timestamps ( 25.perfetto.protos.AndroidStartupMetric.EventTimestampsReventTimestampsX @@ -472,11 +476,12 @@ jank_cause ( R jankCause threadName uid (Ruid( uid_package_name ( RuidPackageName -é -Aprotos/perfetto/metrics/android/thread_time_in_state_metric.protoperfetto.protos6protos/perfetto/metrics/android/process_metadata.proto"Ú +” +Aprotos/perfetto/metrics/android/thread_time_in_state_metric.protoperfetto.protos6protos/perfetto/metrics/android/process_metadata.proto"… AndroidThreadTimeInStateMetricU - processes ( 27.perfetto.protos.AndroidThreadTimeInStateMetric.ProcessR processes• -MetricsByCoreType + processes ( 27.perfetto.protos.AndroidThreadTimeInStateMetric.ProcessR processesÀ +MetricsByCoreType) +time_in_state_cpu (RtimeInStateCpu core_type ( RcoreType runtime_ms (R runtimeMs -- cgit v1.2.3