blob: 4a2c9605a4411ea5b3d1b57766bb0d7d4e1f19da [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
18if (perfetto_build_standalone || perfetto_build_with_android) {
Florian Mayerf98c9d62018-09-03 16:38:16 +010019 import("//gn/standalone/android.gni")
20} else {
21 import("//build/config/android/config.gni")
22}
Oystein Eftevaagdd727e42017-12-05 08:49:55 -080023
Primiano Tuccia1959712018-05-17 11:01:56 +010024# For use_libfuzzer.
Primiano Tucci4c5efa42018-10-23 13:15:13 +010025if (perfetto_build_standalone || perfetto_build_with_android) {
Primiano Tuccia1959712018-05-17 11:01:56 +010026 import("//gn/standalone/sanitizers/vars.gni")
27} else {
28 import("//build/config/sanitizers/sanitizers.gni")
29}
30
Primiano Tuccif3837d52018-01-10 21:12:41 +000031declare_args() {
32 # Only for local development. When true the binaries (perfetto, traced, ...)
33 # are monolithic and don't use a common shared library. This is mainly to
34 # avoid LD_LIBRARY_PATH dances when testing locally.
35 monolithic_binaries = false
Florian Mayerb64d6b12018-08-30 10:46:30 -070036
37 # libunwindstack requires API level 26 or newer.
Florian Mayera2fae262018-08-31 12:10:01 -070038 should_build_heapprofd =
Primiano Tucci4c5efa42018-10-23 13:15:13 +010039 (perfetto_build_standalone || perfetto_build_with_android) && is_clang &&
40 (is_linux || is_android) &&
41 (!is_android || android_api_level >= 26 || perfetto_build_with_android)
Primiano Tuccif3837d52018-01-10 21:12:41 +000042}
Primiano Tucci4c5efa42018-10-23 13:15:13 +010043assert(!monolithic_binaries || !perfetto_build_with_android)
Primiano Tuccif3837d52018-01-10 21:12:41 +000044
Primiano Tucciae2879e2017-09-27 11:02:09 +090045group("all") {
46 testonly = true # allow to build also test targets
47 deps = [
Eric Secklera6ba1792019-01-02 12:51:00 +000048 ":perfetto_unittests",
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000049 "src/protozero/protoc_plugin($host_toolchain)",
Primiano Tucciae2879e2017-09-27 11:02:09 +090050 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +010051 if (perfetto_build_standalone || perfetto_build_with_android) {
Primiano Tuccib03ba362017-12-06 09:47:41 +000052 deps += [
Primiano Tucci808d6df2018-03-31 13:24:18 +010053 ":perfetto",
Primiano Tucci808d6df2018-03-31 13:24:18 +010054 ":perfetto_integrationtests",
55 ":traced",
56 ":traced_probes",
Hector Dearman696ff772019-04-23 18:38:53 +010057 ":trigger_perfetto",
Primiano Tuccic5010802018-01-19 17:13:21 +000058 "protos/perfetto/config:merged_config", # For syntax-checking the proto.
Hector Dearmane92c6742018-11-22 21:42:39 +000059 "protos/perfetto/trace:merged_trace", # For syntax-checking the proto.
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -070060 "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
Primiano Tucci9564d912019-05-21 23:53:18 +010061 "src/public",
Oystein Eftevaag51e06e52018-01-18 11:28:49 -080062 "tools:protoc_helper",
Primiano Tuccib03ba362017-12-06 09:47:41 +000063 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +010064 if (perfetto_build_standalone) {
Primiano Tucci5968caf2018-08-06 10:31:46 +010065 deps += [
Primiano Tucci4c5efa42018-10-23 13:15:13 +010066 ":perfetto_benchmarks",
Primiano Tucci5968caf2018-08-06 10:31:46 +010067 ":trace_processor",
Florian Mayerc50bcc92019-02-07 11:43:30 +000068 "src/profiling/memory:ring_buffer",
Primiano Tucci3cd31322018-10-11 20:06:56 +010069 "src/tracing:consumer_api_test",
Primiano Tucci4c5efa42018-10-23 13:15:13 +010070 "test/configs",
71 "tools/ftrace_proto_gen:ftrace_proto_gen",
72 "tools/proto_to_cpp",
Primiano Tucci5968caf2018-08-06 10:31:46 +010073 "tools/trace_to_text",
Hector Dearman499cd602018-11-20 13:02:31 +000074 "tools/trace_to_text:trace_to_text_lite_host($host_toolchain)",
Primiano Tucci5968caf2018-08-06 10:31:46 +010075 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +010076 if (is_linux || is_android) {
77 deps += [ "tools/skippy" ]
Ryan Savitskidb7f1ae2019-04-10 17:28:28 +010078 deps += [ "tools/busy_threads" ]
Lalit Maganti787418f2019-04-11 14:14:23 +010079 deps += [ "tools/dump_ftrace_stats" ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +010080 }
Florian Mayer2e480712018-12-07 16:25:41 +000081 if (is_fuzzer) {
Primiano Tucci4c5efa42018-10-23 13:15:13 +010082 deps += [ ":fuzzers" ]
83 }
Primiano Tuccia1959712018-05-17 11:01:56 +010084 }
Primiano Tuccib03ba362017-12-06 09:47:41 +000085 }
Primiano Tucciae2879e2017-09-27 11:02:09 +090086}
87
Primiano Tucci3faad742018-05-16 19:30:48 +010088# TODO(primiano): temporary workaround to:
89# 1) Prevent that the UI gets build automatically when doing ninja -C out/xx .
90# 2) Avoid breaking the chrome build, that right now depends on "all".
91group("default") {
92 testonly = true # allow to build also test targets
93 deps = [
94 ":all",
95 ]
96}
97
Primiano Tucci4c5efa42018-10-23 13:15:13 +010098if (perfetto_build_standalone) {
Primiano Tucci3faad742018-05-16 19:30:48 +010099 group("ui") {
100 deps = [
101 "ui",
102 ]
103 }
Primiano Tucci5968caf2018-08-06 10:31:46 +0100104
105 # The trace processor shell executable. An interactive shell that allows to
106 # make queries on the trace using the terminal.
107 group("trace_processor") {
108 deps = [
109 "src/trace_processor:trace_processor_shell",
110 ]
111 }
Primiano Tucci3faad742018-05-16 19:30:48 +0100112}
113
Eric Secklera6ba1792019-01-02 12:51:00 +0000114test("perfetto_unittests") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900115 deps = [
Primiano Tuccib03ba362017-12-06 09:47:41 +0000116 "gn:default_deps",
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000117 "gn:gtest_main",
Hector Dearman6cfec8a2018-03-14 16:54:09 +0000118 "src/base:unittests",
Bruce Dawsonc3e67632018-05-14 14:07:51 +0100119 "src/protozero:unittests",
Oystein Eftevaage5e84fb2018-06-01 17:34:56 -0700120 "src/tracing:unittests",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900121 ]
Primiano Tucci1640ffa2018-05-14 18:25:33 +0100122
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100123 if (perfetto_build_standalone || perfetto_build_with_android) {
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700124 deps += [
125 "src/ipc:unittests",
126 "src/perfetto_cmd:unittests",
Florian Mayerc50bcc92019-02-07 11:43:30 +0000127 "src/profiling/memory:ring_buffer_unittests",
Primiano Tucci808d6df2018-03-31 13:24:18 +0100128 "src/traced/probes:unittests",
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700129 "src/traced/probes/filesystem:unittests",
Primiano Tuccide82dae2018-06-04 16:17:49 +0200130 "src/traced/probes/ftrace:unittests",
Eric Seckler21077742019-03-18 09:07:54 +0000131 "src/traced/service:unittests",
Primiano Tucci808d6df2018-03-31 13:24:18 +0100132 "tools/ftrace_proto_gen:unittests",
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700133 "tools/sanitizers_unittests",
134 ]
Primiano Tucci931284e2017-12-11 09:23:53 +0000135 }
Florian Mayerb64d6b12018-08-30 10:46:30 -0700136 if (should_build_heapprofd) {
137 # Restrict to clang, as libunwindstack and its dependencies is never
138 # built using GCC in the Android tree.
139 deps += [ "src/profiling/memory:unittests" ]
140 }
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100141 if (perfetto_build_standalone && !is_android) {
Lalit Maganti5f3a0182019-05-07 16:40:36 +0100142 deps += [
143 "src/trace_processor:unittests",
144 "src/trace_processor/metrics:unittests",
145 ]
Lalit Maganticaed37e2018-06-01 03:03:08 +0100146 }
Primiano Tuccib03ba362017-12-06 09:47:41 +0000147}
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800148
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100149if (perfetto_build_standalone || perfetto_build_with_android) {
Eric Secklera6ba1792019-01-02 12:51:00 +0000150 test("perfetto_integrationtests") {
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000151 deps = [
152 "gn:default_deps",
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000153 "gn:gtest_main",
Primiano Tucci990b5fe2019-05-23 10:20:50 +0100154 "src/public:integrationtests",
Primiano Tuccide82dae2018-06-04 16:17:49 +0200155 "src/traced/probes/ftrace:integrationtests",
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000156 "test:end_to_end_integrationtests",
157 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100158 if (perfetto_build_standalone && !is_android) {
Hector Dearman7f71d0e2018-08-09 11:26:10 +0100159 deps += [ "src/trace_processor:integrationtests" ]
160 }
Florian Mayer42802492018-12-13 11:00:16 +0000161
162 # TODO(fmayer): Fix in process daemons.
163 if (should_build_heapprofd && is_android && !start_daemons_for_testing) {
164 deps += [ "src/profiling/memory:end_to_end_tests" ]
165 }
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000166 }
167
Primiano Tuccif3837d52018-01-10 21:12:41 +0000168 if (monolithic_binaries) {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100169 libperfetto_target_type = "source_set"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000170 } else {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100171 libperfetto_target_type = "shared_library"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000172 }
173
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100174 target(libperfetto_target_type, "libperfetto") {
Primiano Tucci4e49c022017-12-21 18:22:44 +0100175 deps = [
176 "gn:default_deps",
Primiano Tucci6067e732018-01-08 16:19:40 +0000177 "src/traced/probes",
178 "src/traced/service",
Primiano Tucci3cd31322018-10-11 20:06:56 +0100179 "src/tracing:api",
Primiano Tucci6067e732018-01-08 16:19:40 +0000180 ]
181 }
182
Primiano Tucci3b729102018-01-08 18:16:36 +0000183 # The unprivileged trace daemon that listens for Producer and Consumer
184 # connections, handles the coordination of the tracing sessions and owns the
185 # log buffers.
Primiano Tucci6067e732018-01-08 16:19:40 +0000186 executable("traced") {
187 deps = [
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100188 ":libperfetto",
Primiano Tucci6067e732018-01-08 16:19:40 +0000189 "gn:default_deps",
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100190 "include/perfetto/traced",
Primiano Tucci6067e732018-01-08 16:19:40 +0000191 ]
192 sources = [
193 "src/traced/service/main.cc",
194 ]
195 }
196
Primiano Tucci3b729102018-01-08 18:16:36 +0000197 # The unprivileged daemon that is allowed to access tracefs (for ftrace).
198 # Registers as a Producer on the traced daemon.
Primiano Tucci6067e732018-01-08 16:19:40 +0000199 executable("traced_probes") {
200 deps = [
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100201 ":libperfetto",
Primiano Tucci6067e732018-01-08 16:19:40 +0000202 "gn:default_deps",
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100203 "include/perfetto/traced",
Primiano Tucci6067e732018-01-08 16:19:40 +0000204 ]
205 sources = [
206 "src/traced/probes/main.cc",
Primiano Tucci4e49c022017-12-21 18:22:44 +0100207 ]
208 }
Primiano Tucci3b729102018-01-08 18:16:36 +0000209
210 # The command line client for Perfetto. Allows to configure / start / stop
211 # tracing, acting as a Consumer.
212 executable("perfetto") {
213 deps = [
Primiano Tucci3b729102018-01-08 18:16:36 +0000214 "gn:default_deps",
Hector Dearmanc443a362018-02-28 16:03:56 +0000215 "src/perfetto_cmd",
Primiano Tucci3b729102018-01-08 18:16:36 +0000216 ]
217 sources = [
Hector Dearmanc443a362018-02-28 16:03:56 +0000218 "src/perfetto_cmd/main.cc",
Primiano Tucci3b729102018-01-08 18:16:36 +0000219 ]
220 }
Primiano Tucci6aa75572018-03-21 05:33:14 -0700221
Hector Dearman696ff772019-04-23 18:38:53 +0100222 # Tool to finalize long running traces.
223 # This connects to traced as a producer and sends the triggers passed on the
224 # commandline. This is a subset of what the perfetto binary can do but we
225 # need a separate binary for programs that cannot (for good reason) use the
226 # additional functionality (for example starting traces via consumer socket)
227 # due to selinux rules.
228 executable("trigger_perfetto") {
229 deps = [
230 "gn:default_deps",
231 "src/perfetto_cmd:trigger_perfetto_cmd",
232 ]
233 sources = [
234 "src/perfetto_cmd/trigger_perfetto_main.cc",
235 ]
236 }
237
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100238 if (perfetto_build_with_android) {
Primiano Tucci21c19d82018-03-29 12:35:08 +0100239 executable("trace_to_text") {
240 testonly = true
241 deps = [
242 "gn:default_deps",
Primiano Tucci20dc8f72018-10-23 12:28:29 +0100243 "tools/trace_to_text:full",
Primiano Tucci21c19d82018-03-29 12:35:08 +0100244 ]
245 }
Primiano Tucci21c19d82018-03-29 12:35:08 +0100246
Primiano Tucci808d6df2018-03-31 13:24:18 +0100247 # This target exports perfetto trace protos in the Android build system,
248 # allowing both host and device targets to implement custom parsers based on
249 # our protos.
250 static_library("perfetto_trace_protos") {
251 deps = [
252 "protos/perfetto/trace:lite",
253 ]
254 }
Primiano Tucci676f0cc2018-12-03 20:03:26 +0100255
256 shared_library("libperfetto_android_internal") {
257 deps = [
258 "gn:default_deps",
259 "src/android_internal",
260 ]
261 }
262 } # if (perfetto_build_with_android)
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100263} # if (perfetto_build_standalone || perfetto_build_with_android)
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700264
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100265if (perfetto_build_with_embedder) {
266 if (build_with_chromium) {
267 libperfetto_target_type = "component"
268 } else {
269 libperfetto_target_type = "source_set"
270 }
271 target(libperfetto_target_type, "libperfetto") {
Primiano Tucci20b760c2018-01-19 12:36:12 +0000272 public_configs = [ "gn:public_config" ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800273 deps = [
274 "src/tracing",
275 ]
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700276 configs -= [ "//build/config/compiler:chromium_code" ]
277 configs += [ "//build/config/compiler:no_chromium_code" ]
278 public_deps = [
279 "include/perfetto/tracing/core",
Oystein Eftevaag6fcedac2018-07-02 12:02:55 -0700280 "protos/perfetto/trace:zero",
281 "protos/perfetto/trace/chrome:zero",
Eric Secklerd3139b42019-02-26 13:43:59 +0000282 "protos/perfetto/trace/interned_data:zero",
283 "protos/perfetto/trace/track_event:zero",
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700284 ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800285 }
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700286}
Primiano Tuccia1959712018-05-17 11:01:56 +0100287
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100288if (perfetto_build_standalone) {
289 executable("perfetto_benchmarks") {
290 testonly = true
291 deps = [
292 "gn:default_deps",
293 "src/traced/probes/ftrace:benchmarks",
294 "src/tracing:tracing_benchmarks",
295 "test:benchmark_main",
296 "test:end_to_end_benchmarks",
297 ]
298 }
299
Primiano Tucci59d6ace2018-09-26 22:24:20 +0100300 group("fuzzers") {
301 testonly = true
302 deps = [
303 "src/ipc:buffered_frame_deserializer_fuzzer",
Florian Mayer4a1ee942019-02-07 15:51:16 +0000304 "src/profiling/memory:shared_ring_buffer_fuzzer",
Florian Mayer00389182019-04-08 16:43:21 +0100305 "src/profiling/memory:shared_ring_buffer_write_fuzzer",
Florian Mayerc365e362018-10-24 13:21:17 +0100306 "src/profiling/memory:unwinding_fuzzer",
Primiano Tuccic1678872019-03-20 11:30:54 +0000307 "src/protozero:protozero_decoder_fuzzer",
Hector Dearman59bc02d2019-02-21 17:28:11 +0000308 "src/trace_processor:trace_processor_fuzzer",
Primiano Tucci59d6ace2018-09-26 22:24:20 +0100309 "src/traced/probes/ftrace:cpu_reader_fuzzer",
310 "test:end_to_end_shared_memory_fuzzer",
311 ]
312 }
Primiano Tuccia1959712018-05-17 11:01:56 +0100313}
Florian Mayerb6a921f2018-10-18 18:55:23 +0100314
Ryan Savitskie65beca2019-01-29 18:29:13 +0000315# WARNING: this builds correctly only when using the generated Android.bp.
316#
317# This library gets loaded into (and executes in) arbitrary android processes.
318# Logging must be non-allocating. This is achieved by defining
319# PERFETTO_ANDROID_ASYNC_SAFE_LOG, which needs to be set for all perfetto code
320# being compiled for this library. When generating Android.bp, the |cflags|
321# entry on this target is sufficient (as all sources are flattened into a
322# single bp target). However this is not correctly reflected in the gn
323# structure (which is a tree of targets) as the dependencies would not pick
324# up the flag (and thus use the wrong logging macro).
325#
326# This is deemed acceptable as, at the time of writing, there is no interest in
327# building this library standalone.
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100328if (perfetto_build_with_android) {
Florian Mayerb6a921f2018-10-18 18:55:23 +0100329 # TODO(fmayer): Investigate shared library for common pieces.
330 shared_library("heapprofd_client") {
Ryan Savitskia3da9be2019-01-30 17:45:53 +0000331 configs -= [ "//gn/standalone:android_liblog" ]
Ryan Savitskie65beca2019-01-29 18:29:13 +0000332 cflags = [ "-DPERFETTO_ANDROID_ASYNC_SAFE_LOG" ]
Florian Mayerb6a921f2018-10-18 18:55:23 +0100333 deps = [
334 "src/profiling/memory:malloc_hooks",
335 ]
336 }
Florian Mayer8e7eac42018-11-05 16:04:11 +0000337}
Florian Mayerb6a921f2018-10-18 18:55:23 +0100338
Florian Mayer8e7eac42018-11-05 16:04:11 +0000339if (should_build_heapprofd) {
Florian Mayerb6a921f2018-10-18 18:55:23 +0100340 executable("heapprofd") {
341 deps = [
342 "gn:default_deps",
Florian Mayer4afdd642018-11-13 11:11:04 +0000343 "protos/perfetto/trace:zero",
Florian Mayerb6a921f2018-10-18 18:55:23 +0100344 "src/base",
345 "src/base:unix_socket",
346 "src/profiling/memory:daemon",
347 "src/profiling/memory:wire_protocol",
Florian Mayer8e7eac42018-11-05 16:04:11 +0000348 "src/tracing:ipc",
Florian Mayerb6a921f2018-10-18 18:55:23 +0100349 ]
350 sources = [
351 "src/profiling/memory/main.cc",
352 ]
353 }
354}