blob: d8f8c55220b5e706be80a886f55fdc6610b4995f [file] [log] [blame]
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build_overrides/build.gni")
import("wasm_vars.gni")
# Summary of our typical build configurations:
# 1. Standalone builds
# build_with_chromium = false
# is_perfetto_build_generator = false
# perfetto_build_standalone = true
# perfetto_build_with_android = false
# perfetto_build_with_embedder = false
# 2. Android tree builds
# build_with_chromium = false
# is_perfetto_build_generator = true
# perfetto_build_standalone = false
# perfetto_build_with_android = true
# perfetto_build_with_embedder = false
# 3. Chromium tree builds
# build_with_chromium = true
# is_perfetto_build_generator = false
# perfetto_build_standalone = false
# perfetto_build_with_android = false
# perfetto_build_with_embedder = true
# 4. Builds in other embedder trees (e.g. V8 standalone)
# build_with_chromium = false
# is_perfetto_build_generator = false
# perfetto_build_standalone = false
# perfetto_build_with_android = false
# perfetto_build_with_embedder = true
# 5. Amalgamated sources (Client library)
# build_with_chromium = false
# is_perfetto_build_generator = true
# perfetto_build_standalone = false
# perfetto_build_with_android = false
# perfetto_build_with_embedder = true
# +----------------------------------------------------------------------------+
# | Toolchain / environment related configuration |
# +----------------------------------------------------------------------------+
# This section contains a bunch of variables that are related with the toolchain
# and the build environment. Only tools/gen_xxx should customize them.
# Note that |build_with_chromium| is a global convention used by several
# projects, set outside of our control.
# Chromium sets this to true in its //build_overrides/build.gni.
if (!defined(build_with_chromium)) {
build_with_chromium = false
}
if (!defined(is_nacl)) {
is_nacl = false
}
declare_args() {
# The Android blueprint file generator set this to true (as well as
# is_perfetto_build_generator). This is just about being built in the
# Android tree (AOSP and internal) and is NOT related with the target OS.
# In standalone Android builds and Chromium Android builds, this is false.
perfetto_build_with_android = false
# All the tools/gen_* scripts set this to true. This is mainly used to locate
# .gni files from //gn rather than //build.
is_perfetto_build_generator = false
# This is for override via `gn args` (e.g. for tools/gen_xxx). Embedders
# based on GN (e.g. v8) should NOT set this and instead directly sets
# perfetto_build_with_embedder=true in their GN files.
is_perfetto_embedder = false
}
# This can be overridden by embedders (e.g. v8) in their .gn(i) files. This must
# be different from the GN args flag (is_perfetto_embedder) because of the way
# GN works.
if (!defined(perfetto_build_with_embedder)) {
perfetto_build_with_embedder = build_with_chromium || is_perfetto_embedder
}
perfetto_build_standalone =
!perfetto_build_with_android && !build_with_chromium &&
!perfetto_build_with_embedder
# Only relevant for GN builds. Sets the path where perfetto lives. This is //
# for standalone builds and //third_party/perfetto/ in embedders. The embedder
# can override it in its GN files.
if (perfetto_build_standalone || is_perfetto_build_generator) {
perfetto_root_path = "//"
import("//gn/standalone/android.gni") # For android_api_level
import("//gn/standalone/sanitizers/vars.gni") # For is_fuzzer
} else if (!defined(perfetto_root_path)) {
perfetto_root_path = "//third_party/perfetto/"
import("//build/config/android/config.gni") # For android_api_level
}
# Whether the ftrace producer and the service should be started
# by the integration test or assumed to be running.
# If we're building in the Android tree, we expect that the testing infra
# will start the binaries in the system image before the tests are run.
# In all other cases (i.e. when true), a temporary in-process instance will be
# brought up by our own integrationtest harness.
start_daemons_for_testing = !perfetto_build_with_android
# +----------------------------------------------------------------------------+
# | Tunable build variables for embedders |
# +----------------------------------------------------------------------------+
# The variables in this section allow embedders to enable/disable features
# at the build-system level. This allows to opt-in into the various services
# and tools.
perfetto_force_dlog_default = ""
if (build_with_chromium) {
perfetto_force_dlog_default = "off"
}
declare_args() {
# Enables build of platform-wide tracing services (traced, traced_probes)
# and executables (perfetto_cmd, trigger_perfetto).
# When disabled, only the client library and other auxiliary tools can be
# built (for Chromium and other GN embedders).
# Note that traced_probes is further conditioned by the GN variable
# enable_perfetto_traced_probes, in the declare_args() section below.
enable_perfetto_platform_services =
perfetto_build_standalone || perfetto_build_with_android
# Allow the embedder to use the IPC layer. In turn this allows to use the
# system backend in the client library.
# This includes building things that rely on POSIX sockets, this places
# limitations on the supported operating systems.
# For now the IPC layer is conservatively not enabled on Chromium+Windows
# builds.
enable_perfetto_ipc =
!is_nacl && (perfetto_build_standalone || perfetto_build_with_android ||
(build_with_chromium && !is_win) || is_fuchsia)
# Makes the heap profiling daemon target reachable. It works only on Android,
# but is built on Linux as well for test/compiler coverage.
# On Android, it requires API level 26 due to libunwindstack.
enable_perfetto_heapprofd =
perfetto_build_with_android ||
(perfetto_build_standalone && is_clang &&
(is_linux || (is_android && android_api_level >= 26)))
# Build the perf event profiler (traced_perf).
# TODO(rsavitski): figure out how to make the android-core dependencies build
# under gcc (_Atomic and other issues).
enable_perfetto_traced_perf =
perfetto_build_with_android ||
(perfetto_build_standalone && is_clang &&
(is_linux || (is_android && android_api_level >= 29)))
# The Trace Processor: offline analytical engine to process traces and compute
# metrics using a SQL engine.
if (!defined(enable_perfetto_trace_processor)) {
enable_perfetto_trace_processor =
perfetto_build_standalone || build_with_chromium ||
is_perfetto_build_generator
}
# Enables base::Watchdog. Is supported only on Linux-based platforms in
# standalone GN builds (NOT in bazel/blaze).
# gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating
# the perfetto_build_flags.h header.
enable_perfetto_watchdog =
perfetto_build_with_android ||
(perfetto_build_standalone && !is_perfetto_build_generator)
# Misc host executable under tools/.
enable_perfetto_tools =
perfetto_build_standalone || perfetto_build_with_android
enable_perfetto_unittests = perfetto_build_standalone ||
build_with_chromium || perfetto_build_with_android
enable_perfetto_integration_tests =
perfetto_build_standalone || perfetto_build_with_android
enable_perfetto_benchmarks = perfetto_build_standalone && !is_win
enable_perfetto_fuzzers =
perfetto_build_standalone && defined(is_fuzzer) && is_fuzzer
# Enables the write_version_header.py tool that generates a .h that contains a
# macro with the current git revision and latest release version from
# CHANGELOG. If false base/version.h will return "unknown".
enable_perfetto_version_gen =
perfetto_build_standalone || is_perfetto_build_generator ||
perfetto_build_with_android
# Only for local development. When true the binaries (perfetto, traced, ...)
# are monolithic and don't use a common shared library. This is mainly to
# avoid LD_LIBRARY_PATH dances when testing locally.
# On Windows we default to monolithic executables, because pairing
# dllexport/import adds extra complexity for little benefit. Te only reason
# for monolithic_binaries=false is saving binary size, which matters mainly on
# Android. See also comments on PERFETTO_EXPORT_ENTRYPOINT in compiler.h.
monolithic_binaries = !perfetto_build_with_android && (is_win || is_mac)
# Whether DLOG should be enabled on debug builds (""), all builds ("on"), or
# none ("off"). We disable it by default for embedders to avoid spamming their
# console.
perfetto_force_dlog = perfetto_force_dlog_default
# Whether DCHECKs should be enabled or not. Values: "on" | "off" | "".
# By default ("") DCHECKs are enabled only:
# - If DCHECK_ALWAYS_ON is defined (which is mainly a Chromium-ism).
# - On debug builds (i.e. if NDEBUG is NOT defined) but only in Chromium,
# Android and standalone builds.
# - On all other builds (e.g., SDK) it's off regardless of NDEBUG (unless
# DCHECK_ALWAYS_ON is defined).
# See base/logging.h for the implementation of all this.
perfetto_force_dcheck = ""
# Installs a signal handler for the most common crash signals which unwinds
# the stack and prints the stack trace on stderr. Requires a dependency on
# libbacktrace when enabled.
enable_perfetto_stderr_crash_dump =
is_debug && perfetto_build_standalone && !is_wasm && !is_win
# Enables more aggressive compiler flags that assume recent Intel CPUs.
# Runtime checks during initialization will print an error message and exit
# if the CPU doesn't support those flags.
# Don't enable by default for MacOS. Old Intel Macs as used in CIs
# etc don't have the fancy CPU instructions (i.e. AVX2) this implies.
enable_perfetto_x64_cpu_opt =
current_cpu == "x64" && is_linux && !is_wasm &&
perfetto_build_standalone && !is_perfetto_build_generator
}
declare_args() {
# When false, it disables system backend consumer support in the Perfetto SDK.
# Saves ~300KB binary size.
if (!defined(enable_perfetto_system_consumer)) {
enable_perfetto_system_consumer = enable_perfetto_ipc
}
}
declare_args() {
perfetto_enable_git_rev_version_header =
enable_perfetto_version_gen && perfetto_build_standalone &&
!is_perfetto_build_generator
# The traced_probes daemon is very Linux-specific, as it depends on ftrace and
# various /proc interfaces. There is no point making its code platform-neutral
# as it won't do anything useful on Windows.
# The only reason why we still build it on Mac OS is to be able to run the
# unittests there and making dev on mac less cumbersome. The traced_probes
# code happens to build cleanly and for now the mainteinance cost on Mac is
# extremely low.
enable_perfetto_traced_probes = enable_perfetto_platform_services && !is_win
# The relay service is enabled when platform services are enabled.
# TODO(chinglinyu) check if we can enable on Windows.
enable_perfetto_traced_relay = enable_perfetto_platform_services && !is_win
# Whether info-level logging is enabled.
perfetto_verbose_logs_enabled =
!build_with_chromium || perfetto_force_dlog == "on"
# Enables the SQL query layer of trace processor.
enable_perfetto_trace_processor_sqlite =
enable_perfetto_trace_processor &&
(build_with_chromium || !perfetto_build_with_embedder)
# Enables the optional SQLite percentile module.
enable_perfetto_trace_processor_percentile =
enable_perfetto_trace_processor &&
(perfetto_build_standalone || perfetto_build_with_android)
# Enables the REPL interactive prompt in the trace processor.
enable_perfetto_trace_processor_linenoise =
perfetto_build_standalone && enable_perfetto_trace_processor &&
(is_linux || is_android || is_mac)
# Enables JSON support in the trace processor. Required for JSON trace import
# and export.
enable_perfetto_trace_processor_json =
enable_perfetto_trace_processor && !perfetto_build_with_android
# Enables httpd RPC support in the trace processor.
# Further per-OS conditionals are applied in gn/BUILD.gn.
enable_perfetto_trace_processor_httpd =
enable_perfetto_trace_processor &&
(perfetto_build_standalone || perfetto_build_with_android)
# Enables Zlib support. This is used to compress traces (by the tracing
# service and by the "perfetto" cmdline client) and to decompress traces (by
# trace_processor).
enable_perfetto_zlib =
enable_perfetto_trace_processor || enable_perfetto_platform_services
# Enables function name demangling using sources from llvm. Otherwise
# trace_processor falls back onto using the c++ runtime demangler, which
# typically handles only itanium mangling.
enable_perfetto_llvm_demangle =
enable_perfetto_trace_processor && perfetto_build_standalone
# Enables gRPC in the Perfetto codebase. gRPC significantly increases build
# times and the general footprint of Perfetto. As it only required for
# BigTrace and even then only to build the final ready-to-ship binary, don't
# enable this by default.
enable_perfetto_grpc = false
}
declare_args() {
# Enables the traceconv tool.
enable_perfetto_traceconv =
enable_perfetto_tools && enable_perfetto_trace_processor_sqlite
# Allows to build the UI (TypeScript/ HTML / WASM)
enable_perfetto_ui =
perfetto_build_standalone && enable_perfetto_trace_processor_sqlite &&
host_os != "win"
# Allows to build the perfetto.dev website.
# WARNING: if this flag is enabled, the build performs globbing at generation
# time. Incremental builds that add/remove files will not be supported without
# rerunning gn.
enable_perfetto_site = false
# Skip buildtools dependency checks (needed for ChromeOS).
skip_buildtools_check = false
# Used by CrOS builds. Uses pkg-config to determine the appropriate flags
# for including and linking system libraries.
# set `pkg_config` to the `BUILD_PKG_CONFIG` and
# set `target_pkg_config` to the target `PKG_CONFIG`.
# Note: that if this is enabled `perfetto_use_system_protobuf` should be also.
perfetto_use_pkgconfig = false
# Used by CrOS system builds. Uses the system version of protobuf
# from /usr/include instead of the hermetic one.
perfetto_use_system_protobuf = false
# Used by CrOS system builds. Uses the system version of sqlite
# from /usr/include instead of the hermetic one.
perfetto_use_system_sqlite = false
perfetto_use_system_zlib = false
}
if (is_win) {
# clang-cl
perfetto_isystem_cflag = "/I"
} else {
perfetto_isystem_cflag = "-isystem"
}
# +---------------------------------------------------------------------------+
# | Cross-checks |
# +---------------------------------------------------------------------------+
# Exactly one between build_with_android, build_standalone and
# build_with_embedder must be true.
assert(perfetto_build_standalone || perfetto_build_with_android ||
perfetto_build_with_embedder)
assert(!(perfetto_build_with_android && perfetto_build_standalone))
assert(!(perfetto_build_with_embedder && perfetto_build_standalone))
assert(!(perfetto_build_with_android && perfetto_build_with_embedder))
# If |build_with_chromium| is true then also |perfetto_build_with_embedder|
# must be true
assert(!build_with_chromium || perfetto_build_with_embedder)
# If |perfetto_build_with_android| is true then also
# |is_perfetto_build_generator| must be true.
assert(!perfetto_build_with_android || is_perfetto_build_generator)
# We should never end up in a state where is_perfetto_embedder=true but
# perfetto_build_with_embedder=false.
assert(!is_perfetto_embedder || perfetto_build_with_embedder)
# The monolithic binaries is not supported when building in the Android tree.
assert(!monolithic_binaries || !perfetto_build_with_android)
# Watchdog must be on in Android builds.
assert(enable_perfetto_watchdog || !perfetto_build_with_android)
assert(perfetto_force_dlog == "" || perfetto_force_dlog == "on" ||
perfetto_force_dlog == "off")
# If enable_perfetto_traced_probes is set, enable_perfetto_platform_services
# must be set as well. Doesn't make sense to build traced_probes without the
# rest. traced_probes integration tests depend on traced.
assert(!enable_perfetto_traced_probes || enable_perfetto_platform_services)
# |perfetto_use_pkgconfig| changes the behavior of
# |perfetto_use_system_protobuf|, so if perfetto_use_pkgconfig is set,
# |perfetto_use_system_protobuf| must be set.
assert(!perfetto_use_pkgconfig || perfetto_use_system_protobuf,
"perfetto_use_pkgconfig requires perfetto_use_system_protobuf")