blob: 70260da701b228592894d1d294f15a5a7b66cbc0 [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 }
Primiano Tuccia1959712018-05-17 11:01:56 +010042}
43
Mikhail Khokhlov0f7e68d2020-01-16 15:39:27 +000044if (enable_perfetto_trace_processor && enable_perfetto_trace_processor_sqlite) {
Primiano Tucci02c11762019-08-30 00:57:59 +020045 all_targets += [ "src/trace_processor:trace_processor_shell" ]
Primiano Tuccif3837d52018-01-10 21:12:41 +000046}
Primiano Tucci02c11762019-08-30 00:57:59 +020047
Hector Dearmana9545e52022-05-17 12:23:25 +010048if (enable_perfetto_traceconv) {
49 all_targets += [ "src/traceconv" ]
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000050 if (is_cross_compiling) {
51 # In many cross-compilation scenarios (typically Android) developers expect
Hector Dearmana9545e52022-05-17 12:23:25 +010052 # the host version of traceconv to be available somewhere in out/, so
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000053 # they can convert Android traces on their dev machine. Also
54 # tools/gen_android_bp explicitly depends on the host version for the
Hector Dearmana9545e52022-05-17 12:23:25 +010055 # cc_binary_host("traceconv") target in Android.bp.
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000056 # Note that when cross-compiling the host executable will be available in
Hector Dearmana9545e52022-05-17 12:23:25 +010057 # out/xxx/gcc_like_host/traceconv NOT just out/xxx/traceconv.
58 all_targets += [ "src/traceconv($host_toolchain)" ]
Primiano Tuccibc7a9c22022-03-15 14:09:49 +000059 }
60}
61
Primiano Tucci02c11762019-08-30 00:57:59 +020062if (enable_perfetto_heapprofd) {
Florian Mayerddc8ae22021-02-18 17:20:09 +000063 all_targets += [ "src/profiling/memory:heapprofd" ]
64
65 if (is_linux && !is_android) {
66 all_targets += [ "src/profiling/memory:heapprofd_glibc_preload" ]
67 }
Primiano Tucci02c11762019-08-30 00:57:59 +020068 if (perfetto_build_with_android) {
Florian Mayer23f79372020-06-16 14:37:06 +020069 all_targets += [
70 "src/profiling/memory:heapprofd_client",
71 "src/profiling/memory:heapprofd_client_api",
72 ]
Primiano Tucci02c11762019-08-30 00:57:59 +020073 }
74}
75
Ryan Savitskia76b3cc2019-11-20 16:25:24 +000076if (enable_perfetto_traced_perf) {
77 all_targets += [ "src/profiling/perf:traced_perf" ]
78}
79
Primiano Tucci02c11762019-08-30 00:57:59 +020080if (perfetto_build_with_android) {
Primiano Tucci94ca9a92021-01-14 11:16:15 +010081 all_targets += [ "src/android_internal:libperfetto_android_internal" ]
Primiano Tucci02c11762019-08-30 00:57:59 +020082}
83
84if (enable_perfetto_tools) {
Lalit Maganti6a641aa2022-08-26 14:36:27 +010085 all_targets += [ "src/tools" ]
86
87 # Windows does not have an IPC implementation.
88 if (!is_win) {
89 all_targets += [ "src/websocket_bridge" ]
90 }
Primiano Tucci02c11762019-08-30 00:57:59 +020091}
92
93if (enable_perfetto_unittests) {
94 import("gn/perfetto_unittests.gni")
95 test("perfetto_unittests") {
Chong Gu2dc2d8e2022-02-10 07:28:09 -080096 if (is_fuchsia) {
Hector Dearman06a6eb62022-08-02 12:49:58 +010097 additional_manifest_fragments =
98 [ "//build/config/fuchsia/test/network.shard.test-cml" ]
Chong Gu2dc2d8e2022-02-10 07:28:09 -080099 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200100 deps = perfetto_unittests_targets
101 }
102 all_targets += [ ":perfetto_unittests" ]
103}
104
105if (enable_perfetto_integration_tests) {
106 import("gn/perfetto_integrationtests.gni")
107 test("perfetto_integrationtests") {
108 deps = perfetto_integrationtests_targets
109 }
110 all_targets += [
111 ":perfetto_integrationtests",
Mohit Sainic56f7692022-01-12 10:28:01 +0000112 "examples/sdk:sdk_example",
Primiano Tucci02c11762019-08-30 00:57:59 +0200113 "test:client_api_example",
Primiano Tucciff68cac2020-08-06 18:13:17 +0200114 "test/stress_test",
Primiano Tucci02c11762019-08-30 00:57:59 +0200115 ]
116}
117
Mikhail Khokhlov90f09f62019-12-17 12:53:51 +0000118if (enable_perfetto_trace_processor_json) {
Stephen Nuskoaca77482020-01-10 15:47:06 +0000119 test("trace_processor_minimal_smoke_tests") {
Mikhail Khokhlov90f09f62019-12-17 12:53:51 +0000120 testonly = true
121 deps = [
122 "gn:default_deps",
123 "src/trace_processor:storage_minimal_smoke_tests",
124 ]
125 }
126 all_targets += [ ":trace_processor_minimal_smoke_tests" ]
127}
128
Primiano Tucci02c11762019-08-30 00:57:59 +0200129if (enable_perfetto_benchmarks) {
130 import("gn/perfetto_benchmarks.gni")
131 executable("perfetto_benchmarks") {
132 testonly = true
133 deps = perfetto_benchmarks_targets
134 }
135 all_targets += [ ":perfetto_benchmarks" ]
136}
137
138if (enable_perfetto_fuzzers) {
139 import("gn/perfetto_fuzzers.gni")
140 group("fuzzers") {
141 testonly = true
142 deps = perfetto_fuzzers_targets
143 }
144 all_targets += [ ":fuzzers" ]
145}
146
147# Less interesting stuff that makes sense only in the standalone build, mainly
148# compile-time checks for the CI.
149if (perfetto_build_standalone) {
150 all_targets += [
Primiano Tucci02c11762019-08-30 00:57:59 +0200151 "test/configs",
152
Lalit Maganti79d70fe2022-02-15 18:31:09 +0000153 # For syntax-checking the protos.
Lalit Maganti79d70fe2022-02-15 18:31:09 +0000154 "protos/perfetto/trace:merged_trace_lite",
Primiano Tucci02c11762019-08-30 00:57:59 +0200155
Primiano Tucci57dd66b2019-10-15 23:09:04 +0100156 # For checking all generated xxx.gen.{cc,h} files without waiting for
157 # embedders to try to use them and fail.
Primiano Tucci57dd66b2019-10-15 23:09:04 +0100158 "protos/perfetto/config:cpp",
159 "protos/perfetto/common:cpp",
160
Primiano Tucci02c11762019-08-30 00:57:59 +0200161 # Used in the when updating the ftrace protos
162 "protos/perfetto/trace/ftrace:descriptor",
Primiano Tucci55b4d912020-01-28 11:17:51 +0000163
164 # Checks that the "fake" backend implementations build.
165 "src/tracing:client_api_no_backends_compile_test",
Primiano Tucci02c11762019-08-30 00:57:59 +0200166 ]
Primiano Tucci497c3ed2021-05-24 12:24:39 +0100167 if (is_linux || is_android || is_mac) {
168 all_targets += [ "src/tracebox" ]
169 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200170}
Primiano Tuccif3837d52018-01-10 21:12:41 +0000171
Primiano Tuccifbf4a732019-12-11 00:32:15 +0000172# The CTS code is built (but not ran) also in standalone builds. This is to
173# catch refactoring breakages earlier without having to wait for treehugger.
174if (is_android && (perfetto_build_standalone || perfetto_build_with_android)) {
175 all_targets += [ "test/cts:perfetto_cts_deps" ]
Daniele Di Proietto2e6c1062022-09-14 13:52:19 +0000176 all_targets += [ "test/vts:perfetto_vts_deps" ]
Primiano Tuccifbf4a732019-12-11 00:32:15 +0000177}
178
Primiano Tucciae2879e2017-09-27 11:02:09 +0900179group("all") {
180 testonly = true # allow to build also test targets
Primiano Tucci02c11762019-08-30 00:57:59 +0200181 deps = all_targets
Primiano Tucciae2879e2017-09-27 11:02:09 +0900182}
183
Primiano Tucci02c11762019-08-30 00:57:59 +0200184# This target is used when running ninja without any argument (by default would
185# build all reachable targets). This is mainly used to prevent the UI being
186# built when running ninja -C out/xxx.
187# This has effect only in standalone builds, no effect on chromium builds.
188# Chromium's "all" target depends on our "all" target above. However chromium's
189# "default" target depends on any target that we cause to be discovered by
190# depending on other GN files.
Primiano Tucci3faad742018-05-16 19:30:48 +0100191group("default") {
Primiano Tucci02c11762019-08-30 00:57:59 +0200192 testonly = true
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000193 deps = [ ":all" ]
Primiano Tucci3faad742018-05-16 19:30:48 +0100194}
195
Primiano Tucci02c11762019-08-30 00:57:59 +0200196# +----------------------------------------------------------------------------+
197# | Other definitions: root targets that don't belong to any other subdirectory|
198# +----------------------------------------------------------------------------+
Primiano Tucci3faad742018-05-16 19:30:48 +0100199
Primiano Tucci02c11762019-08-30 00:57:59 +0200200if (enable_perfetto_ui) {
Mikhail Khokhlov8643d1c2019-06-04 12:02:47 +0100201 group("ui") {
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000202 deps = [ "ui" ]
Mikhail Khokhlov8643d1c2019-06-04 12:02:47 +0100203 }
204}
205
Primiano Tucci02c11762019-08-30 00:57:59 +0200206# In Android builds, we build the code of traced and traced_probes in one shared
207# library that exposes one xxx_main() for each. The executables themselves are
208# tiny shells that just invoke their own entry point into the library.
209# This is done merely for saving binary size, because the three binaries happen
210# to share a lot of code.
211# When setting monolithic_binaries=true (only supported in standalone builds)
212# it builds more conventional executables, where each binary has the full
213# implementation and no shared library dependency. This is to make dev cycles
214# on Android faster, avoiding all the LD_LIBRARY_PATH boilerplate.
215# libperfetto.so is also used for stuff that is exposed to the rest of the
216# Android tree.
217if (enable_perfetto_platform_services) {
Primiano Tuccif3837d52018-01-10 21:12:41 +0000218 if (monolithic_binaries) {
Primiano Tucci098f0952019-09-03 10:21:20 +0100219 libperfetto_target_type = "static_library"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000220 } else {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100221 libperfetto_target_type = "shared_library"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000222 }
223
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100224 target(libperfetto_target_type, "libperfetto") {
Primiano Tucci098f0952019-09-03 10:21:20 +0100225 if (libperfetto_target_type == "static_library") {
226 complete_static_lib = true
227 }
Primiano Tucci4e49c022017-12-21 18:22:44 +0100228 deps = [
229 "gn:default_deps",
Primiano Tucci6067e732018-01-08 16:19:40 +0000230 "src/traced/service",
231 ]
Primiano Tuccia7f5a8e2021-01-02 17:10:50 +0100232 if (enable_perfetto_traced_probes) {
233 deps += [ "src/traced/probes" ]
234 }
Primiano Tucci6067e732018-01-08 16:19:40 +0000235 }
Primiano Tucci02c11762019-08-30 00:57:59 +0200236}
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700237
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200238if (!build_with_chromium) {
Primiano Tucci55b4d912020-01-28 11:17:51 +0000239 # Client library target exposed to the Android tree.
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200240 # Still in experimental stage and not API stable yet.
241 # See "libperfetto_client_example" (in Android.bp.extras) for an example
242 # on how to use the Perfetto Client API from the android tree.
243 static_library("libperfetto_client_experimental") {
244 complete_static_lib = true
Primiano Tuccifbf4a732019-12-11 00:32:15 +0000245 public_deps = [
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200246 "gn:default_deps",
Primiano Tucci3feec552020-02-04 11:14:42 +0000247 "src/tracing:client_api",
Primiano Tucci10c9e9e2021-01-08 13:04:40 +0100248 "src/tracing:platform_impl",
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200249 ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000250 sources = [ "include/perfetto/tracing.h" ]
Primiano Tuccie8020f92019-11-26 13:24:01 +0000251 assert_no_deps = [ "//gn:protobuf_lite" ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100252 }
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200253}
254
Primiano Tucci02c11762019-08-30 00:57:59 +0200255# TODO(primiano): there seem to be two "libperfetto" and one
256# "libperfetto_client_experimental" targets defined within this BUILD.gn file.
257# Rationalize them with eseckler@. For now seems this one is only used from
258# chromium and the other one only from the Android tree.
Primiano Tucci7e05fc12019-08-27 17:29:47 +0200259if (build_with_chromium) {
Eric Secklerc77dc1b2020-01-21 13:23:35 +0000260 component("libperfetto") {
261 public_configs = [ "gn:public_config" ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800262 deps = [
Sylwester Blaszczyk0430ce82020-08-07 16:00:51 +0200263 "src/trace_processor/importers/memory_tracker:graph_processor",
Eric Seckler48d1ab52020-01-23 09:56:29 +0000264 "src/tracing:client_api",
Primiano Tuccic4c063b2020-01-27 09:34:46 +0000265 "src/tracing/core",
Eric Seckler48d1ab52020-01-23 09:56:29 +0000266
267 # TODO(eseckler): Create a platform for chrome and hook it up somehow.
268 "src/tracing:platform_fake",
Eric Secklerc77dc1b2020-01-21 13:23:35 +0000269 ]
270 configs -= [ "//build/config/compiler:chromium_code" ]
271 configs += [ "//build/config/compiler:no_chromium_code" ]
272 public_deps = [
Sylwester Blaszczyk0430ce82020-08-07 16:00:51 +0200273 "include/perfetto/ext/trace_processor/importers/memory_tracker",
Primiano Tucci2c5488f2019-06-01 03:27:28 +0100274 "include/perfetto/ext/tracing/core",
Eric Seckler48d1ab52020-01-23 09:56:29 +0000275 "include/perfetto/tracing",
Nicolò Mazzucatoc1084462019-09-24 16:26:06 +0100276 "protos/perfetto/common:zero",
Oystein Eftevaag6fcedac2018-07-02 12:02:55 -0700277 "protos/perfetto/trace:zero",
278 "protos/perfetto/trace/chrome:zero",
Eric Secklerd3139b42019-02-26 13:43:59 +0000279 "protos/perfetto/trace/interned_data:zero",
Oystein Eftevaagae116202019-07-11 09:48:42 -0700280 "protos/perfetto/trace/profiling:zero",
Piotr Roguski1c96e672020-08-24 16:19:50 +0200281 "protos/perfetto/trace/ps:zero",
Eric Secklerd3139b42019-02-26 13:43:59 +0000282 "protos/perfetto/trace/track_event:zero",
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700283 ]
Stephen Nuskobfa6d632020-01-21 14:10:56 +0000284 if (enable_perfetto_ipc) {
Eric Seckler05355e02020-01-27 15:29:50 +0000285 deps += [
286 "src/tracing/ipc/producer",
287 "src/tracing/ipc/service",
288 ]
Stephen Nuskobfa6d632020-01-21 14:10:56 +0000289 public_deps += [ "include/perfetto/ext/tracing/ipc:ipc" ]
290 }
Eric Seckler60eff7d2020-05-20 13:03:07 +0100291 if (!is_nacl && !is_ios) {
292 deps += [
293 "src/trace_processor:export_json",
294 "src/trace_processor:storage_minimal",
295 ]
296 public_deps += [
297 "include/perfetto/ext/trace_processor:export_json",
298 "include/perfetto/trace_processor:storage",
299 ]
300 }
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800301 }
Mikhail Khokhlov2bcfb352019-12-20 10:19:58 +0000302 component("libtrace_processor") {
303 public_configs = [ "gn:public_config" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000304 deps = [ "src/trace_processor:lib" ]
Mikhail Khokhlov2bcfb352019-12-20 10:19:58 +0000305 configs -= [ "//build/config/compiler:chromium_code" ]
306 configs += [ "//build/config/compiler:no_chromium_code" ]
Primiano Tucci2925e9d2020-01-27 10:15:58 +0000307 public_deps = [ "include/perfetto/trace_processor" ]
Eric Secklera7870e62019-11-01 10:11:58 +0000308 }
Alexander Timindfc4b692021-02-15 13:32:53 +0000309 component("perfetto_test_support") {
310 testonly = true
311 public_configs = [ "gn:public_config" ]
312 configs -= [ "//build/config/compiler:chromium_code" ]
313 configs += [ "//build/config/compiler:no_chromium_code" ]
314 public_deps = [ "include/perfetto/test:test_support" ]
315 deps = [ "src/tracing/test:test_support" ]
316 }
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700317}