blob: 576f1019265ca5168fa10103ca5465eb741a6bd7 [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")
Florian Mayerf98c9d62018-09-03 16:38:16 +010016if (!build_with_chromium) {
17 import("//gn/standalone/android.gni")
18} else {
19 import("//build/config/android/config.gni")
20}
Oystein Eftevaagdd727e42017-12-05 08:49:55 -080021
Primiano Tuccia1959712018-05-17 11:01:56 +010022# For use_libfuzzer.
23if (!build_with_chromium) {
24 import("//gn/standalone/sanitizers/vars.gni")
25} else {
26 import("//build/config/sanitizers/sanitizers.gni")
27}
28
Primiano Tuccif3837d52018-01-10 21:12:41 +000029declare_args() {
30 # Only for local development. When true the binaries (perfetto, traced, ...)
31 # are monolithic and don't use a common shared library. This is mainly to
32 # avoid LD_LIBRARY_PATH dances when testing locally.
33 monolithic_binaries = false
Florian Mayerb64d6b12018-08-30 10:46:30 -070034
35 # libunwindstack requires API level 26 or newer.
Florian Mayera2fae262018-08-31 12:10:01 -070036 should_build_heapprofd =
Primiano Tucci5313adf2018-09-09 15:10:59 +010037 !build_with_chromium && is_clang && (is_linux || is_android) &&
Florian Mayera2fae262018-08-31 12:10:01 -070038 (!is_android || android_api_level >= 26 || build_with_android)
Primiano Tuccif3837d52018-01-10 21:12:41 +000039}
40assert(!monolithic_binaries || !build_with_android)
41
Primiano Tucciae2879e2017-09-27 11:02:09 +090042group("all") {
43 testonly = true # allow to build also test targets
44 deps = [
Lalit Maganti79f2d7b2018-01-23 18:27:33 +000045 ":perfetto_unittests",
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000046 "src/protozero/protoc_plugin($host_toolchain)",
Primiano Tucciae2879e2017-09-27 11:02:09 +090047 ]
Primiano Tuccib03ba362017-12-06 09:47:41 +000048 if (!build_with_chromium) {
49 deps += [
Primiano Tucci808d6df2018-03-31 13:24:18 +010050 ":perfetto",
51 ":perfetto_benchmarks",
52 ":perfetto_integrationtests",
53 ":traced",
54 ":traced_probes",
Primiano Tuccic5010802018-01-19 17:13:21 +000055 "protos/perfetto/config:merged_config", # For syntax-checking the proto.
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -070056 "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
Hector Dearmanfcbafda2018-01-18 11:13:57 +000057 "test/configs",
Oystein Eftevaag51e06e52018-01-18 11:28:49 -080058 "tools:protoc_helper",
Primiano Tucci808d6df2018-03-31 13:24:18 +010059 "tools/ftrace_proto_gen:ftrace_proto_gen",
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -070060 "tools/proto_to_cpp",
Primiano Tuccib03ba362017-12-06 09:47:41 +000061 ]
Primiano Tucci21c19d82018-03-29 12:35:08 +010062 if (!build_with_android) {
Primiano Tucci5968caf2018-08-06 10:31:46 +010063 deps += [
64 ":trace_processor",
Primiano Tucci3cd31322018-10-11 20:06:56 +010065 "src/tracing:consumer_api_test",
Primiano Tucci5968caf2018-08-06 10:31:46 +010066 "tools/trace_to_text",
67 ]
Primiano Tucci21c19d82018-03-29 12:35:08 +010068 }
Primiano Tuccic96f71b2018-02-06 19:21:09 +000069 if (is_linux || is_android) {
Primiano Tucci808d6df2018-03-31 13:24:18 +010070 deps += [ "tools/skippy" ]
Primiano Tuccic96f71b2018-02-06 19:21:09 +000071 }
Primiano Tucci1640ffa2018-05-14 18:25:33 +010072 if (is_linux) {
73 deps += [ "tools:pipestats" ]
74 }
Primiano Tuccia1959712018-05-17 11:01:56 +010075 if (use_libfuzzer) {
76 deps += [ ":fuzzers" ]
77 }
Primiano Tuccib03ba362017-12-06 09:47:41 +000078 }
Primiano Tucciae2879e2017-09-27 11:02:09 +090079}
80
Primiano Tucci3faad742018-05-16 19:30:48 +010081# TODO(primiano): temporary workaround to:
82# 1) Prevent that the UI gets build automatically when doing ninja -C out/xx .
83# 2) Avoid breaking the chrome build, that right now depends on "all".
84group("default") {
85 testonly = true # allow to build also test targets
86 deps = [
87 ":all",
88 ]
89}
90
91if (build_standalone) {
92 group("ui") {
93 deps = [
94 "ui",
95 ]
96 }
Primiano Tucci5968caf2018-08-06 10:31:46 +010097
98 # The trace processor shell executable. An interactive shell that allows to
99 # make queries on the trace using the terminal.
100 group("trace_processor") {
101 deps = [
102 "src/trace_processor:trace_processor_shell",
103 ]
104 }
Primiano Tucci3faad742018-05-16 19:30:48 +0100105}
106
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000107executable("perfetto_unittests") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900108 testonly = true
109 deps = [
Primiano Tuccib03ba362017-12-06 09:47:41 +0000110 "gn:default_deps",
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000111 "gn:gtest_main",
Hector Dearman6cfec8a2018-03-14 16:54:09 +0000112 "src/base:unittests",
Bruce Dawsonc3e67632018-05-14 14:07:51 +0100113 "src/protozero:unittests",
Oystein Eftevaage5e84fb2018-06-01 17:34:56 -0700114 "src/tracing:unittests",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900115 ]
Primiano Tucci1640ffa2018-05-14 18:25:33 +0100116
Primiano Tucci931284e2017-12-11 09:23:53 +0000117 if (!build_with_chromium) {
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700118 deps += [
119 "src/ipc:unittests",
120 "src/perfetto_cmd:unittests",
Primiano Tucci808d6df2018-03-31 13:24:18 +0100121 "src/traced/probes:unittests",
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700122 "src/traced/probes/filesystem:unittests",
Primiano Tuccide82dae2018-06-04 16:17:49 +0200123 "src/traced/probes/ftrace:unittests",
Primiano Tucci808d6df2018-03-31 13:24:18 +0100124 "tools/ftrace_proto_gen:unittests",
Oystein Eftevaag067fd5b2018-03-27 12:39:30 -0700125 "tools/sanitizers_unittests",
126 ]
Primiano Tucci931284e2017-12-11 09:23:53 +0000127 }
Florian Mayerb64d6b12018-08-30 10:46:30 -0700128 if (should_build_heapprofd) {
129 # Restrict to clang, as libunwindstack and its dependencies is never
130 # built using GCC in the Android tree.
131 deps += [ "src/profiling/memory:unittests" ]
132 }
Hector Dearmanb6b029e2018-08-28 10:14:20 +0100133 if (build_standalone && !is_android) {
Lalit Maganticaed37e2018-06-01 03:03:08 +0100134 deps += [ "src/trace_processor:unittests" ]
135 }
Primiano Tuccib03ba362017-12-06 09:47:41 +0000136}
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800137
Primiano Tucci808d6df2018-03-31 13:24:18 +0100138if (!build_with_chromium) {
Primiano Tuccib03ba362017-12-06 09:47:41 +0000139 executable("perfetto_benchmarks") {
140 testonly = true
141 deps = [
142 "gn:default_deps",
Primiano Tuccide82dae2018-06-04 16:17:49 +0200143 "src/traced/probes/ftrace:benchmarks",
Primiano Tuccib03ba362017-12-06 09:47:41 +0000144 "src/tracing:tracing_benchmarks",
Hector Dearmanbc8368e2018-01-25 17:34:11 +0000145 "test:benchmark_main",
Lalit Magantibfc3d3e2018-03-22 20:28:38 +0000146 "test:end_to_end_benchmarks",
Primiano Tuccib03ba362017-12-06 09:47:41 +0000147 ]
Oystein Eftevaagdd727e42017-12-05 08:49:55 -0800148 }
Primiano Tucci4e49c022017-12-21 18:22:44 +0100149
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000150 executable("perfetto_integrationtests") {
151 testonly = true
152 deps = [
153 "gn:default_deps",
Florian Mayerd8bd81b2018-01-25 12:49:15 +0000154 "gn:gtest_main",
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 ]
Hector Dearman7f71d0e2018-08-09 11:26:10 +0100158 if (build_standalone && !is_android) {
159 deps += [ "src/trace_processor:integrationtests" ]
160 }
Lalit Maganti0b9a6ac2018-02-16 18:05:06 +0000161 if (build_with_android) {
162 cflags = [ "-DPERFETTO_BUILD_WITH_ANDROID" ]
163 }
Lalit Maganti79f2d7b2018-01-23 18:27:33 +0000164 }
165
Primiano Tuccif3837d52018-01-10 21:12:41 +0000166 if (monolithic_binaries) {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100167 libperfetto_target_type = "source_set"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000168 } else {
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100169 libperfetto_target_type = "shared_library"
Primiano Tuccif3837d52018-01-10 21:12:41 +0000170 }
171
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100172 target(libperfetto_target_type, "libperfetto") {
Primiano Tucci4e49c022017-12-21 18:22:44 +0100173 deps = [
174 "gn:default_deps",
Primiano Tucci6067e732018-01-08 16:19:40 +0000175 "src/traced/probes",
176 "src/traced/service",
Primiano Tucci3cd31322018-10-11 20:06:56 +0100177 "src/tracing:api",
Primiano Tucci6067e732018-01-08 16:19:40 +0000178 ]
179 }
180
Primiano Tucci3b729102018-01-08 18:16:36 +0000181 # The unprivileged trace daemon that listens for Producer and Consumer
182 # connections, handles the coordination of the tracing sessions and owns the
183 # log buffers.
Primiano Tucci6067e732018-01-08 16:19:40 +0000184 executable("traced") {
185 deps = [
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100186 ":libperfetto",
Primiano Tucci6067e732018-01-08 16:19:40 +0000187 "gn:default_deps",
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100188 "include/perfetto/traced",
Primiano Tucci6067e732018-01-08 16:19:40 +0000189 ]
190 sources = [
191 "src/traced/service/main.cc",
192 ]
193 }
194
Primiano Tucci3b729102018-01-08 18:16:36 +0000195 # The unprivileged daemon that is allowed to access tracefs (for ftrace).
196 # Registers as a Producer on the traced daemon.
Primiano Tucci6067e732018-01-08 16:19:40 +0000197 executable("traced_probes") {
198 deps = [
Primiano Tuccibdb2a592018-10-11 15:59:29 +0100199 ":libperfetto",
Primiano Tucci6067e732018-01-08 16:19:40 +0000200 "gn:default_deps",
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100201 "include/perfetto/traced",
Primiano Tucci6067e732018-01-08 16:19:40 +0000202 ]
203 sources = [
204 "src/traced/probes/main.cc",
Primiano Tucci4e49c022017-12-21 18:22:44 +0100205 ]
206 }
Primiano Tucci3b729102018-01-08 18:16:36 +0000207
208 # The command line client for Perfetto. Allows to configure / start / stop
209 # tracing, acting as a Consumer.
210 executable("perfetto") {
211 deps = [
Primiano Tucci3b729102018-01-08 18:16:36 +0000212 "gn:default_deps",
Hector Dearmanc443a362018-02-28 16:03:56 +0000213 "src/perfetto_cmd",
Primiano Tucci3b729102018-01-08 18:16:36 +0000214 ]
215 sources = [
Hector Dearmanc443a362018-02-28 16:03:56 +0000216 "src/perfetto_cmd/main.cc",
Primiano Tucci3b729102018-01-08 18:16:36 +0000217 ]
Lalit Maganti0b9a6ac2018-02-16 18:05:06 +0000218 if (is_android) {
219 deps += [ "src/base:android_task_runner" ]
220 }
Primiano Tucci6d848532018-01-17 10:32:33 +0000221 if (build_with_android) {
222 cflags = [ "-DPERFETTO_BUILD_WITH_ANDROID" ]
Primiano Tucci6d848532018-01-17 10:32:33 +0000223 libs = [
224 "binder",
225 "services",
226 "utils",
227 ]
228 }
Primiano Tucci3b729102018-01-08 18:16:36 +0000229 }
Primiano Tucci6aa75572018-03-21 05:33:14 -0700230
Primiano Tucci21c19d82018-03-29 12:35:08 +0100231 if (build_with_android) {
232 executable("trace_to_text") {
233 testonly = true
234 deps = [
235 "gn:default_deps",
236 "tools/trace_to_text:lib",
237 ]
238 }
Primiano Tucci21c19d82018-03-29 12:35:08 +0100239
Primiano Tucci808d6df2018-03-31 13:24:18 +0100240 # This target exports perfetto trace protos in the Android build system,
241 # allowing both host and device targets to implement custom parsers based on
242 # our protos.
243 static_library("perfetto_trace_protos") {
244 deps = [
245 "protos/perfetto/trace:lite",
246 ]
247 }
Primiano Tucci6aa75572018-03-21 05:33:14 -0700248 }
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700249}
250
251if (build_with_chromium) {
252 component("libperfetto") {
Primiano Tucci20b760c2018-01-19 12:36:12 +0000253 public_configs = [ "gn:public_config" ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800254 deps = [
255 "src/tracing",
256 ]
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700257 configs -= [ "//build/config/compiler:chromium_code" ]
258 configs += [ "//build/config/compiler:no_chromium_code" ]
259 public_deps = [
260 "include/perfetto/tracing/core",
Oystein Eftevaag6fcedac2018-07-02 12:02:55 -0700261 "protos/perfetto/trace:zero",
262 "protos/perfetto/trace/chrome:zero",
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700263 ]
Oystein Eftevaag5e8a4eb2018-01-09 11:41:58 -0800264 }
Oystein Eftevaaga812a942018-03-23 11:52:32 -0700265}
Primiano Tuccia1959712018-05-17 11:01:56 +0100266
Primiano Tucci59d6ace2018-09-26 22:24:20 +0100267if (!build_with_chromium) {
268 group("fuzzers") {
269 testonly = true
270 deps = [
271 "src/ipc:buffered_frame_deserializer_fuzzer",
272 "src/traced/probes/ftrace:cpu_reader_fuzzer",
273 "test:end_to_end_shared_memory_fuzzer",
274 ]
275 }
Primiano Tuccia1959712018-05-17 11:01:56 +0100276}
Florian Mayerb6a921f2018-10-18 18:55:23 +0100277
278if (!build_with_chromium) {
279 # TODO(fmayer): Investigate shared library for common pieces.
280 shared_library("heapprofd_client") {
281 deps = [
282 "src/profiling/memory:malloc_hooks",
283 ]
284 }
285
286 executable("heapprofd") {
287 deps = [
288 "gn:default_deps",
289 "src/base",
290 "src/base:unix_socket",
291 "src/profiling/memory:daemon",
292 "src/profiling/memory:wire_protocol",
293 ]
294 sources = [
295 "src/profiling/memory/main.cc",
296 ]
297 }
298}