blob: a6d4a637258133ad4a78c49c7c22a5de3c01ec9b [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")
Primiano Tucci4c5efa42018-10-23 13:15:13 +010016
17if (perfetto_build_standalone || perfetto_build_with_android) {
Florian Mayerf98c9d62018-09-03 16:38:16 +010018 import("//gn/standalone/android.gni")
19} else {
20 import("//build/config/android/config.gni")
21}
Oystein Eftevaagdd727e42017-12-05 08:49:55 -080022
Primiano Tuccia1959712018-05-17 11:01:56 +010023# For use_libfuzzer.
Primiano Tucci4c5efa42018-10-23 13:15:13 +010024if (perfetto_build_standalone || perfetto_build_with_android) {
Primiano Tuccia1959712018-05-17 11:01:56 +010025 import("//gn/standalone/sanitizers/vars.gni")
26} else {
27 import("//build/config/sanitizers/sanitizers.gni")
28}
29
Primiano Tuccif3837d52018-01-10 21:12:41 +000030declare_args() {
31 # Only for local development. When true the binaries (perfetto, traced, ...)
32 # are monolithic and don't use a common shared library. This is mainly to
33 # avoid LD_LIBRARY_PATH dances when testing locally.
34 monolithic_binaries = false
Florian Mayerb64d6b12018-08-30 10:46:30 -070035
36 # libunwindstack requires API level 26 or newer.
Florian Mayera2fae262018-08-31 12:10:01 -070037 should_build_heapprofd =
Primiano Tucci4c5efa42018-10-23 13:15:13 +010038 (perfetto_build_standalone || perfetto_build_with_android) && is_clang &&
39 (is_linux || is_android) &&
40 (!is_android || android_api_level >= 26 || perfetto_build_with_android)
Primiano Tuccif3837d52018-01-10 21:12:41 +000041}
Primiano Tucci4c5efa42018-10-23 13:15:13 +010042assert(!monolithic_binaries || !perfetto_build_with_android)
Primiano Tuccif3837d52018-01-10 21:12:41 +000043
Primiano Tucciae2879e2017-09-27 11:02:09 +090044group("all") {
45 testonly = true # allow to build also test targets
46 deps = [
Lalit Maganti79f2d7b2018-01-23 18:27:33 +000047 ":perfetto_unittests",
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000048 "src/protozero/protoc_plugin($host_toolchain)",
Primiano Tucciae2879e2017-09-27 11:02:09 +090049 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +010050 if (perfetto_build_standalone || perfetto_build_with_android) {
Primiano Tuccib03ba362017-12-06 09:47:41 +000051 deps += [
Primiano Tucci808d6df2018-03-31 13:24:18 +010052 ":perfetto",
Primiano Tucci808d6df2018-03-31 13:24:18 +010053 ":perfetto_integrationtests",
54 ":traced",
55 ":traced_probes",
Primiano Tuccic5010802018-01-19 17:13:21 +000056 "protos/perfetto/config:merged_config", # For syntax-checking the proto.
Florian Mayer98c3c3e2018-11-01 14:03:39 +000057 "protos/perfetto/profiling:lite", # For syntax-checking the proto.
58 # TODO(fmayer): Remove once used.
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -070059 "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
Oystein Eftevaag51e06e52018-01-18 11:28:49 -080060 "tools:protoc_helper",
Primiano Tuccib03ba362017-12-06 09:47:41 +000061 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +010062 if (perfetto_build_standalone) {
Primiano Tucci5968caf2018-08-06 10:31:46 +010063 deps += [
Primiano Tucci4c5efa42018-10-23 13:15:13 +010064 ":perfetto_benchmarks",
Primiano Tucci5968caf2018-08-06 10:31:46 +010065 ":trace_processor",
Primiano Tucci3cd31322018-10-11 20:06:56 +010066 "src/tracing:consumer_api_test",
Primiano Tucci4c5efa42018-10-23 13:15:13 +010067 "test/configs",
68 "tools/ftrace_proto_gen:ftrace_proto_gen",
69 "tools/proto_to_cpp",
Primiano Tucci5968caf2018-08-06 10:31:46 +010070 "tools/trace_to_text",
71 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +010072 if (is_linux || is_android) {
73 deps += [ "tools/skippy" ]
74 }
75 if (is_linux) {
76 deps += [ "tools:pipestats" ]
77 }
78 if (use_libfuzzer) {
79 deps += [ ":fuzzers" ]
80 }
Primiano Tuccia1959712018-05-17 11:01:56 +010081 }
Primiano Tuccib03ba362017-12-06 09:47:41 +000082 }
Primiano Tucciae2879e2017-09-27 11:02:09 +090083}
84
Primiano Tucci3faad742018-05-16 19:30:48 +010085# TODO(primiano): temporary workaround to:
86# 1) Prevent that the UI gets build automatically when doing ninja -C out/xx .
87# 2) Avoid breaking the chrome build, that right now depends on "all".
88group("default") {
89 testonly = true # allow to build also test targets
90 deps = [
91 ":all",
92 ]
93}
94
Primiano Tucci4c5efa42018-10-23 13:15:13 +010095if (perfetto_build_standalone) {
Primiano Tucci3faad742018-05-16 19:30:48 +010096 group("ui") {
97 deps = [
98 "ui",
99 ]
100 }
Primiano Tucci5968caf2018-08-06 10:31:46 +0100101
102 # The trace processor shell executable. An interactive shell that allows to
103 # make queries on the trace using the terminal.
104 group("trace_processor") {
105 deps = [
106 "src/trace_processor:trace_processor_shell",
107 ]
108 }
Primiano Tucci3faad742018-05-16 19:30:48 +0100109}
110
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000111executable("perfetto_unittests") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900112 testonly = true
113 deps = [
Primiano Tuccib03ba362017-12-06 09:47:41 +0000114 "gn:default_deps",
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000115 "gn:gtest_main",
Hector Dearman6cfec8a2018-03-14 16:54:09 +0000116 "src/base:unittests",
Bruce Dawsonc3e67632018-05-14 14:07:51 +0100117 "src/protozero:unittests",
Oystein Eftevaage5e84fb2018-06-01 17:34:56 -0700118 "src/tracing:unittests",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900119 ]
Primiano Tucci1640ffa2018-05-14 18:25:33 +0100120
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100121 if (perfetto_build_standalone || perfetto_build_with_android) {
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700122 deps += [
123 "src/ipc:unittests",
124 "src/perfetto_cmd:unittests",
Primiano Tucci808d6df2018-03-31 13:24:18 +0100125 "src/traced/probes:unittests",
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700126 "src/traced/probes/filesystem:unittests",
Primiano Tuccide82dae2018-06-04 16:17:49 +0200127 "src/traced/probes/ftrace:unittests",
Primiano Tucci808d6df2018-03-31 13:24:18 +0100128 "tools/ftrace_proto_gen:unittests",
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700129 "tools/sanitizers_unittests",
130 ]
Primiano Tucci931284e2017-12-11 09:23:53 +0000131 }
Florian Mayerb64d6b12018-08-30 10:46:30 -0700132 if (should_build_heapprofd) {
133 # Restrict to clang, as libunwindstack and its dependencies is never
134 # built using GCC in the Android tree.
135 deps += [ "src/profiling/memory:unittests" ]
136 }
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100137 if (perfetto_build_standalone && !is_android) {
Lalit Maganticaed37e2018-06-01 03:03:08 +0100138 deps += [ "src/trace_processor:unittests" ]
139 }
Primiano Tuccib03ba362017-12-06 09:47:41 +0000140}
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800141
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100142if (perfetto_build_standalone || perfetto_build_with_android) {
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000143 executable("perfetto_integrationtests") {
144 testonly = true
145 deps = [
146 "gn:default_deps",
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000147 "gn:gtest_main",
Primiano Tuccide82dae2018-06-04 16:17:49 +0200148 "src/traced/probes/ftrace:integrationtests",
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000149 "test:end_to_end_integrationtests",
150 ]
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100151 if (perfetto_build_standalone && !is_android) {
Hector Dearman7f71d0e2018-08-09 11:26:10 +0100152 deps += [ "src/trace_processor:integrationtests" ]
153 }
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100154 if (perfetto_build_with_android) {
Lalit Maganti0b9a6ac2018-02-16 18:05:06 +0000155 cflags = [ "-DPERFETTO_BUILD_WITH_ANDROID" ]
156 }
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000157 }
158
Primiano Tuccif3837d52018-01-10 21:12:41 +0000159 if (monolithic_binaries) {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100160 libperfetto_target_type = "source_set"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000161 } else {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100162 libperfetto_target_type = "shared_library"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000163 }
164
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100165 target(libperfetto_target_type, "libperfetto") {
Primiano Tucci4e49c022017-12-21 18:22:44 +0100166 deps = [
167 "gn:default_deps",
Primiano Tucci6067e732018-01-08 16:19:40 +0000168 "src/traced/probes",
169 "src/traced/service",
Primiano Tucci3cd31322018-10-11 20:06:56 +0100170 "src/tracing:api",
Primiano Tucci6067e732018-01-08 16:19:40 +0000171 ]
172 }
173
Primiano Tucci3b729102018-01-08 18:16:36 +0000174 # The unprivileged trace daemon that listens for Producer and Consumer
175 # connections, handles the coordination of the tracing sessions and owns the
176 # log buffers.
Primiano Tucci6067e732018-01-08 16:19:40 +0000177 executable("traced") {
178 deps = [
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100179 ":libperfetto",
Primiano Tucci6067e732018-01-08 16:19:40 +0000180 "gn:default_deps",
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100181 "include/perfetto/traced",
Primiano Tucci6067e732018-01-08 16:19:40 +0000182 ]
183 sources = [
184 "src/traced/service/main.cc",
185 ]
186 }
187
Primiano Tucci3b729102018-01-08 18:16:36 +0000188 # The unprivileged daemon that is allowed to access tracefs (for ftrace).
189 # Registers as a Producer on the traced daemon.
Primiano Tucci6067e732018-01-08 16:19:40 +0000190 executable("traced_probes") {
191 deps = [
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100192 ":libperfetto",
Primiano Tucci6067e732018-01-08 16:19:40 +0000193 "gn:default_deps",
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100194 "include/perfetto/traced",
Primiano Tucci6067e732018-01-08 16:19:40 +0000195 ]
196 sources = [
197 "src/traced/probes/main.cc",
Primiano Tucci4e49c022017-12-21 18:22:44 +0100198 ]
199 }
Primiano Tucci3b729102018-01-08 18:16:36 +0000200
201 # The command line client for Perfetto. Allows to configure / start / stop
202 # tracing, acting as a Consumer.
203 executable("perfetto") {
204 deps = [
Primiano Tucci3b729102018-01-08 18:16:36 +0000205 "gn:default_deps",
Hector Dearmanc443a362018-02-28 16:03:56 +0000206 "src/perfetto_cmd",
Primiano Tucci3b729102018-01-08 18:16:36 +0000207 ]
208 sources = [
Hector Dearmanc443a362018-02-28 16:03:56 +0000209 "src/perfetto_cmd/main.cc",
Primiano Tucci3b729102018-01-08 18:16:36 +0000210 ]
Lalit Maganti0b9a6ac2018-02-16 18:05:06 +0000211 if (is_android) {
212 deps += [ "src/base:android_task_runner" ]
213 }
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100214 if (perfetto_build_with_android) {
Primiano Tucci6d848532018-01-17 10:32:33 +0000215 cflags = [ "-DPERFETTO_BUILD_WITH_ANDROID" ]
Primiano Tucci6d848532018-01-17 10:32:33 +0000216 libs = [
217 "binder",
218 "services",
219 "utils",
220 ]
221 }
Primiano Tucci3b729102018-01-08 18:16:36 +0000222 }
Primiano Tucci6aa75572018-03-21 05:33:14 -0700223
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100224 if (perfetto_build_with_android) {
Primiano Tucci21c19d82018-03-29 12:35:08 +0100225 executable("trace_to_text") {
226 testonly = true
227 deps = [
228 "gn:default_deps",
Primiano Tucci20dc8f72018-10-23 12:28:29 +0100229 "tools/trace_to_text:full",
Primiano Tucci21c19d82018-03-29 12:35:08 +0100230 ]
231 }
Primiano Tucci21c19d82018-03-29 12:35:08 +0100232
Primiano Tucci808d6df2018-03-31 13:24:18 +0100233 # This target exports perfetto trace protos in the Android build system,
234 # allowing both host and device targets to implement custom parsers based on
235 # our protos.
236 static_library("perfetto_trace_protos") {
237 deps = [
238 "protos/perfetto/trace:lite",
239 ]
240 }
Primiano Tucci6aa75572018-03-21 05:33:14 -0700241 }
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100242} # if (perfetto_build_standalone || perfetto_build_with_android)
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700243
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100244if (perfetto_build_with_embedder) {
245 if (build_with_chromium) {
246 libperfetto_target_type = "component"
247 } else {
248 libperfetto_target_type = "source_set"
249 }
250 target(libperfetto_target_type, "libperfetto") {
Primiano Tucci20b760c2018-01-19 12:36:12 +0000251 public_configs = [ "gn:public_config" ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800252 deps = [
253 "src/tracing",
254 ]
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700255 configs -= [ "//build/config/compiler:chromium_code" ]
256 configs += [ "//build/config/compiler:no_chromium_code" ]
257 public_deps = [
258 "include/perfetto/tracing/core",
Oystein Eftevaag6fcedac2018-07-02 12:02:55 -0700259 "protos/perfetto/trace:zero",
260 "protos/perfetto/trace/chrome:zero",
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700261 ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800262 }
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700263}
Primiano Tuccia1959712018-05-17 11:01:56 +0100264
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100265if (perfetto_build_standalone) {
266 executable("perfetto_benchmarks") {
267 testonly = true
268 deps = [
269 "gn:default_deps",
270 "src/traced/probes/ftrace:benchmarks",
271 "src/tracing:tracing_benchmarks",
272 "test:benchmark_main",
273 "test:end_to_end_benchmarks",
274 ]
275 }
276
Primiano Tucci59d6ace2018-09-26 22:24:20 +0100277 group("fuzzers") {
278 testonly = true
279 deps = [
280 "src/ipc:buffered_frame_deserializer_fuzzer",
Florian Mayerc365e362018-10-24 13:21:17 +0100281 "src/profiling/memory:unwinding_fuzzer",
Primiano Tucci59d6ace2018-09-26 22:24:20 +0100282 "src/traced/probes/ftrace:cpu_reader_fuzzer",
283 "test:end_to_end_shared_memory_fuzzer",
284 ]
285 }
Primiano Tuccia1959712018-05-17 11:01:56 +0100286}
Florian Mayerb6a921f2018-10-18 18:55:23 +0100287
Primiano Tucci4c5efa42018-10-23 13:15:13 +0100288if (perfetto_build_with_android) {
Florian Mayerb6a921f2018-10-18 18:55:23 +0100289 # TODO(fmayer): Investigate shared library for common pieces.
290 shared_library("heapprofd_client") {
291 deps = [
292 "src/profiling/memory:malloc_hooks",
293 ]
294 }
Florian Mayer8e7eac42018-11-05 16:04:11 +0000295}
Florian Mayerb6a921f2018-10-18 18:55:23 +0100296
Florian Mayer8e7eac42018-11-05 16:04:11 +0000297if (should_build_heapprofd) {
Florian Mayerb6a921f2018-10-18 18:55:23 +0100298 executable("heapprofd") {
299 deps = [
300 "gn:default_deps",
301 "src/base",
302 "src/base:unix_socket",
303 "src/profiling/memory:daemon",
304 "src/profiling/memory:wire_protocol",
Florian Mayer8e7eac42018-11-05 16:04:11 +0000305 "src/tracing:ipc",
Florian Mayerb6a921f2018-10-18 18:55:23 +0100306 ]
307 sources = [
308 "src/profiling/memory/main.cc",
309 ]
310 }
311}