Skip to content

Commit 1fc013d

Browse files
committed
amalgamated C SDK: drop C++ implementation files unused by the C ABI
Source: 5,727,555 → 5,557,692 bytes (-169,863 = -3.0%) Binary: 6,049,608 → 5,904,712 bytes (-O0, -141 KB) Binary: 2,265,688 → 2,220,504 bytes (-O2, -44 KB / -2.0%) Compile: 9.7s → 9.5s (-O0); 31.0s → 30.1s (-O2) Drop two groups of C++ source files that are part of the SDK's GN closure but unreachable from the C ABI surface in include/perfetto/public/abi/. src/tracing/BUILD.gn (gated under enable_perfetto_minimal_trace_protos): console_interceptor.cc — pretty-printed console output for in-process trace readback. Public C++ only (ConsoleInterceptor::Register); nothing in include/perfetto/public/ references it. track_event_state_tracker.cc — helper for replaying TrackEvent state in a consumer; only used by console_interceptor.cc. track_event_legacy.cc — implementation of LegacyTraceId::Write. The class is constructed only inside `#if PERFETTO_ENABLE_LEGACY_TRACE_EVENTS` blocks (off by default), so the .cc symbol is dead. src/base/BUILD.gn: cpu_info.cc — used only by profiling and system_info data sources. ctrl_c_handler.cc — used only by perfetto_cmd. getopt_compat.cc — Windows getopt fallback used only by command-line tools. subprocess.cc + posix/windows variants — used only by tests and host tools (perfetto_cmd, kallsyms loader, etc.). All audit checks: zero non-test #include sites under src/{shared_lib, tracing,protozero,protovm,ipc,base}/ and include/perfetto/{public, tracing,ext/tracing}/ (excluding the dropped files' own self-references).
1 parent 0acaa29 commit 1fc013d

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

src/base/BUILD.gn

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ perfetto_component("base") {
3535
sources = [
3636
"android_utils.cc",
3737
"base64.cc",
38-
"cpu_info.cc",
3938
"crash_keys.cc",
40-
"ctrl_c_handler.cc",
4139
"event_fd.cc",
4240
"file_utils.cc",
4341
"fixed_string_writer.cc",
44-
"getopt_compat.cc",
4542
"intrusive_list.cc",
4643
"intrusive_tree.cc",
4744
"log_ring_buffer.h",
@@ -70,6 +67,17 @@ perfetto_component("base") {
7067
"weak_runner.cc",
7168
]
7269

70+
# Sources only used by host tools (perfetto_cmd, trace_processor probes,
71+
# tests). Not reachable from any SDK closure entry point — gated under the
72+
# same C-SDK-minimal flag used to drop unused per-domain protos.
73+
if (!enable_perfetto_minimal_trace_protos) {
74+
sources += [
75+
"cpu_info.cc",
76+
"ctrl_c_handler.cc",
77+
"getopt_compat.cc",
78+
]
79+
}
80+
7381
if (!is_nacl) {
7482
sources += [
7583
"lock_free_task_runner.cc",
@@ -78,7 +86,7 @@ perfetto_component("base") {
7886
]
7987
}
8088

81-
if (_subprocess_supported) {
89+
if (_subprocess_supported && !enable_perfetto_minimal_trace_protos) {
8290
sources += [
8391
"subprocess.cc",
8492
"subprocess_posix.cc",

src/tracing/BUILD.gn

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ source_set("client_api_without_backends") {
8484
"../../include/perfetto/tracing",
8585
]
8686
sources = [
87-
"console_interceptor.cc",
8887
"data_source.cc",
8988
"debug_annotation.cc",
9089
"event_context.cc",
@@ -106,10 +105,30 @@ source_set("client_api_without_backends") {
106105
"tracing_policy.cc",
107106
"track.cc",
108107
"track_event_category_registry.cc",
109-
"track_event_legacy.cc",
110-
"track_event_state_tracker.cc",
111108
"virtual_destructors.cc",
112109
]
110+
111+
# Optional C++-only SDK features that the C ABI doesn't expose:
112+
# - console_interceptor: pretty-printed text output for in-process trace
113+
# readback. Only used by C++ embedders calling
114+
# ConsoleInterceptor::Register; not surfaced via include/perfetto/public.
115+
# - track_event_state_tracker: helper for replaying TrackEvent state in a
116+
# consumer; only used by console_interceptor.
117+
# - track_event_legacy: implementation of LegacyTraceId::Write for the
118+
# PERFETTO_ENABLE_LEGACY_TRACE_EVENTS Chrome-style macros, off by
119+
# default. The internal::LegacyTraceId class is only constructed inside
120+
# `#if PERFETTO_ENABLE_LEGACY_TRACE_EVENTS` blocks in
121+
# internal/track_event_data_source.h, so the .cc symbol is never called
122+
# when the macro is off.
123+
if (enable_perfetto_minimal_trace_protos) {
124+
# Drop ~830 lines of C++ that the C SDK never reaches.
125+
} else {
126+
sources += [
127+
"console_interceptor.cc",
128+
"track_event_legacy.cc",
129+
"track_event_state_tracker.cc",
130+
]
131+
}
113132
assert_no_deps = [ "service" ]
114133
if (enable_perfetto_ipc) {
115134
assert_no_deps += [

0 commit comments

Comments
 (0)