Skip to content

Commit 7094e2f

Browse files
committed
sdk: honor TraceConfig.compression_type on the in-process backend
Mirror what `src/traced/service/service.cc` does for the system backend: when the SDK is built with `enable_perfetto_zlib=true`, construct the in-process backend's TracingService with `init_opts.compressor_fn = &ZlibCompressFn` so that `TraceConfig.compression_type = COMPRESSION_TYPE_DEFLATE` actually takes effect. Without this, the in-process service is created with default `init_opts` (compressor_fn == nullptr) and the `compression_type` field on the TraceConfig is silently ignored — embedders writing a local `.pftrace` via `TracingSession::Setup(cfg, fd)` got an uncompressed file regardless of what they set in the config. The compressor is wired only when PERFETTO_ZLIB is enabled, matching the existing pattern in `service.cc:136-139`. No new public API; the behavior is opt-in via the TraceConfig field that already exists.
1 parent 5dba463 commit 7094e2f

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

Android.bp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ cc_library {
954954
":perfetto_src_tracing_ipc_producer_producer",
955955
":perfetto_src_tracing_ipc_service_service",
956956
":perfetto_src_tracing_service_service",
957+
":perfetto_src_tracing_service_zlib_compressor",
957958
":perfetto_src_tracing_system_backend",
958959
],
959960
host_supported: true,
@@ -1033,17 +1034,24 @@ cc_library {
10331034
cflags: [
10341035
"-DPERFETTO_REGEX_FORCE_STD",
10351036
"-DPERFETTO_SHLIB_SDK_IMPLEMENTATION",
1037+
"-DZLIB_IMPLEMENTATION",
10361038
],
10371039
min_sdk_version: "30",
10381040
target: {
10391041
android: {
10401042
shared_libs: [
10411043
"liblog",
1044+
"libz",
10421045
],
10431046
static_libs: [
10441047
"perfetto_flags_c_lib",
10451048
],
10461049
},
1050+
host: {
1051+
static_libs: [
1052+
"libz",
1053+
],
1054+
},
10471055
windows: {
10481056
enabled: true,
10491057
cflags: [
@@ -1168,6 +1176,7 @@ cc_library_static {
11681176
":perfetto_src_tracing_ipc_producer_producer",
11691177
":perfetto_src_tracing_ipc_service_service",
11701178
":perfetto_src_tracing_service_service",
1179+
":perfetto_src_tracing_service_zlib_compressor",
11711180
":perfetto_src_tracing_system_backend",
11721181
],
11731182
shared_libs: [
@@ -1317,6 +1326,7 @@ cc_library_static {
13171326
],
13181327
cflags: [
13191328
"-DPERFETTO_REGEX_FORCE_STD",
1329+
"-DZLIB_IMPLEMENTATION",
13201330
],
13211331
apex_available: [
13221332
"//apex_available:anyapex",
@@ -1325,10 +1335,18 @@ cc_library_static {
13251335
min_sdk_version: "30",
13261336
target: {
13271337
android: {
1338+
shared_libs: [
1339+
"libz",
1340+
],
13281341
static_libs: [
13291342
"perfetto_flags_c_lib",
13301343
],
13311344
},
1345+
host: {
1346+
static_libs: [
1347+
"libz",
1348+
],
1349+
},
13321350
},
13331351
}
13341352

@@ -2135,10 +2153,18 @@ cc_library_static {
21352153
],
21362154
target: {
21372155
android: {
2156+
shared_libs: [
2157+
"libz",
2158+
],
21382159
static_libs: [
21392160
"perfetto_flags_c_lib",
21402161
],
21412162
},
2163+
host: {
2164+
static_libs: [
2165+
"libz",
2166+
],
2167+
},
21422168
},
21432169
}
21442170

@@ -3134,6 +3160,7 @@ cc_test {
31343160
":perfetto_src_tracing_ipc_producer_relay",
31353161
":perfetto_src_tracing_ipc_service_service",
31363162
":perfetto_src_tracing_service_service",
3163+
":perfetto_src_tracing_service_zlib_compressor",
31373164
":perfetto_src_tracing_system_backend",
31383165
":perfetto_src_tracing_test_api_test_support",
31393166
":perfetto_src_tracing_test_client_api_integrationtests",
@@ -3348,10 +3375,18 @@ cc_test {
33483375
test_config: "PerfettoIntegrationTests.xml",
33493376
target: {
33503377
android: {
3378+
shared_libs: [
3379+
"libz",
3380+
],
33513381
static_libs: [
33523382
"perfetto_flags_c_lib",
33533383
],
33543384
},
3385+
host: {
3386+
static_libs: [
3387+
"libz",
3388+
],
3389+
},
33553390
},
33563391
}
33573392

BUILD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ perfetto_cc_library(
183183
":src_tracing_ipc_producer_producer",
184184
":src_tracing_ipc_service_service",
185185
":src_tracing_service_service",
186+
":src_tracing_service_zlib_compressor",
186187
":src_tracing_system_backend",
187188
],
188189
hdrs = [
@@ -276,7 +277,7 @@ perfetto_cc_library(
276277
":src_base_regex_regex",
277278
":src_base_version",
278279
":src_protovm_protovm",
279-
],
280+
] + PERFETTO_CONFIG.deps.zlib,
280281
linkstatic = True,
281282
)
282283

@@ -9505,6 +9506,7 @@ perfetto_cc_library(
95059506
":src_tracing_ipc_producer_producer",
95069507
":src_tracing_ipc_service_service",
95079508
":src_tracing_service_service",
9509+
":src_tracing_service_zlib_compressor",
95089510
":src_tracing_system_backend",
95099511
],
95109512
hdrs = [
@@ -9595,7 +9597,7 @@ perfetto_cc_library(
95959597
":src_base_regex_regex",
95969598
":src_base_version",
95979599
":src_protovm_protovm",
9598-
],
9600+
] + PERFETTO_CONFIG.deps.zlib,
95999601
linkstatic = True,
96009602
)
96019603

src/tracing/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ source_set("in_process_backend") {
205205
"core",
206206
"service",
207207
]
208+
if (enable_perfetto_zlib) {
209+
deps += [ "service:zlib_compressor" ]
210+
}
208211
sources = [ "internal/in_process_tracing_backend.cc" ]
209212
}
210213

src/tracing/internal/in_process_tracing_backend.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include "src/tracing/core/in_process_shared_memory.h"
2727

28+
#if PERFETTO_BUILDFLAG(PERFETTO_ZLIB)
29+
#include "src/tracing/service/zlib_compressor.h"
30+
#endif
31+
2832
// TODO(primiano): When the in-process backend is used, we should never end up
2933
// in a situation where the thread where the TracingService and Producer live
3034
// writes a packet and hence can get into the GetNewChunk() stall.
@@ -68,7 +72,16 @@ TracingService* InProcessTracingBackend::GetOrCreateService(
6872
if (!service_) {
6973
std::unique_ptr<InProcessSharedMemory::Factory> shm(
7074
new InProcessSharedMemory::Factory());
71-
service_ = TracingService::CreateInstance(std::move(shm), task_runner);
75+
TracingService::InitOpts init_opts = {};
76+
#if PERFETTO_BUILDFLAG(PERFETTO_ZLIB)
77+
// Wire the zlib compressor so TraceConfig.compression_type =
78+
// COMPRESSION_TYPE_DEFLATE takes effect on the in-process backend's
79+
// service, mirroring what src/traced/service/service.cc does for the
80+
// system backend.
81+
init_opts.compressor_fn = &ZlibCompressFn;
82+
#endif
83+
service_ =
84+
TracingService::CreateInstance(std::move(shm), task_runner, init_opts);
7285
service_->SetSMBScrapingEnabled(true);
7386
}
7487
return service_.get();

0 commit comments

Comments
 (0)