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("../../gn/fuzzer.gni") 16import("../../gn/perfetto.gni") 17import("../../gn/test.gni") 18 19# Full version of the client API. Supports both the in-process backend and the 20# system backend (on posix systems and if enabled by the enable_perfetto_ipc). 21# The backends are designed to be dead-code-eliminated via linker's gc-section 22# when not use. See comments in Tracing::Initialize() in tracing.h. 23group("client_api") { 24 public_deps = [ 25 ":client_api_without_backends", 26 ":in_process_backend", 27 "../../gn:default_deps", 28 "../../include/perfetto/tracing", 29 "../../include/perfetto/tracing/core", 30 ] 31 if (enable_perfetto_ipc) { 32 public_deps += [ ":system_backend" ] 33 } else { 34 public_deps += [ ":system_backend_fake" ] 35 } 36} 37 38# This target checks that the client API builds without backends. This is to 39# check that no references to the backends are leaked from the implementation 40# internals. In turn, this allows to dead-code-eliminate unused backends when 41# using linker's gc-sections (or similar mechanism). 42if (perfetto_build_standalone) { 43 shared_library("client_api_no_backends_compile_test") { 44 deps = [ 45 ":client_api_without_backends", 46 ":platform_fake", 47 "../../gn:default_deps", 48 ] 49 } 50} 51 52# Separate target because the embedder might not want this. 53source_set("platform_impl") { 54 deps = [ 55 "../../gn:default_deps", 56 "../../include/perfetto/tracing", 57 "../base", 58 ] 59 sources = [ 60 "platform_posix.cc", 61 "platform_windows.cc", 62 ] 63} 64 65# Fake platform that allows buiding the client lib on all OSes. You can only use 66# those parts of the client lib that do not use the platform. 67source_set("platform_fake") { 68 deps = [ 69 "../../gn:default_deps", 70 "../../include/perfetto/tracing", 71 ] 72 sources = [ "platform_fake.cc" ] 73} 74 75# Code that both public headers and other non-public sources (e.g. 76# src/tracing/core) need to depend on. It cannot be in the root :tracing target 77# otherwise there would be a cyclic dependency because public itself needs to 78# depend on tracing. 79source_set("common") { 80 deps = [ 81 "../../gn:default_deps", 82 "../../include/perfetto/tracing", 83 ] 84 sources = [ "trace_writer_base.cc" ] 85} 86 87# Base target for the client API. On its own doesn't provide any backend other 88# than the unsupported one. 89source_set("client_api_without_backends") { 90 deps = [ 91 "../../include/perfetto/tracing/core", 92 "../../protos/perfetto/common:zero", 93 "../../protos/perfetto/config:cpp", 94 "../../protos/perfetto/config/interceptors:cpp", 95 "../../protos/perfetto/config/track_event:cpp", 96 "../base", 97 "core", 98 ] 99 public_deps = [ 100 "../../gn:default_deps", 101 "../../include/perfetto/tracing", 102 ] 103 sources = [ 104 "console_interceptor.cc", 105 "data_source.cc", 106 "debug_annotation.cc", 107 "event_context.cc", 108 "interceptor.cc", 109 "internal/checked_scope.cc", 110 "internal/interceptor_trace_writer.cc", 111 "internal/tracing_backend_fake.cc", 112 "internal/tracing_muxer_fake.cc", 113 "internal/tracing_muxer_fake.h", 114 "internal/tracing_muxer_impl.cc", 115 "internal/tracing_muxer_impl.h", 116 "internal/track_event_internal.cc", 117 "internal/track_event_interned_fields.cc", 118 "platform.cc", 119 "traced_value.cc", 120 "tracing.cc", 121 "tracing_policy.cc", 122 "track.cc", 123 "track_event_category_registry.cc", 124 "track_event_legacy.cc", 125 "track_event_state_tracker.cc", 126 "virtual_destructors.cc", 127 ] 128 assert_no_deps = [ "service" ] 129 if (enable_perfetto_ipc) { 130 assert_no_deps += [ 131 "../ipc:common", 132 "ipc/common", 133 ] 134 } 135} 136 137# Separate target because the embedder might not want this. 138source_set("integrationtests") { 139 testonly = true 140 deps = [ 141 "../../gn:default_deps", 142 "../../gn:gtest_and_gmock", 143 "../../include/perfetto/ext/tracing/ipc", 144 "../../include/perfetto/tracing", 145 "../../protos/perfetto/trace:cpp", 146 "../base", 147 "../base:test_support", 148 ] 149 sources = [ "internal/tracing_muxer_impl_integrationtest.cc" ] 150} 151 152perfetto_unittest_source_set("unittests") { 153 testonly = true 154 deps = [ 155 "../../gn:default_deps", 156 "../../gn:gtest_and_gmock", 157 "../../protos/perfetto/trace:lite", 158 "../../protos/perfetto/trace/track_event:lite", 159 "../base", 160 "../base:test_support", 161 "test:test_support", 162 ] 163 164 sources = [] 165 166 # TODO(primiano): remove the build_with_chromium conditional once the root 167 # //BUILD.gn:libperfetto (in chromium) stops adding tracing:platform_fake. 168 # The problem is the following: in chrome builds we end up with duplicate 169 # symbol definitions in the test because both platforms (impl and fake) are 170 # present: impl added here and fake coming from chromium's base (full path: 171 # perfetto_unittests -> //(chromium)base:test_support -> //(chromium)base 172 # -> libperfetto -> platform_fake. 173 if (!build_with_chromium) { 174 deps += [ 175 ":client_api_without_backends", 176 ":platform_impl", 177 ] 178 179 sources += [ 180 "internal/interceptor_trace_writer_unittest.cc", 181 "traced_proto_unittest.cc", 182 "traced_value_unittest.cc", 183 ] 184 } 185} 186 187# System backend: connects to an external "traced" instance via a UNIX socket. 188# Requires the IPC layer and is supported only on posix systems. 189if (enable_perfetto_ipc) { 190 source_set("system_backend") { 191 public_deps = [ "../../include/perfetto/tracing" ] 192 deps = [ 193 ":client_api_without_backends", 194 "../../gn:default_deps", 195 "../../include/perfetto/tracing/core", 196 "../base", 197 "ipc:common", 198 "ipc/producer", 199 "ipc/service", 200 ] 201 if (enable_perfetto_system_consumer) { 202 deps += [ "ipc/consumer" ] 203 } 204 sources = [ "internal/system_tracing_backend.cc" ] 205 } 206} else { 207 source_set("system_backend_fake") { 208 public_deps = [ "../../include/perfetto/tracing" ] 209 deps = [ 210 "../../gn:default_deps", 211 "../base", 212 ] 213 sources = [ "internal/system_tracing_backend_fake.cc" ] 214 } 215} 216 217# In-process backend: starts the tracing service in-process on a dedicated 218# thread. It depends only on having a valid "platform" target. It has a larger 219# binary size cost because links in all the service code. 220source_set("in_process_backend") { 221 public_deps = [ "../../include/perfetto/tracing" ] 222 deps = [ 223 ":client_api_without_backends", 224 "../../gn:default_deps", 225 "../../include/perfetto/tracing/core", 226 "../base", 227 "core", 228 "service", 229 ] 230 sources = [ "internal/in_process_tracing_backend.cc" ] 231} 232 233if (enable_perfetto_benchmarks) { 234 source_set("benchmarks") { 235 testonly = true 236 deps = [ 237 ":platform_impl", 238 "../..:libperfetto_client_experimental", 239 "../../gn:benchmark", 240 "../../gn:default_deps", 241 ] 242 sources = [ "api_benchmark.cc" ] 243 } 244} 245