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