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 15import("//build_overrides/build.gni") 16import("wasm_vars.gni") 17 18# Summary of our typical build configurations: 19 20# 1. Standalone builds 21# build_with_chromium = false 22# is_perfetto_build_generator = false 23# perfetto_build_standalone = true 24# perfetto_build_with_android = false 25# perfetto_build_with_embedder = false 26 27# 2. Android tree builds 28# build_with_chromium = false 29# is_perfetto_build_generator = true 30# perfetto_build_standalone = false 31# perfetto_build_with_android = true 32# perfetto_build_with_embedder = false 33 34# 3. Chromium tree builds 35# build_with_chromium = true 36# is_perfetto_build_generator = false 37# perfetto_build_standalone = false 38# perfetto_build_with_android = false 39# perfetto_build_with_embedder = true 40 41# 4. Builds in other embedder trees (e.g. V8 standalone) 42# build_with_chromium = false 43# is_perfetto_build_generator = false 44# perfetto_build_standalone = false 45# perfetto_build_with_android = false 46# perfetto_build_with_embedder = true 47 48# 5. Amalgamated sources (Client library) 49# build_with_chromium = false 50# is_perfetto_build_generator = true 51# perfetto_build_standalone = false 52# perfetto_build_with_android = false 53# perfetto_build_with_embedder = true 54 55# +----------------------------------------------------------------------------+ 56# | Toolchain / environment related configuration | 57# +----------------------------------------------------------------------------+ 58# This section contains a bunch of variables that are related with the toolchain 59# and the build environment. Only tools/gen_xxx should customize them. 60 61# Note that |build_with_chromium| is a global convention used by several 62# projects, set outside of our control. 63 64# Chromium sets this to true in its //build_overrides/build.gni. 65if (!defined(build_with_chromium)) { 66 build_with_chromium = false 67} 68 69if (!defined(is_nacl)) { 70 is_nacl = false 71} 72 73declare_args() { 74 # The Android blueprint file generator set this to true (as well as 75 # is_perfetto_build_generator). This is just about being built in the 76 # Android tree (AOSP and internal) and is NOT related with the target OS. 77 # In standalone Android builds and Chromium Android builds, this is false. 78 perfetto_build_with_android = false 79 80 # All the tools/gen_* scripts set this to true. This is mainly used to locate 81 # .gni files from //gn rather than //build. 82 is_perfetto_build_generator = false 83 84 # This is for override via `gn args` (e.g. for tools/gen_xxx). Embedders 85 # based on GN (e.g. v8) should NOT set this and instead directly sets 86 # perfetto_build_with_embedder=true in their GN files. 87 is_perfetto_embedder = false 88} 89 90# This can be overridden by embedders (e.g. v8) in their .gn(i) files. This must 91# be different from the GN args flag (is_perfetto_embedder) because of the way 92# GN works. 93if (!defined(perfetto_build_with_embedder)) { 94 perfetto_build_with_embedder = build_with_chromium || is_perfetto_embedder 95} 96 97perfetto_build_standalone = 98 !perfetto_build_with_android && !build_with_chromium && 99 !perfetto_build_with_embedder 100 101# Only relevant for GN builds. Sets the path where perfetto lives. This is // 102# for standalone builds and //third_party/perfetto/ in embedders. The embedder 103# can override it in its GN files. 104if (perfetto_build_standalone || is_perfetto_build_generator) { 105 perfetto_root_path = "//" 106 import("//gn/standalone/android.gni") # For android_api_level 107 import("//gn/standalone/sanitizers/vars.gni") # For is_fuzzer 108} else if (!defined(perfetto_root_path)) { 109 perfetto_root_path = "//third_party/perfetto/" 110 import("//build/config/android/config.gni") # For android_api_level 111} 112 113# Whether the ftrace producer and the service should be started 114# by the integration test or assumed to be running. 115# If we're building in the Android tree, we expect that the testing infra 116# will start the binaries in the system image before the tests are run. 117# In all other cases (i.e. when true), a temporary in-process instance will be 118# brought up by our own integrationtest harness. 119start_daemons_for_testing = !perfetto_build_with_android 120 121# +----------------------------------------------------------------------------+ 122# | Tunable build variables for embedders | 123# +----------------------------------------------------------------------------+ 124# The variables in this section allow embedders to enable/disable features 125# at the build-system level. This allows to opt-in into the various services 126# and tools. 127 128perfetto_force_dlog_default = "" 129if (build_with_chromium) { 130 perfetto_force_dlog_default = "off" 131} 132 133declare_args() { 134 # Enables build of platform-wide tracing services (traced, traced_probes) 135 # and executables (perfetto_cmd, trigger_perfetto). 136 # When disabled, only the client library and other auxiliary tools can be 137 # built (for Chromium and other GN embedders). 138 # Note that traced_probes is further conditioned by the GN variable 139 # enable_perfetto_traced_probes, in the declare_args() section below. 140 enable_perfetto_platform_services = 141 perfetto_build_standalone || perfetto_build_with_android 142 143 # Allow the embedder to use the IPC layer. In turn this allows to use the 144 # system backend in the client library. 145 # This includes building things that rely on POSIX sockets, this places 146 # limitations on the supported operating systems. 147 # For now the IPC layer is conservatively not enabled on Chromium+Windows 148 # builds. 149 enable_perfetto_ipc = 150 !is_fuchsia && !is_nacl && 151 (perfetto_build_standalone || perfetto_build_with_android || 152 (build_with_chromium && !is_win)) 153 154 # Makes the heap profiling daemon target reachable. It works only on Android, 155 # but is built on Linux as well for test/compiler coverage. 156 # On Android, it requires API level 26 due to libunwindstack. 157 enable_perfetto_heapprofd = 158 perfetto_build_with_android || 159 (perfetto_build_standalone && is_clang && 160 (is_linux || (is_android && android_api_level >= 26))) 161 162 # Build the perf event profiler (traced_perf). 163 # TODO(rsavitski): figure out how to make the android-core dependencies build 164 # under gcc (_Atomic and other issues). 165 enable_perfetto_traced_perf = 166 perfetto_build_with_android || 167 (perfetto_build_standalone && is_clang && is_linux) 168 169 # The Trace Processor: offline analytical engine to process traces and compute 170 # metrics using a SQL engine. 171 if (!defined(enable_perfetto_trace_processor)) { 172 enable_perfetto_trace_processor = 173 perfetto_build_standalone || build_with_chromium || 174 is_perfetto_build_generator 175 } 176 177 # Enables base::Watchdog. Is supported only on Linux-based platforms in 178 # standalone GN builds (NOT in bazel/blaze). 179 # gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating 180 # the perfetto_build_flags.h header. 181 enable_perfetto_watchdog = 182 perfetto_build_with_android || 183 (perfetto_build_standalone && !is_perfetto_build_generator) 184 185 # Misc host executable under tools/. 186 enable_perfetto_tools = 187 perfetto_build_standalone || perfetto_build_with_android 188 189 enable_perfetto_unittests = perfetto_build_standalone || 190 build_with_chromium || perfetto_build_with_android 191 192 enable_perfetto_integration_tests = 193 perfetto_build_standalone || perfetto_build_with_android 194 195 enable_perfetto_benchmarks = perfetto_build_standalone && !is_win 196 197 enable_perfetto_fuzzers = 198 perfetto_build_standalone && defined(is_fuzzer) && is_fuzzer 199 200 # Enables the write_version_header.py tool that generates a .h that contains a 201 # macro with the current git revision and latest release version from 202 # CHANGELOG. If false base/version.h will return "unknown". 203 enable_perfetto_version_gen = 204 perfetto_build_standalone || is_perfetto_build_generator || 205 perfetto_build_with_android 206 207 # Only for local development. When true the binaries (perfetto, traced, ...) 208 # are monolithic and don't use a common shared library. This is mainly to 209 # avoid LD_LIBRARY_PATH dances when testing locally. 210 # On Windows we default to monolithic executables, because pairing 211 # dllexport/import adds extra complexity for little benefit. Te only reason 212 # for monolithic_binaries=false is saving binary size, which matters mainly on 213 # Android. See also comments on PERFETTO_EXPORTED_ENTRYPOINT in compiler.h. 214 monolithic_binaries = is_win 215 216 # Whether DLOG should be enabled on debug builds (""), all builds ("on"), or 217 # none ("off"). We disable it by default for embedders to avoid spamming their 218 # console. 219 perfetto_force_dlog = perfetto_force_dlog_default 220 221 # Whether DCHECKs should be enabled or not. Values: "on" | "off" | "". 222 # By default ("") DCHECKs are enabled only: 223 # - If DCHECK_ALWAYS_ON is defined (which is mainly a Chromium-ism). 224 # - On debug builds (i.e. if NDEBUG is NOT defined) but only in Chromium, 225 # Android and standalone builds. 226 # - On all other builds (e.g., SDK) it's off regardless of NDEBUG (unless 227 # DCHECK_ALWAYS_ON is defined). 228 # See base/logging.h for the implementation of all this. 229 perfetto_force_dcheck = "" 230 231 # Installs a signal handler for the most common crash signals which unwinds 232 # the stack and prints the stack trace on stderr. Requires a dependency on 233 # libbacktrace when enabled. 234 enable_perfetto_stderr_crash_dump = 235 is_debug && perfetto_build_standalone && !is_wasm && !is_win 236 237 # Enables more aggressive compiler flags that assume recent Intel CPUs. 238 # Runtime checks during initialization will print an error message and exit 239 # if the CPU doesn't support those flags. 240 enable_perfetto_x64_cpu_opt = 241 current_cpu == "x64" && (is_linux || is_mac) && !is_wasm && 242 perfetto_build_standalone && !is_perfetto_build_generator 243} 244 245declare_args() { 246 perfetto_enable_git_rev_version_header = 247 enable_perfetto_version_gen && perfetto_build_standalone && 248 !is_perfetto_build_generator 249 250 # The traced_probes daemon is very Linux-specific, as it depends on ftrace and 251 # various /proc interfaces. There is no point making its code platform-neutral 252 # as it won't do anything useful on Windows. 253 # The only reason why we still build it on Mac OS is to be able to run the 254 # unittests there and making dev on mac less cumbersome. The traced_probes 255 # code happens to build cleanly and for now the mainteinance cost on Mac is 256 # extremely low. 257 enable_perfetto_traced_probes = enable_perfetto_platform_services && !is_win 258 259 # Whether info-level logging is enabled. 260 perfetto_verbose_logs_enabled = 261 !build_with_chromium || perfetto_force_dlog == "on" 262 263 # Enables the SQL query layer of trace processor. 264 enable_perfetto_trace_processor_sqlite = 265 enable_perfetto_trace_processor && 266 (build_with_chromium || !perfetto_build_with_embedder) 267 268 # Enables the optional SQLite percentile module. 269 enable_perfetto_trace_processor_percentile = 270 enable_perfetto_trace_processor && perfetto_build_standalone 271 272 # Enables the REPL interactive prompt in the trace processor. 273 enable_perfetto_trace_processor_linenoise = 274 perfetto_build_standalone && enable_perfetto_trace_processor && 275 (is_linux || is_android || is_mac) 276 277 # Enables JSON support in the trace processor. Required for JSON trace import 278 # and export. 279 enable_perfetto_trace_processor_json = 280 enable_perfetto_trace_processor && !perfetto_build_with_android 281 282 # Enables httpd RPC support in the trace processor. 283 # Further per-OS conditionals are applied in gn/BUILD.gn. 284 enable_perfetto_trace_processor_httpd = 285 enable_perfetto_trace_processor && 286 (perfetto_build_standalone || perfetto_build_with_android) 287 288 # Enables Zlib support. This is used both by the "perfetto" cmdline client 289 # (for compressing traces) and by trace processor (for compressed traces). 290 enable_perfetto_zlib = 291 (enable_perfetto_trace_processor && !build_with_chromium) || 292 enable_perfetto_platform_services 293 294 # Enables function name demangling using sources from llvm. Otherwise 295 # trace_processor falls back onto using the c++ runtime demangler, which 296 # typically handles only itanium mangling. 297 enable_perfetto_llvm_demangle = 298 enable_perfetto_trace_processor && perfetto_build_standalone 299} 300 301declare_args() { 302 # Enables the trace_to_text tool. 303 enable_perfetto_tools_trace_to_text = 304 enable_perfetto_tools && enable_perfetto_trace_processor_sqlite 305 306 # Allows to build the UI (TypeScript/ HTML / WASM) 307 enable_perfetto_ui = 308 perfetto_build_standalone && enable_perfetto_trace_processor_sqlite && 309 host_os != "win" 310 311 # Skip buildtools dependency checks (needed for ChromeOS). 312 skip_buildtools_check = false 313 314 # Used by CrOS system builds. Uses the system version of protobuf 315 # from /usr/include instead of the hermetic one. 316 perfetto_use_system_protobuf = false 317 318 perfetto_use_system_zlib = false 319} 320 321if (is_win) { 322 # clang-cl 323 perfetto_isystem_cflag = "/I" 324} else { 325 perfetto_isystem_cflag = "-isystem" 326} 327 328# +---------------------------------------------------------------------------+ 329# | Cross-checks | 330# +---------------------------------------------------------------------------+ 331 332# Exactly one between build_with_android, build_standalone and 333# build_with_embedder must be true. 334assert(perfetto_build_standalone || perfetto_build_with_android || 335 perfetto_build_with_embedder) 336assert(!(perfetto_build_with_android && perfetto_build_standalone)) 337assert(!(perfetto_build_with_embedder && perfetto_build_standalone)) 338assert(!(perfetto_build_with_android && perfetto_build_with_embedder)) 339 340# If |build_with_chromium| is true then also |perfetto_build_with_embedder| 341# must be true 342assert(!build_with_chromium || perfetto_build_with_embedder) 343 344# If |perfetto_build_with_android| is true then also 345# |is_perfetto_build_generator| must be true. 346assert(!perfetto_build_with_android || is_perfetto_build_generator) 347 348# We should never end up in a state where is_perfetto_embedder=true but 349# perfetto_build_with_embedder=false. 350assert(!is_perfetto_embedder || perfetto_build_with_embedder) 351 352# The monolithic binaries is not supported when building in the Android tree. 353assert(!monolithic_binaries || !perfetto_build_with_android) 354 355# Watchdog must be on in Android builds. 356assert(enable_perfetto_watchdog || !perfetto_build_with_android) 357 358assert(perfetto_force_dlog == "" || perfetto_force_dlog == "on" || 359 perfetto_force_dlog == "off") 360 361# If enable_perfetto_traced_probes is set, enable_perfetto_platform_services 362# must be set as well. Doesn't make sense to build traced_probes without the 363# rest. traced_probes integration tests depend on traced. 364assert(!enable_perfetto_traced_probes || enable_perfetto_platform_services) 365