-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.gn
351 lines (324 loc) · 10.2 KB
/
BUILD.gn
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# 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("gn/perfetto.gni")
import("gn/test.gni")
if (perfetto_build_standalone || perfetto_build_with_android) {
import("//gn/standalone/android.gni")
} else {
import("//build/config/android/config.gni")
}
# For use_libfuzzer.
if (perfetto_build_standalone || perfetto_build_with_android) {
import("//gn/standalone/sanitizers/vars.gni")
} else {
import("//build/config/sanitizers/sanitizers.gni")
}
declare_args() {
# 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.
monolithic_binaries = false
# libunwindstack requires API level 26 or newer.
should_build_heapprofd =
(perfetto_build_standalone || perfetto_build_with_android) && is_clang &&
(is_linux || is_android) &&
(!is_android || android_api_level >= 26 || perfetto_build_with_android)
}
assert(!monolithic_binaries || !perfetto_build_with_android)
group("all") {
testonly = true # allow to build also test targets
deps = [
":perfetto_unittests",
"src/protozero/protoc_plugin($host_toolchain)",
]
if (perfetto_build_standalone || perfetto_build_with_android) {
deps += [
":perfetto",
":perfetto_integrationtests",
":traced",
":traced_probes",
":trigger_perfetto",
"protos/perfetto/config:merged_config", # For syntax-checking the proto.
"protos/perfetto/trace:merged_trace", # For syntax-checking the proto.
"src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
"tools:protoc_helper",
]
if (perfetto_build_standalone) {
deps += [
":perfetto_benchmarks",
":trace_processor",
"src/profiling/memory:ring_buffer",
"src/tracing:consumer_api_test",
"test/configs",
"tools/ftrace_proto_gen:ftrace_proto_gen",
"tools/proto_to_cpp",
"tools/trace_to_text",
"tools/trace_to_text:trace_to_text_lite_host($host_toolchain)",
]
if (is_linux || is_android) {
deps += [ "tools/skippy" ]
deps += [ "tools/busy_threads" ]
deps += [ "tools/dump_ftrace_stats" ]
}
if (is_fuzzer) {
deps += [ ":fuzzers" ]
}
}
}
}
# TODO(primiano): temporary workaround to:
# 1) Prevent that the UI gets build automatically when doing ninja -C out/xx .
# 2) Avoid breaking the chrome build, that right now depends on "all".
group("default") {
testonly = true # allow to build also test targets
deps = [
":all",
]
}
if (perfetto_build_standalone) {
group("ui") {
deps = [
"ui",
]
}
# The trace processor shell executable. An interactive shell that allows to
# make queries on the trace using the terminal.
group("trace_processor") {
deps = [
"src/trace_processor:trace_processor_shell",
]
}
}
test("perfetto_unittests") {
deps = [
"gn:default_deps",
"gn:gtest_main",
"src/base:unittests",
"src/protozero:unittests",
"src/tracing:unittests",
]
if (perfetto_build_standalone || perfetto_build_with_android) {
deps += [
"src/ipc:unittests",
"src/perfetto_cmd:unittests",
"src/profiling/memory:ring_buffer_unittests",
"src/traced/probes:unittests",
"src/traced/probes/filesystem:unittests",
"src/traced/probes/ftrace:unittests",
"src/traced/service:unittests",
"tools/ftrace_proto_gen:unittests",
"tools/sanitizers_unittests",
]
}
if (should_build_heapprofd) {
# Restrict to clang, as libunwindstack and its dependencies is never
# built using GCC in the Android tree.
deps += [ "src/profiling/memory:unittests" ]
}
if (perfetto_build_standalone && !is_android) {
deps += [
"src/trace_processor:unittests",
]
}
}
if (perfetto_build_standalone || perfetto_build_with_android) {
test("perfetto_integrationtests") {
deps = [
"gn:default_deps",
"gn:gtest_main",
"src/traced/probes/ftrace:integrationtests",
"test:end_to_end_integrationtests",
]
if (perfetto_build_standalone && !is_android) {
deps += [ "src/trace_processor:integrationtests" ]
}
# TODO(fmayer): Fix in process daemons.
if (should_build_heapprofd && is_android && !start_daemons_for_testing) {
deps += [ "src/profiling/memory:end_to_end_tests" ]
}
}
if (monolithic_binaries) {
libperfetto_target_type = "source_set"
} else {
libperfetto_target_type = "shared_library"
}
target(libperfetto_target_type, "libperfetto") {
deps = [
"gn:default_deps",
"src/traced/probes",
"src/traced/service",
"src/tracing:api",
]
}
# The unprivileged trace daemon that listens for Producer and Consumer
# connections, handles the coordination of the tracing sessions and owns the
# log buffers.
executable("traced") {
deps = [
":libperfetto",
"gn:default_deps",
"include/perfetto/traced",
]
sources = [
"src/traced/service/main.cc",
]
}
# The unprivileged daemon that is allowed to access tracefs (for ftrace).
# Registers as a Producer on the traced daemon.
executable("traced_probes") {
deps = [
":libperfetto",
"gn:default_deps",
"include/perfetto/traced",
]
sources = [
"src/traced/probes/main.cc",
]
}
# The command line client for Perfetto. Allows to configure / start / stop
# tracing, acting as a Consumer.
executable("perfetto") {
deps = [
"gn:default_deps",
"src/perfetto_cmd",
]
sources = [
"src/perfetto_cmd/main.cc",
]
}
# Tool to finalize long running traces.
# This connects to traced as a producer and sends the triggers passed on the
# commandline. This is a subset of what the perfetto binary can do but we
# need a separate binary for programs that cannot (for good reason) use the
# additional functionality (for example starting traces via consumer socket)
# due to selinux rules.
executable("trigger_perfetto") {
deps = [
"gn:default_deps",
"src/perfetto_cmd:trigger_perfetto_cmd",
]
sources = [
"src/perfetto_cmd/trigger_perfetto_main.cc",
]
}
if (perfetto_build_with_android) {
executable("trace_to_text") {
testonly = true
deps = [
"gn:default_deps",
"tools/trace_to_text:full",
]
}
# This target exports perfetto trace protos in the Android build system,
# allowing both host and device targets to implement custom parsers based on
# our protos.
static_library("perfetto_trace_protos") {
deps = [
"protos/perfetto/trace:lite",
]
}
shared_library("libperfetto_android_internal") {
deps = [
"gn:default_deps",
"src/android_internal",
]
}
} # if (perfetto_build_with_android)
} # if (perfetto_build_standalone || perfetto_build_with_android)
if (perfetto_build_with_embedder) {
if (build_with_chromium) {
libperfetto_target_type = "component"
} else {
libperfetto_target_type = "source_set"
}
target(libperfetto_target_type, "libperfetto") {
public_configs = [ "gn:public_config" ]
deps = [
"src/tracing",
]
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
public_deps = [
"include/perfetto/tracing/core",
"protos/perfetto/trace:zero",
"protos/perfetto/trace/chrome:zero",
"protos/perfetto/trace/interned_data:zero",
"protos/perfetto/trace/track_event:zero",
]
}
}
if (perfetto_build_standalone) {
executable("perfetto_benchmarks") {
testonly = true
deps = [
"gn:default_deps",
"src/traced/probes/ftrace:benchmarks",
"src/tracing:tracing_benchmarks",
"test:benchmark_main",
"test:end_to_end_benchmarks",
]
}
group("fuzzers") {
testonly = true
deps = [
"src/ipc:buffered_frame_deserializer_fuzzer",
"src/profiling/memory:shared_ring_buffer_fuzzer",
"src/profiling/memory:shared_ring_buffer_write_fuzzer",
"src/profiling/memory:unwinding_fuzzer",
"src/protozero:protozero_decoder_fuzzer",
"src/trace_processor:trace_processor_fuzzer",
"src/traced/probes/ftrace:cpu_reader_fuzzer",
"test:end_to_end_shared_memory_fuzzer",
]
}
}
# WARNING: this builds correctly only when using the generated Android.bp.
#
# This library gets loaded into (and executes in) arbitrary android processes.
# Logging must be non-allocating. This is achieved by defining
# PERFETTO_ANDROID_ASYNC_SAFE_LOG, which needs to be set for all perfetto code
# being compiled for this library. When generating Android.bp, the |cflags|
# entry on this target is sufficient (as all sources are flattened into a
# single bp target). However this is not correctly reflected in the gn
# structure (which is a tree of targets) as the dependencies would not pick
# up the flag (and thus use the wrong logging macro).
#
# This is deemed acceptable as, at the time of writing, there is no interest in
# building this library standalone.
if (perfetto_build_with_android) {
# TODO(fmayer): Investigate shared library for common pieces.
shared_library("heapprofd_client") {
configs -= [ "//gn/standalone:android_liblog" ]
cflags = [ "-DPERFETTO_ANDROID_ASYNC_SAFE_LOG" ]
deps = [
"src/profiling/memory:malloc_hooks",
]
}
}
if (should_build_heapprofd) {
executable("heapprofd") {
deps = [
"gn:default_deps",
"protos/perfetto/trace:zero",
"src/base",
"src/base:unix_socket",
"src/profiling/memory:daemon",
"src/profiling/memory:wire_protocol",
"src/tracing:ipc",
]
sources = [
"src/profiling/memory/main.cc",
]
}
}