aboutsummaryrefslogtreecommitdiff
path: root/src/tracing/BUILD.gn
blob: 2440d39f10a841caca4252e2ee20c6f025b512d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# 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("../../gn/fuzzer.gni")
import("../../gn/perfetto.gni")
import("../../gn/test.gni")

# Full version of the client API. Supports both the in-process backend and the
# system backend (on posix systems and if enabled by the enable_perfetto_ipc).
# The backends are designed to be dead-code-eliminated via linker's gc-section
# when not use. See comments in Tracing::Initialize() in tracing.h.
group("client_api") {
  public_deps = [
    ":client_api_without_backends",
    ":in_process_backend",
    "../../gn:default_deps",
    "../../include/perfetto/tracing",
    "../../include/perfetto/tracing/core",
  ]
  if (enable_perfetto_ipc) {
    public_deps += [ ":system_backend" ]
  } else {
    public_deps += [ ":system_backend_fake" ]
  }
}

# This target checks that the client API builds without backends. This is to
# check that no references to the backends are leaked from the implementation
# internals. In turn, this allows to dead-code-eliminate unused backends when
# using linker's gc-sections (or similar mechanism).
if (perfetto_build_standalone) {
  shared_library("client_api_no_backends_compile_test") {
    deps = [
      ":client_api_without_backends",
      ":platform_fake",
      "../../gn:default_deps",
    ]
  }
}

# Separate target because the embedder might not want this (e.g. on Windows).
source_set("platform_impl") {
  deps = [
    "../../gn:default_deps",
    "../../include/perfetto/tracing",
    "../base",
  ]
  sources = [ "platform_posix.cc" ]
}

# Fake platform that allows buiding the client lib on all OSes. You can only use
# those parts of the client lib that do not use the platform.
source_set("platform_fake") {
  deps = [
    "../../gn:default_deps",
    "../../include/perfetto/tracing",
  ]
  sources = [ "platform_fake.cc" ]
}

# Code that both public headers and other non-public sources (e.g.
# src/tracing/core) need to depend on. It cannot be in the root :tracing target
# otherwise there would be a cyclic dependency because public itself needs to
# depend on tracing.
source_set("common") {
  deps = [
    "../../gn:default_deps",
    "../../include/perfetto/tracing",
  ]
  sources = [ "trace_writer_base.cc" ]
}

# Base target for the client API. On its own doesn't provide any backend other
# than the unsupported one.
source_set("client_api_without_backends") {
  deps = [
    "../../include/perfetto/tracing/core",
    "../../protos/perfetto/common:zero",
    "../../protos/perfetto/config:cpp",
    "../../protos/perfetto/config/interceptors:zero",
    "../../protos/perfetto/config/track_event:cpp",
    "../base",
    "core",
  ]
  public_deps = [
    "../../gn:default_deps",
    "../../include/perfetto/tracing",
  ]
  sources = [
    "console_interceptor.cc",
    "data_source.cc",
    "debug_annotation.cc",
    "event_context.cc",
    "interceptor.cc",
    "internal/checked_scope.cc",
    "internal/interceptor_trace_writer.cc",
    "internal/tracing_backend_fake.cc",
    "internal/tracing_muxer_fake.cc",
    "internal/tracing_muxer_fake.h",
    "internal/tracing_muxer_impl.cc",
    "internal/tracing_muxer_impl.h",
    "internal/track_event_internal.cc",
    "internal/track_event_interned_fields.cc",
    "platform.cc",
    "traced_value.cc",
    "tracing.cc",
    "tracing_policy.cc",
    "track.cc",
    "track_event_category_registry.cc",
    "track_event_legacy.cc",
    "track_event_state_tracker.cc",
    "virtual_destructors.cc",
  ]
  assert_no_deps = [ "core:service" ]
  if (enable_perfetto_ipc) {
    assert_no_deps += [
      "../ipc:common",
      "ipc/common",
    ]
  }
}

perfetto_unittest_source_set("unittests") {
  testonly = true
  deps = [
    "../../protos/perfetto/trace:lite",
    "../../protos/perfetto/trace/track_event:lite",
    "../base",
    "../base:test_support",
    "test:test_support",
  ]

  sources = []

  # TODO(primiano): remove the build_with_chromium conditional once the root
  # //BUILD.gn:libperfetto (in chromium) stops adding tracing:platform_fake.
  # The problem is the following: in chrome builds we end up with duplicate
  # symbol definitions in the test because both platorm (impl and fake) are
  # present: impl added here and fake coming from chromium's base (full path:
  # perfetto_unittests -> //(chromium)base:test_support -> //(chromium)base
  # -> libperfetto -> platform_fake.
  if (!build_with_chromium) {
    deps += [
      ":client_api_without_backends",
      ":platform_impl",
    ]
    sources += [
      "traced_proto_unittest.cc",
      "traced_value_unittest.cc",
    ]
  }
}

# System backend: connects to an external "traced" instance via a UNIX socket.
# Requires the IPC layer and is supported only on posix systems.
if (enable_perfetto_ipc) {
  source_set("system_backend") {
    public_deps = [ "../../include/perfetto/tracing" ]
    deps = [
      ":client_api_without_backends",
      "../../gn:default_deps",
      "../../include/perfetto/tracing/core",
      "../base",
      "ipc/consumer",
      "ipc/producer",
      "ipc/service",
    ]
    sources = [ "internal/system_tracing_backend.cc" ]
  }
} else {
  source_set("system_backend_fake") {
    public_deps = [ "../../include/perfetto/tracing" ]
    deps = [
      "../../gn:default_deps",
      "../base",
    ]
    sources = [ "internal/system_tracing_backend_fake.cc" ]
  }
}

# In-process backend: starts the tracing service in-process on a dedicated
# thread. It depends only on having a valid "platform" target. It has a larger
# binary size cost because links in all the service code.
source_set("in_process_backend") {
  public_deps = [ "../../include/perfetto/tracing" ]
  deps = [
    ":client_api_without_backends",
    "../../gn:default_deps",
    "../../include/perfetto/tracing/core",
    "../base",
    "core:service",
  ]
  sources = [ "internal/in_process_tracing_backend.cc" ]
}

if (enable_perfetto_benchmarks) {
  source_set("benchmarks") {
    testonly = true
    deps = [
      ":platform_impl",
      "../..:libperfetto_client_experimental",
      "../../gn:benchmark",
      "../../gn:default_deps",
    ]
    sources = [ "api_benchmark.cc" ]
  }
}