1 # 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 15 import("gn/perfetto.gni") 16 import("gn/test.gni") 17 18 if (perfetto_build_standalone || perfetto_build_with_android) { 19 import("//gn/standalone/android.gni") 20 } else { 21 import("//build/config/android/config.gni") 22 } 23 24 # For use_libfuzzer. 25 if (perfetto_build_standalone || perfetto_build_with_android) { 26 import("//gn/standalone/sanitizers/vars.gni") 27 } else { 28 import("//build/config/sanitizers/sanitizers.gni") 29 } 30 31 declare_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 36 37 # libunwindstack requires API level 26 or newer. 38 should_build_heapprofd = 39 (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) 42 } 43 assert(!monolithic_binaries || !perfetto_build_with_android) 44 45 group("all") { 46 testonly = true # allow to build also test targets 47 deps = [ 48 ":perfetto_unittests", 49 "src/protozero/protoc_plugin($host_toolchain)", 50 ] 51 if (perfetto_build_standalone || perfetto_build_with_android) { 52 deps += [ 53 ":perfetto", 54 ":perfetto_integrationtests", 55 ":traced", 56 ":traced_probes", 57 ":trigger_perfetto", 58 "protos/perfetto/config:merged_config", # For syntax-checking the proto. 59 "protos/perfetto/trace:merged_trace", # For syntax-checking the proto. 60 "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)", 61 "tools:protoc_helper", 62 ] 63 if (perfetto_build_standalone) { 64 deps += [ 65 ":perfetto_benchmarks", 66 ":trace_processor", 67 "src/profiling/memory:ring_buffer", 68 "src/tracing:consumer_api_test", 69 "test/configs", 70 "tools/ftrace_proto_gen:ftrace_proto_gen", 71 "tools/proto_to_cpp", 72 "tools/trace_to_text", 73 "tools/trace_to_text:trace_to_text_lite_host($host_toolchain)", 74 ] 75 if (is_linux || is_android) { 76 deps += [ "tools/skippy" ] 77 deps += [ "tools/busy_threads" ] 78 deps += [ "tools/dump_ftrace_stats" ] 79 } 80 if (is_fuzzer) { 81 deps += [ ":fuzzers" ] 82 } 83 } 84 } 85 } 86 87 # TODO(primiano): temporary workaround to: 88 # 1) Prevent that the UI gets build automatically when doing ninja -C out/xx . 89 # 2) Avoid breaking the chrome build, that right now depends on "all". 90 group("default") { 91 testonly = true # allow to build also test targets 92 deps = [ 93 ":all", 94 ] 95 } 96 97 if (perfetto_build_standalone) { 98 group("ui") { 99 deps = [ 100 "ui", 101 ] 102 } 103 104 # The trace processor shell executable. An interactive shell that allows to 105 # make queries on the trace using the terminal. 106 group("trace_processor") { 107 deps = [ 108 "src/trace_processor:trace_processor_shell", 109 ] 110 } 111 } 112 113 test("perfetto_unittests") { 114 deps = [ 115 "gn:default_deps", 116 "gn:gtest_main", 117 "src/base:unittests", 118 "src/protozero:unittests", 119 "src/tracing:unittests", 120 ] 121 122 if (perfetto_build_standalone || perfetto_build_with_android) { 123 deps += [ 124 "src/ipc:unittests", 125 "src/perfetto_cmd:unittests", 126 "src/profiling/memory:ring_buffer_unittests", 127 "src/traced/probes:unittests", 128 "src/traced/probes/filesystem:unittests", 129 "src/traced/probes/ftrace:unittests", 130 "src/traced/service:unittests", 131 "tools/ftrace_proto_gen:unittests", 132 "tools/sanitizers_unittests", 133 ] 134 } 135 if (should_build_heapprofd) { 136 # Restrict to clang, as libunwindstack and its dependencies is never 137 # built using GCC in the Android tree. 138 deps += [ "src/profiling/memory:unittests" ] 139 } 140 if (perfetto_build_standalone && !is_android) { 141 deps += [ 142 "src/trace_processor:unittests", 143 ] 144 } 145 } 146 147 if (perfetto_build_standalone || perfetto_build_with_android) { 148 test("perfetto_integrationtests") { 149 deps = [ 150 "gn:default_deps", 151 "gn:gtest_main", 152 "src/traced/probes/ftrace:integrationtests", 153 "test:end_to_end_integrationtests", 154 ] 155 if (perfetto_build_standalone && !is_android) { 156 deps += [ "src/trace_processor:integrationtests" ] 157 } 158 159 # TODO(fmayer): Fix in process daemons. 160 if (should_build_heapprofd && is_android && !start_daemons_for_testing) { 161 deps += [ "src/profiling/memory:end_to_end_tests" ] 162 } 163 } 164 165 if (monolithic_binaries) { 166 libperfetto_target_type = "source_set" 167 } else { 168 libperfetto_target_type = "shared_library" 169 } 170 171 target(libperfetto_target_type, "libperfetto") { 172 deps = [ 173 "gn:default_deps", 174 "src/traced/probes", 175 "src/traced/service", 176 "src/tracing:api", 177 ] 178 } 179 180 # The unprivileged trace daemon that listens for Producer and Consumer 181 # connections, handles the coordination of the tracing sessions and owns the 182 # log buffers. 183 executable("traced") { 184 deps = [ 185 ":libperfetto", 186 "gn:default_deps", 187 "include/perfetto/traced", 188 ] 189 sources = [ 190 "src/traced/service/main.cc", 191 ] 192 } 193 194 # The unprivileged daemon that is allowed to access tracefs (for ftrace). 195 # Registers as a Producer on the traced daemon. 196 executable("traced_probes") { 197 deps = [ 198 ":libperfetto", 199 "gn:default_deps", 200 "include/perfetto/traced", 201 ] 202 sources = [ 203 "src/traced/probes/main.cc", 204 ] 205 } 206 207 # The command line client for Perfetto. Allows to configure / start / stop 208 # tracing, acting as a Consumer. 209 executable("perfetto") { 210 deps = [ 211 "gn:default_deps", 212 "src/perfetto_cmd", 213 ] 214 sources = [ 215 "src/perfetto_cmd/main.cc", 216 ] 217 } 218 219 # Tool to finalize long running traces. 220 # This connects to traced as a producer and sends the triggers passed on the 221 # commandline. This is a subset of what the perfetto binary can do but we 222 # need a separate binary for programs that cannot (for good reason) use the 223 # additional functionality (for example starting traces via consumer socket) 224 # due to selinux rules. 225 executable("trigger_perfetto") { 226 deps = [ 227 "gn:default_deps", 228 "src/perfetto_cmd:trigger_perfetto_cmd", 229 ] 230 sources = [ 231 "src/perfetto_cmd/trigger_perfetto_main.cc", 232 ] 233 } 234 235 if (perfetto_build_with_android) { 236 executable("trace_to_text") { 237 testonly = true 238 deps = [ 239 "gn:default_deps", 240 "tools/trace_to_text:full", 241 ] 242 } 243 244 # This target exports perfetto trace protos in the Android build system, 245 # allowing both host and device targets to implement custom parsers based on 246 # our protos. 247 static_library("perfetto_trace_protos") { 248 deps = [ 249 "protos/perfetto/trace:lite", 250 ] 251 } 252 253 shared_library("libperfetto_android_internal") { 254 deps = [ 255 "gn:default_deps", 256 "src/android_internal", 257 ] 258 } 259 } # if (perfetto_build_with_android) 260 } # if (perfetto_build_standalone || perfetto_build_with_android) 261 262 if (perfetto_build_with_embedder) { 263 if (build_with_chromium) { 264 libperfetto_target_type = "component" 265 } else { 266 libperfetto_target_type = "source_set" 267 } 268 target(libperfetto_target_type, "libperfetto") { 269 public_configs = [ "gn:public_config" ] 270 deps = [ 271 "src/tracing", 272 ] 273 configs -= [ "//build/config/compiler:chromium_code" ] 274 configs += [ "//build/config/compiler:no_chromium_code" ] 275 public_deps = [ 276 "include/perfetto/tracing/core", 277 "protos/perfetto/trace:zero", 278 "protos/perfetto/trace/chrome:zero", 279 "protos/perfetto/trace/interned_data:zero", 280 "protos/perfetto/trace/track_event:zero", 281 ] 282 } 283 } 284 285 if (perfetto_build_standalone) { 286 executable("perfetto_benchmarks") { 287 testonly = true 288 deps = [ 289 "gn:default_deps", 290 "src/traced/probes/ftrace:benchmarks", 291 "src/tracing:tracing_benchmarks", 292 "test:benchmark_main", 293 "test:end_to_end_benchmarks", 294 ] 295 } 296 297 group("fuzzers") { 298 testonly = true 299 deps = [ 300 "src/ipc:buffered_frame_deserializer_fuzzer", 301 "src/profiling/memory:shared_ring_buffer_fuzzer", 302 "src/profiling/memory:shared_ring_buffer_write_fuzzer", 303 "src/profiling/memory:unwinding_fuzzer", 304 "src/protozero:protozero_decoder_fuzzer", 305 "src/trace_processor:trace_processor_fuzzer", 306 "src/traced/probes/ftrace:cpu_reader_fuzzer", 307 "test:end_to_end_shared_memory_fuzzer", 308 ] 309 } 310 } 311 312 # WARNING: this builds correctly only when using the generated Android.bp. 313 # 314 # This library gets loaded into (and executes in) arbitrary android processes. 315 # Logging must be non-allocating. This is achieved by defining 316 # PERFETTO_ANDROID_ASYNC_SAFE_LOG, which needs to be set for all perfetto code 317 # being compiled for this library. When generating Android.bp, the |cflags| 318 # entry on this target is sufficient (as all sources are flattened into a 319 # single bp target). However this is not correctly reflected in the gn 320 # structure (which is a tree of targets) as the dependencies would not pick 321 # up the flag (and thus use the wrong logging macro). 322 # 323 # This is deemed acceptable as, at the time of writing, there is no interest in 324 # building this library standalone. 325 if (perfetto_build_with_android) { 326 # TODO(fmayer): Investigate shared library for common pieces. 327 shared_library("heapprofd_client") { 328 configs -= [ "//gn/standalone:android_liblog" ] 329 cflags = [ "-DPERFETTO_ANDROID_ASYNC_SAFE_LOG" ] 330 deps = [ 331 "src/profiling/memory:malloc_hooks", 332 ] 333 } 334 } 335 336 if (should_build_heapprofd) { 337 executable("heapprofd") { 338 deps = [ 339 "gn:default_deps", 340 "protos/perfetto/trace:zero", 341 "src/base", 342 "src/base:unix_socket", 343 "src/profiling/memory:daemon", 344 "src/profiling/memory:wire_protocol", 345 "src/tracing:ipc", 346 ] 347 sources = [ 348 "src/profiling/memory/main.cc", 349 ] 350 } 351 } 352