blob: ee45b3c21742d8d73c886340ac91078279c00e3a [file] [log] [blame]
Primiano Tucciae2879e2017-09-27 11:02:09 +09001# Copyright (C) 2017 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Oystein Eftevaagdd727e42017-12-05 08:49:55 -080015import("gn/perfetto.gni")
Eric Secklera6ba1792019-01-02 12:51:00 +000016import("gn/test.gni")
Primiano Tucci4c5efa42018-10-23 13:15:13 +010017
Primiano Tucci02c11762019-08-30 00:57:59 +020018# +----------------------------------------------------------------------------+
19# | "all" targets definition: defines targets reachable by the various configs |
20# +----------------------------------------------------------------------------+
21# There is a subtletly here related with chromium and other GN embedders.
22# When adding a dependency some_dir/:target_name, some_dir/BUILD.gn is
23# "discovered". As a side effect any *other* target defined in some_dir/BUILD.gn
24# (and its transitive dependencies) becomes implicitly part of the "default"
25# target, the one invoked running ninja -C out/xxx without further args.
26# Because of this, care must be taken to wrap dependencies to targets in other
27# build files with if (enable_xxx) flags. Accidentally including a harmless
28# target that happens to be defined in the same BUILD.gn that contains targets
29# incompatible with the chromium build will cause build/roll failures.
30
31all_targets = [ "protos/perfetto/trace:perfetto_trace_protos" ]
32
33if (enable_perfetto_platform_services) {
34 all_targets += [
35 "src/perfetto_cmd:perfetto",
36 "src/perfetto_cmd:trigger_perfetto",
37 "src/traced/service:traced",
Primiano Tucci02c11762019-08-30 00:57:59 +020038 ]
Primiano Tuccia7f5a8e2021-01-02 17:10:50 +010039 if (enable_perfetto_traced_probes) {
40 all_targets += [ "src/traced/probes:traced_probes" ]
41 }
Chinglin Yu4ce83902023-06-28 08:16:35 +000042 if (enable_perfetto_traced_relay) {
43 all_targets += [ "src/traced_relay:traced_relay" ]
44 }
Primiano Tuccia1959712018-05-17 11:01:56 +010045}
46
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +000047if (enable_perfetto_trace_processor && enable_perfetto_trace_processor_sqlite) {
Ivan Chonga2964b02024-06-11 16:54:56 +000048 if (enable_perfetto_grpc) {
Ivan Chongec1fc222024-06-27 08:33:53 +000049 all_targets += [ "src/bigtrace/orchestrator:orchestrator_main" ]
50 all_targets += [ "src/bigtrace/worker:worker_main" ]
Ivan Chonga2964b02024-06-11 16:54:56 +000051 }
Primiano Tucci02c11762019-08-30 00:57:59 +020052 all_targets += [ "src/trace_processor:trace_processor_shell" ]
Primiano Tuccif3837d52018-01-10 21:12:41 +000053}
Primiano Tucci02c11762019-08-30 00:57:59 +020054
Aaron Vaage608d07a2024-03-04 09:56:04 -080055if (enable_perfetto_trace_processor) {
56 all_targets += [ "src/trace_redaction:trace_redactor" ]
57}
58
Hector Dearmana9545e52022-05-17 12:23:25 +010059if (enable_perfetto_traceconv) {
60 all_targets += [ "src/traceconv" ]
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000061 if (is_cross_compiling) {
62 # In many cross-compilation scenarios (typically Android) developers expect
Hector Dearmana9545e52022-05-17 12:23:25 +010063 # the host version of traceconv to be available somewhere in out/, so
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000064 # they can convert Android traces on their dev machine. Also
65 # tools/gen_android_bp explicitly depends on the host version for the
Hector Dearmana9545e52022-05-17 12:23:25 +010066 # cc_binary_host("traceconv") target in Android.bp.
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000067 # Note that when cross-compiling the host executable will be available in
Hector Dearmana9545e52022-05-17 12:23:25 +010068 # out/xxx/gcc_like_host/traceconv NOT just out/xxx/traceconv.
69 all_targets += [ "src/traceconv($host_toolchain)" ]
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000070 }
71}
72
Primiano Tucci02c11762019-08-30 00:57:59 +020073if (enable_perfetto_heapprofd) {
Florian Mayerddc8ae22021-02-18 17:20:09 +000074 all_targets += [ "src/profiling/memory:heapprofd" ]
75
76 if (is_linux && !is_android) {
77 all_targets += [ "src/profiling/memory:heapprofd_glibc_preload" ]
78 }
Primiano Tucci02c11762019-08-30 00:57:59 +020079 if (perfetto_build_with_android) {
Florian Mayer23f79372020-06-16 14:37:06 +020080 all_targets += [
81 "src/profiling/memory:heapprofd_client",
82 "src/profiling/memory:heapprofd_client_api",
83 ]
Primiano Tucci02c11762019-08-30 00:57:59 +020084 }
85}
86
Ryan Savitskia76b3cc2019-11-20 16:25:24 +000087if (enable_perfetto_traced_perf) {
88 all_targets += [ "src/profiling/perf:traced_perf" ]
89}
90
Primiano Tucci02c11762019-08-30 00:57:59 +020091if (perfetto_build_with_android) {
Primiano Tucci94ca9a92021-01-14 11:16:15 +010092 all_targets += [ "src/android_internal:libperfetto_android_internal" ]
Primiano Tucci02c11762019-08-30 00:57:59 +020093}
94
95if (enable_perfetto_tools) {
Lalit Maganti6a641aa2022-08-26 14:36:27 +010096 all_targets += [ "src/tools" ]
97
98 # Windows does not have an IPC implementation.
99 if (!is_win) {
100 all_targets += [ "src/websocket_bridge" ]
101 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200102}
103
104if (enable_perfetto_unittests) {
105 import("gn/perfetto_unittests.gni")
106 test("perfetto_unittests") {
Chong Gu2dc2d8e2022-02-10 07:28:09 -0800107 if (is_fuchsia) {
Hector Dearman06a6eb62022-08-02 12:49:58 +0100108 additional_manifest_fragments =
Primiano Tuccid4bbac32024-02-09 16:45:56 +0000109 [ "//build/config/fuchsia/test/network.shard.test-cml" ] # nogncheck
Chong Gu2dc2d8e2022-02-10 07:28:09 -0800110 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200111 deps = perfetto_unittests_targets
112 }
113 all_targets += [ ":perfetto_unittests" ]
114}
115
116if (enable_perfetto_integration_tests) {
117 import("gn/perfetto_integrationtests.gni")
118 test("perfetto_integrationtests") {
119 deps = perfetto_integrationtests_targets
120 }
121 all_targets += [
122 ":perfetto_integrationtests",
Mohit Sainic56f7692022-01-12 10:28:01 +0000123 "examples/sdk:sdk_example",
Primiano Tucci02c11762019-08-30 00:57:59 +0200124 "test:client_api_example",
Primiano Tucciff68cac2020-08-06 18:13:17 +0200125 "test/stress_test",
Primiano Tucci02c11762019-08-30 00:57:59 +0200126 ]
Hector Dearmanc9f70082023-03-15 21:26:57 +0000127 if (!is_win && !is_mac) {
Daniele Di Proietto48c739d2023-06-19 13:52:42 +0000128 all_targets += [
129 "examples/shared_lib:example_shlib_data_source",
130 "examples/shared_lib:example_shlib_track_event",
131 ]
Daniele Di Proietto3b5b77c2022-06-20 11:05:17 +0100132 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200133}
134
Mikhail Khokhlov90f09f62019-12-17 12:53:51 +0000135if (enable_perfetto_trace_processor_json) {
Stephen Nuskoaca77482020-01-10 15:47:06 +0000136 test("trace_processor_minimal_smoke_tests") {
Mikhail Khokhlov90f09f62019-12-17 12:53:51 +0000137 testonly = true
138 deps = [
139 "gn:default_deps",
140 "src/trace_processor:storage_minimal_smoke_tests",
141 ]
142 }
143 all_targets += [ ":trace_processor_minimal_smoke_tests" ]
144}
145
Primiano Tucci02c11762019-08-30 00:57:59 +0200146if (enable_perfetto_benchmarks) {
147 import("gn/perfetto_benchmarks.gni")
148 executable("perfetto_benchmarks") {
149 testonly = true
150 deps = perfetto_benchmarks_targets
151 }
152 all_targets += [ ":perfetto_benchmarks" ]
153}
154
155if (enable_perfetto_fuzzers) {
156 import("gn/perfetto_fuzzers.gni")
157 group("fuzzers") {
158 testonly = true
159 deps = perfetto_fuzzers_targets
160 }
161 all_targets += [ ":fuzzers" ]
162}
163
164# Less interesting stuff that makes sense only in the standalone build, mainly
165# compile-time checks for the CI.
166if (perfetto_build_standalone) {
167 all_targets += [
Primiano Tucci02c11762019-08-30 00:57:59 +0200168 "test/configs",
169
Lalit Maganti88e64de2022-11-21 18:29:57 +0000170 # Used to evaluate the Python folder for Bazel script generation.
171 "python:trace_processor_py",
172
Primiano Tucci57dd66b2019-10-15 23:09:04 +0100173 # For checking all generated xxx.gen.{cc,h} files without waiting for
174 # embedders to try to use them and fail.
Primiano Tucci57dd66b2019-10-15 23:09:04 +0100175 "protos/perfetto/config:cpp",
176 "protos/perfetto/common:cpp",
177
Primiano Tucci02c11762019-08-30 00:57:59 +0200178 # Used in the when updating the ftrace protos
179 "protos/perfetto/trace/ftrace:descriptor",
Primiano Tucci55b4d912020-01-28 11:17:51 +0000180
181 # Checks that the "fake" backend implementations build.
182 "src/tracing:client_api_no_backends_compile_test",
Primiano Tucci02c11762019-08-30 00:57:59 +0200183 ]
Primiano Tucci497c3ed2021-05-24 12:24:39 +0100184 if (is_linux || is_android || is_mac) {
185 all_targets += [ "src/tracebox" ]
186 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200187}
Primiano Tuccif3837d52018-01-10 21:12:41 +0000188
Daniele Di Proietto29cbcc22024-05-15 14:25:39 +0000189if (enable_perfetto_merged_protos_check) {
190 # For syntax-checking the protos.
191 all_targets += [ "protos/perfetto/trace:merged_trace_lite" ]
192}
193
Primiano Tuccifbf4a732019-12-11 00:32:15 +0000194# The CTS code is built (but not ran) also in standalone builds. This is to
195# catch refactoring breakages earlier without having to wait for treehugger.
196if (is_android && (perfetto_build_standalone || perfetto_build_with_android)) {
197 all_targets += [ "test/cts:perfetto_cts_deps" ]
Daniele Di Proietto2e6c1062022-09-14 13:52:19 +0000198 all_targets += [ "test/vts:perfetto_vts_deps" ]
Primiano Tuccifbf4a732019-12-11 00:32:15 +0000199}
200
Primiano Tucciae2879e2017-09-27 11:02:09 +0900201group("all") {
202 testonly = true # allow to build also test targets
Primiano Tucci02c11762019-08-30 00:57:59 +0200203 deps = all_targets
Primiano Tucciae2879e2017-09-27 11:02:09 +0900204}
205
Primiano Tucci02c11762019-08-30 00:57:59 +0200206# This target is used when running ninja without any argument (by default would
207# build all reachable targets). This is mainly used to prevent the UI being
208# built when running ninja -C out/xxx.
209# This has effect only in standalone builds, no effect on chromium builds.
210# Chromium's "all" target depends on our "all" target above. However chromium's
211# "default" target depends on any target that we cause to be discovered by
212# depending on other GN files.
Primiano Tucci3faad742018-05-16 19:30:48 +0100213group("default") {
Primiano Tucci02c11762019-08-30 00:57:59 +0200214 testonly = true
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000215 deps = [ ":all" ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100216}
217
Primiano Tucci02c11762019-08-30 00:57:59 +0200218# +----------------------------------------------------------------------------+
219# | Other definitions: root targets that don't belong to any other subdirectory|
220# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100221
Primiano Tucci02c11762019-08-30 00:57:59 +0200222if (enable_perfetto_ui) {
Mikhail Khokhlov8643d1c2019-06-04 12:02:47 +0100223 group("ui") {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000224 deps = [ "ui" ]
Mikhail Khokhlov8643d1c2019-06-04 12:02:47 +0100225 }
226}
227
Daniele Di Proiettoe5a603e2022-11-10 09:33:19 +0000228if (enable_perfetto_site) {
229 group("site") {
230 deps = [ "infra/perfetto.dev:site" ]
231 }
232}
233
Primiano Tucci02c11762019-08-30 00:57:59 +0200234# In Android builds, we build the code of traced and traced_probes in one shared
235# library that exposes one xxx_main() for each. The executables themselves are
236# tiny shells that just invoke their own entry point into the library.
237# This is done merely for saving binary size, because the three binaries happen
238# to share a lot of code.
239# When setting monolithic_binaries=true (only supported in standalone builds)
240# it builds more conventional executables, where each binary has the full
241# implementation and no shared library dependency. This is to make dev cycles
242# on Android faster, avoiding all the LD_LIBRARY_PATH boilerplate.
243# libperfetto.so is also used for stuff that is exposed to the rest of the
244# Android tree.
245if (enable_perfetto_platform_services) {
Primiano Tuccif3837d52018-01-10 21:12:41 +0000246 if (monolithic_binaries) {
Primiano Tucci098f0952019-09-03 10:21:20 +0100247 libperfetto_target_type = "static_library"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000248 } else {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100249 libperfetto_target_type = "shared_library"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000250 }
251
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100252 target(libperfetto_target_type, "libperfetto") {
Primiano Tucci098f0952019-09-03 10:21:20 +0100253 if (libperfetto_target_type == "static_library") {
254 complete_static_lib = true
255 }
Primiano Tucci4e49c022017-12-21 18:22:44 +0100256 deps = [
257 "gn:default_deps",
Primiano Tucci6067e732018-01-08 16:19:40 +0000258 "src/traced/service",
259 ]
Primiano Tuccia7f5a8e2021-01-02 17:10:50 +0100260 if (enable_perfetto_traced_probes) {
261 deps += [ "src/traced/probes" ]
262 }
Primiano Tucci6067e732018-01-08 16:19:40 +0000263 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200264}
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700265
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200266if (!build_with_chromium) {
Primiano Tucci55b4d912020-01-28 11:17:51 +0000267 # Client library target exposed to the Android tree.
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200268 # Still in experimental stage and not API stable yet.
269 # See "libperfetto_client_example" (in Android.bp.extras) for an example
270 # on how to use the Perfetto Client API from the android tree.
271 static_library("libperfetto_client_experimental") {
272 complete_static_lib = true
Primiano Tuccifbf4a732019-12-11 00:32:15 +0000273 public_deps = [
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200274 "gn:default_deps",
Primiano Tucci3feec552020-02-04 11:14:42 +0000275 "src/tracing:client_api",
Primiano Tucci10c9e9e2021-01-08 13:04:40 +0100276 "src/tracing:platform_impl",
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200277 ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000278 sources = [ "include/perfetto/tracing.h" ]
Primiano Tuccid4bbac32024-02-09 16:45:56 +0000279 assert_no_deps = [ "gn:protobuf_lite" ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100280 }
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200281}
282
Primiano Tucci02c11762019-08-30 00:57:59 +0200283# TODO(primiano): there seem to be two "libperfetto" and one
284# "libperfetto_client_experimental" targets defined within this BUILD.gn file.
285# Rationalize them with eseckler@. For now seems this one is only used from
286# chromium and the other one only from the Android tree.
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200287if (build_with_chromium) {
Eric Secklerc77dc1b2020-01-21 13:23:35 +0000288 component("libperfetto") {
289 public_configs = [ "gn:public_config" ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800290 deps = [
Sylwester Blaszczyk0430ce82020-08-07 16:00:51 +0200291 "src/trace_processor/importers/memory_tracker:graph_processor",
Eric Seckler48d1ab52020-01-23 09:56:29 +0000292 "src/tracing:client_api",
Sami Kyostilaedbf6262023-07-26 08:02:47 +0000293 "src/tracing:platform_impl",
Primiano Tuccic4c063b2020-01-27 09:34:46 +0000294 "src/tracing/core",
Eric Secklerc77dc1b2020-01-21 13:23:35 +0000295 ]
Primiano Tuccid4bbac32024-02-09 16:45:56 +0000296 configs -= [ "//build/config/compiler:chromium_code" ] # nogncheck
297 configs += [ "//build/config/compiler:no_chromium_code" ] # nogncheck
Eric Secklerc77dc1b2020-01-21 13:23:35 +0000298 public_deps = [
Sylwester Blaszczyk0430ce82020-08-07 16:00:51 +0200299 "include/perfetto/ext/trace_processor/importers/memory_tracker",
Primiano Tucci2c5488f2019-06-01 03:27:28 +0100300 "include/perfetto/ext/tracing/core",
Eric Seckler48d1ab52020-01-23 09:56:29 +0000301 "include/perfetto/tracing",
Nicolò Mazzucatoc1084462019-09-24 16:26:06 +0100302 "protos/perfetto/common:zero",
Oystein Eftevaag6fcedac2018-07-02 12:02:55 -0700303 "protos/perfetto/trace:zero",
304 "protos/perfetto/trace/chrome:zero",
Etienne Pierre-Doray92f6e182024-01-10 14:21:24 -0800305 "protos/perfetto/trace/etw:zero",
Eric Secklerd3139b42019-02-26 13:43:59 +0000306 "protos/perfetto/trace/interned_data:zero",
Oystein Eftevaagae116202019-07-11 09:48:42 -0700307 "protos/perfetto/trace/profiling:zero",
Piotr Roguski1c96e672020-08-24 16:19:50 +0200308 "protos/perfetto/trace/ps:zero",
Eric Secklerd3139b42019-02-26 13:43:59 +0000309 "protos/perfetto/trace/track_event:zero",
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700310 ]
Stephen Nuskobfa6d632020-01-21 14:10:56 +0000311 if (enable_perfetto_ipc) {
Eric Seckler05355e02020-01-27 15:29:50 +0000312 deps += [
313 "src/tracing/ipc/producer",
314 "src/tracing/ipc/service",
315 ]
Stephen Nuskobfa6d632020-01-21 14:10:56 +0000316 public_deps += [ "include/perfetto/ext/tracing/ipc:ipc" ]
317 }
Dave Tapuskaf9c47a32023-01-31 14:12:40 -0500318 if (!is_nacl) {
Eric Seckler60eff7d2020-05-20 13:03:07 +0100319 deps += [
320 "src/trace_processor:export_json",
321 "src/trace_processor:storage_minimal",
322 ]
323 public_deps += [
324 "include/perfetto/ext/trace_processor:export_json",
325 "include/perfetto/trace_processor:storage",
326 ]
327 }
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800328 }
Alexander Timina5e78bf2023-11-13 23:43:47 +0000329
Alexander Timind9cf07b2023-11-16 00:39:10 +0000330 # TODO(altimin): this is a temp workaround around very strange link failures
331 # on win-dbg-ng buildbot.
332 if (!is_win) {
333 libtrace_processor_target_type = "source_set"
334 } else {
335 libtrace_processor_target_type = "component"
336 }
337
Alexander Timina5e78bf2023-11-13 23:43:47 +0000338 # In Chromium, we want to ensure that we don't link dynamically against sqlite
339 # (as Chromium also uses a more restricted version of sqlite which is actually
340 # shipped to the users).
Alexander Timin237faee2023-11-15 17:14:38 +0000341 # source_set helps us to achieve that.
Alexander Timind9cf07b2023-11-16 00:39:10 +0000342 target(libtrace_processor_target_type, "libtrace_processor") {
Mikhail Khokhlov2bcfb352019-12-20 10:19:58 +0000343 public_configs = [ "gn:public_config" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000344 deps = [ "src/trace_processor:lib" ]
Primiano Tuccid4bbac32024-02-09 16:45:56 +0000345 configs -= [ "//build/config/compiler:chromium_code" ] # nogncheck
346 configs += [ "//build/config/compiler:no_chromium_code" ] # nogncheck
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000347 public_deps = [ "include/perfetto/trace_processor" ]
Eric Secklera7870e62019-11-01 10:11:58 +0000348 }
Alexander Timindfc4b692021-02-15 13:32:53 +0000349 component("perfetto_test_support") {
350 testonly = true
351 public_configs = [ "gn:public_config" ]
Primiano Tuccid4bbac32024-02-09 16:45:56 +0000352 configs -= [ "//build/config/compiler:chromium_code" ] # nogncheck
353 configs += [ "//build/config/compiler:no_chromium_code" ] # nogncheck
Alexander Timindfc4b692021-02-15 13:32:53 +0000354 public_deps = [ "include/perfetto/test:test_support" ]
355 deps = [ "src/tracing/test:test_support" ]
356 }
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700357}