blob: 9ef32c291083a6f1518f4f3eefcf0b1ffcf0d204 [file] [log] [blame]
Florian Mayerc9b84232018-08-02 11:17:03 +01001# Copyright (C) 2018 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
Primiano Tucci13ae72f2019-06-06 10:53:02 +010015import("../../../gn/fuzzer.gni")
16import("../../../gn/perfetto.gni")
Primiano Tucci02c11762019-08-30 00:57:59 +020017import("../../../gn/test.gni")
Florian Mayer8aba4322018-08-06 09:45:38 +010018
Primiano Tucci02c11762019-08-30 00:57:59 +020019assert(enable_perfetto_heapprofd)
20
21# The Android heap profiling daemon.
22executable("heapprofd") {
23 deps = [
24 "../../../gn:default_deps",
25 "../../../protos/perfetto/trace:zero",
26 "../../../src/base",
27 "../../../src/base:unix_socket",
28 "../../../src/profiling/memory:daemon",
29 "../../../src/profiling/memory:wire_protocol",
30 "../../../src/tracing:ipc",
31 ]
32 sources = [
33 "main.cc",
34 ]
Florian Mayerc365e362018-10-24 13:21:17 +010035}
36
Primiano Tucci02c11762019-08-30 00:57:59 +020037# This library gets loaded into (and executes in) arbitrary android processes.
38# Logging must be non-allocating. This is achieved by defining
39# PERFETTO_ANDROID_ASYNC_SAFE_LOG, which needs to be set for all perfetto code
40# being compiled for this library. When generating Android.bp, the |cflags|
41# entry on this target is sufficient (as all sources are flattened into a
42# single bp target). However this is not correctly reflected in the gn
43# structure (which is a tree of targets) as the dependencies would not pick
44# up the flag (and thus use the wrong logging macro).
45#
46# This builds only in the Android tree, when using the generated Android.bp.
47if (perfetto_build_with_android) {
48 shared_library("heapprofd_client") {
49 configs -= [ "//gn/standalone:android_liblog" ]
50 cflags = [ "-DPERFETTO_ANDROID_ASYNC_SAFE_LOG" ]
51 deps = [
52 ":malloc_hooks",
53 ]
54 }
55
56 # This will export publicly visible symbols for the malloc_hooks.
57 source_set("malloc_hooks") {
58 deps = [
59 ":client",
60 ":proc_utils",
61 ":scoped_spinlock",
62 ":wire_protocol",
63 "../../../gn:default_deps",
64 "../../base",
65 "../../base:unix_socket",
66 ]
67 cflags = [
68 "-isystem",
69 rebase_path("../../../buildtools/bionic/libc", root_build_dir),
70 ]
71 sources = [
72 "malloc_hooks.cc",
73 ]
74 }
75} # if (perfetto_build_with_android)
76
Florian Mayerb85a9382018-09-27 13:59:01 +010077source_set("wire_protocol") {
Primiano Tucci13ae72f2019-06-06 10:53:02 +010078 public_deps = [
79 "../../../gn:libunwindstack",
80 ]
Florian Mayerb64d6b12018-08-30 10:46:30 -070081 deps = [
Florian Mayer51950592019-03-06 20:05:15 +000082 ":ring_buffer",
Florian Mayerb64d6b12018-08-30 10:46:30 -070083 "../../../gn:default_deps",
84 "../../base",
Florian Mayerb6a921f2018-10-18 18:55:23 +010085 "../../base:unix_socket",
Florian Mayerb64d6b12018-08-30 10:46:30 -070086 ]
87 sources = [
Florian Mayerb85a9382018-09-27 13:59:01 +010088 "wire_protocol.cc",
89 "wire_protocol.h",
Florian Mayerb64d6b12018-08-30 10:46:30 -070090 ]
91}
92
Ryan Savitski10c19fb2019-01-22 14:44:15 +000093source_set("proc_utils") {
94 deps = [
95 "../../../gn:default_deps",
Florian Mayercc7eab02019-09-25 11:52:23 +010096 "../../../include/perfetto/profiling:normalize",
Ryan Savitski10c19fb2019-01-22 14:44:15 +000097 "../../base",
98 ]
99 sources = [
100 "proc_utils.cc",
101 "proc_utils.h",
102 ]
103}
104
Ryan Savitskia502bde2019-02-26 21:34:03 +0000105source_set("scoped_spinlock") {
Florian Mayerc50bcc92019-02-07 11:43:30 +0000106 deps = [
107 "../../../gn:default_deps",
108 "../../base",
109 ]
110 sources = [
Ryan Savitskia502bde2019-02-26 21:34:03 +0000111 "scoped_spinlock.cc",
112 "scoped_spinlock.h",
113 ]
114}
115
116source_set("ring_buffer") {
117 deps = [
118 ":scoped_spinlock",
119 "../../../gn:default_deps",
120 "../../base",
121 ]
122 sources = [
Florian Mayerc50bcc92019-02-07 11:43:30 +0000123 "shared_ring_buffer.cc",
Ryan Savitskia502bde2019-02-26 21:34:03 +0000124 "shared_ring_buffer.h",
Florian Mayerc50bcc92019-02-07 11:43:30 +0000125 ]
126}
127
128source_set("ring_buffer_unittests") {
129 testonly = true
130 deps = [
131 ":ring_buffer",
132 "../../../gn:default_deps",
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100133 "../../../gn:gtest_and_gmock",
Florian Mayerc50bcc92019-02-07 11:43:30 +0000134 "../../base",
135 ]
136 sources = [
137 "shared_ring_buffer_unittest.cc",
138 ]
139}
140
Florian Mayerb85a9382018-09-27 13:59:01 +0100141source_set("daemon") {
Florian Mayerb64d6b12018-08-30 10:46:30 -0700142 deps = [
Ryan Savitski10c19fb2019-01-22 14:44:15 +0000143 ":proc_utils",
Florian Mayer51950592019-03-06 20:05:15 +0000144 ":ring_buffer",
145 ":scoped_spinlock",
Florian Mayerb85a9382018-09-27 13:59:01 +0100146 ":wire_protocol",
Florian Mayerb64d6b12018-08-30 10:46:30 -0700147 "../../../gn:default_deps",
Primiano Tucci70431002019-08-22 17:13:10 +0200148 "../../../protos/perfetto/config/profiling:lite",
Florian Mayerb64d6b12018-08-30 10:46:30 -0700149 "../../base",
Florian Mayerb6a921f2018-10-18 18:55:23 +0100150 "../../base:unix_socket",
Florian Mayere9f46862018-11-07 20:20:37 +0000151 "../../tracing",
152 "../../tracing:ipc",
Florian Mayerb64d6b12018-08-30 10:46:30 -0700153 ]
Florian Mayer4afdd642018-11-13 11:11:04 +0000154 public_deps = [
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100155 "../../../gn:libunwindstack",
Primiano Tucci57dd66b2019-10-15 23:09:04 +0100156 "../../../protos/perfetto/config/profiling:cpp",
Florian Mayer4afdd642018-11-13 11:11:04 +0000157 "../../../protos/perfetto/trace:zero",
Florian Mayer5716fc12019-06-24 11:50:51 -0700158 "../../../protos/perfetto/trace/interned_data:zero",
Florian Mayer4afdd642018-11-13 11:11:04 +0000159 "../../../protos/perfetto/trace/profiling:zero",
160 ]
Florian Mayerb64d6b12018-08-30 10:46:30 -0700161 sources = [
Florian Mayer86feba62018-09-05 17:49:08 +0100162 "bookkeeping.cc",
163 "bookkeeping.h",
Florian Mayer7791fce2019-05-16 18:04:20 +0100164 "bookkeeping_dump.cc",
165 "bookkeeping_dump.h",
Florian Mayere9f46862018-11-07 20:20:37 +0000166 "heapprofd_producer.cc",
167 "heapprofd_producer.h",
Florian Mayer4afdd642018-11-13 11:11:04 +0000168 "interner.h",
Florian Mayer98965ba2019-09-13 15:32:36 +0100169 "java_hprof_producer.cc",
170 "java_hprof_producer.h",
Florian Mayer7142c7c2019-05-20 18:11:41 +0100171 "page_idle_checker.cc",
172 "page_idle_checker.h",
Florian Mayer78cb5622018-11-27 17:17:10 +0000173 "system_property.cc",
174 "system_property.h",
Florian Mayerb85a9382018-09-27 13:59:01 +0100175 "unwinding.cc",
176 "unwinding.h",
Ryan Savitski549753e2019-03-15 15:52:37 +0000177 "unwound_messages.h",
Florian Mayer7142c7c2019-05-20 18:11:41 +0100178 "utils.cc",
179 "utils.h",
Florian Mayer86feba62018-09-05 17:49:08 +0100180 ]
181}
182
Florian Mayer824274d2018-09-17 11:33:45 +0100183source_set("client") {
Florian Mayer824274d2018-09-17 11:33:45 +0100184 deps = [
Ryan Savitski10c19fb2019-01-22 14:44:15 +0000185 ":proc_utils",
Florian Mayer51950592019-03-06 20:05:15 +0000186 ":ring_buffer",
Ryan Savitskia502bde2019-02-26 21:34:03 +0000187 ":scoped_spinlock",
Florian Mayerb85a9382018-09-27 13:59:01 +0100188 ":wire_protocol",
Florian Mayer824274d2018-09-17 11:33:45 +0100189 "../../../gn:default_deps",
190 "../../base",
Florian Mayerb6a921f2018-10-18 18:55:23 +0100191 "../../base:unix_socket",
Florian Mayer824274d2018-09-17 11:33:45 +0100192 ]
Primiano Tucci02c11762019-08-30 00:57:59 +0200193 public_deps = [
194 "../../../gn:libunwindstack",
195 ]
Florian Mayer824274d2018-09-17 11:33:45 +0100196 sources = [
197 "client.cc",
198 "client.h",
Florian Mayerc6be21f2018-10-02 11:33:59 +0100199 "sampler.h",
Florian Mayer824274d2018-09-17 11:33:45 +0100200 ]
201}
202
Primiano Tucci02c11762019-08-30 00:57:59 +0200203perfetto_unittest_source_set("unittests") {
Florian Mayerc9b84232018-08-02 11:17:03 +0100204 testonly = true
205 deps = [
Florian Mayer824274d2018-09-17 11:33:45 +0100206 ":client",
Florian Mayerb85a9382018-09-27 13:59:01 +0100207 ":daemon",
Ryan Savitski10c19fb2019-01-22 14:44:15 +0000208 ":proc_utils",
Florian Mayerb85a9382018-09-27 13:59:01 +0100209 ":wire_protocol",
210 "../../../gn:default_deps",
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100211 "../../../gn:gtest_and_gmock",
212 "../../../gn:libunwindstack",
Florian Mayercc7eab02019-09-25 11:52:23 +0100213 "../../../include/perfetto/profiling:normalize",
Florian Mayerc9b84232018-08-02 11:17:03 +0100214 "../../base",
Florian Mayerb64d6b12018-08-30 10:46:30 -0700215 "../../base:test_support",
Florian Mayer86820d12019-04-08 19:19:46 +0100216 "../../tracing",
Florian Mayerc9b84232018-08-02 11:17:03 +0100217 ]
218 sources = [
Florian Mayer86feba62018-09-05 17:49:08 +0100219 "bookkeeping_unittest.cc",
Florian Mayer824274d2018-09-17 11:33:45 +0100220 "client_unittest.cc",
Florian Mayer096bbe32019-04-03 12:10:53 +0100221 "heapprofd_producer_unittest.cc",
Florian Mayer4afdd642018-11-13 11:11:04 +0000222 "interner_unittest.cc",
Florian Mayer7142c7c2019-05-20 18:11:41 +0100223 "page_idle_checker_unittest.cc",
Florian Mayerf3e3dd32019-01-17 10:33:56 +0000224 "proc_utils_unittest.cc",
Florian Mayerc6be21f2018-10-02 11:33:59 +0100225 "sampler_unittest.cc",
Florian Mayer78cb5622018-11-27 17:17:10 +0000226 "system_property_unittest.cc",
Florian Mayerb64d6b12018-08-30 10:46:30 -0700227 "unwinding_unittest.cc",
Florian Mayer7ad12752018-10-02 16:48:44 +0100228 "wire_protocol_unittest.cc",
Florian Mayerb64d6b12018-08-30 10:46:30 -0700229 ]
230}
231
Florian Mayer42802492018-12-13 11:00:16 +0000232source_set("end_to_end_tests") {
Florian Mayer42802492018-12-13 11:00:16 +0000233 testonly = true
234 deps = [
235 ":client",
236 ":daemon",
237 ":wire_protocol",
238 "../../../gn:default_deps",
Primiano Tucci13ae72f2019-06-06 10:53:02 +0100239 "../../../gn:gtest_and_gmock",
240 "../../../gn:libunwindstack",
Primiano Tucci0f2f3b42019-05-21 19:37:01 +0100241 "../../../include/perfetto/protozero",
Primiano Tucci70431002019-08-22 17:13:10 +0200242 "../../../protos/perfetto/config/profiling:zero",
Florian Mayer42802492018-12-13 11:00:16 +0000243 "../../../test:test_helper",
244 "../../base",
245 "../../base:test_support",
246 ]
247 sources = [
248 "heapprofd_end_to_end_test.cc",
249 ]
250 if (start_daemons_for_testing) {
251 defines = [ "PERFETTO_START_DAEMONS_FOR_TESTING" ]
252 }
253}
254
Florian Mayerc365e362018-10-24 13:21:17 +0100255perfetto_fuzzer_test("unwinding_fuzzer") {
Ryan Savitski75476042019-03-11 18:50:13 +0000256 testonly = true
Florian Mayerc365e362018-10-24 13:21:17 +0100257 sources = [
258 "unwinding_fuzzer.cc",
259 ]
260 deps = [
261 ":daemon",
Ryan Savitski75476042019-03-11 18:50:13 +0000262 ":ring_buffer",
Florian Mayerc365e362018-10-24 13:21:17 +0100263 ":wire_protocol",
264 "../../../gn:default_deps",
Ryan Savitski75476042019-03-11 18:50:13 +0000265 "../../base",
Ryan Savitski75476042019-03-11 18:50:13 +0000266 "../../tracing",
Florian Mayerc365e362018-10-24 13:21:17 +0100267 ]
268}
Florian Mayer4a1ee942019-02-07 15:51:16 +0000269
270perfetto_fuzzer_test("shared_ring_buffer_fuzzer") {
Ryan Savitski75476042019-03-11 18:50:13 +0000271 testonly = true
Florian Mayer4a1ee942019-02-07 15:51:16 +0000272 sources = [
273 "shared_ring_buffer_fuzzer.cc",
274 ]
275 deps = [
276 ":ring_buffer",
277 "../../../gn:default_deps",
Ryan Savitski75476042019-03-11 18:50:13 +0000278 "../../base",
Florian Mayer4a1ee942019-02-07 15:51:16 +0000279 ]
280}
Florian Mayer00389182019-04-08 16:43:21 +0100281
282perfetto_fuzzer_test("shared_ring_buffer_write_fuzzer") {
283 testonly = true
284 sources = [
285 "shared_ring_buffer_write_fuzzer.cc",
286 ]
287 deps = [
288 ":ring_buffer",
289 "../../../gn:default_deps",
290 "../../base",
291 ]
292}