1# 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 15import("../../../gn/fuzzer.gni") 16import("../../../gn/perfetto.gni") 17import("../../../gn/test.gni") 18 19assert(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/producer", 31 ] 32 sources = [ "main.cc" ] 33} 34 35# This library gets loaded into (and executes in) arbitrary android processes. 36# Logging must be non-allocating. This is achieved by defining 37# PERFETTO_ANDROID_ASYNC_SAFE_LOG, which needs to be set for all perfetto code 38# being compiled for this library. When generating Android.bp, the |cflags| 39# entry on this target is sufficient (as all sources are flattened into a 40# single bp target). However this is not correctly reflected in the gn 41# structure (which is a tree of targets) as the dependencies would not pick 42# up the flag (and thus use the wrong logging macro). 43# 44# This builds only in the Android tree, when using the generated Android.bp. 45if (perfetto_build_with_android) { 46 shared_library("heapprofd_client") { 47 configs -= [ "//gn/standalone:android_liblog" ] 48 cflags = [ "-DPERFETTO_ANDROID_ASYNC_SAFE_LOG" ] 49 deps = [ ":malloc_hooks" ] 50 } 51 52 # This will export publicly visible symbols for the malloc_hooks. 53 source_set("malloc_hooks") { 54 deps = [ 55 ":client", 56 ":scoped_spinlock", 57 ":wire_protocol", 58 "../../../gn:default_deps", 59 "../../base", 60 "../../base:unix_socket", 61 "../common:proc_utils", 62 ] 63 cflags = [ 64 "-isystem", 65 rebase_path("../../../buildtools/bionic/libc", root_build_dir), 66 ] 67 sources = [ "malloc_hooks.cc" ] 68 } 69} # if (perfetto_build_with_android) 70 71source_set("wire_protocol") { 72 public_deps = [ "../../../gn:libunwindstack" ] 73 deps = [ 74 ":ring_buffer", 75 "../../../gn:default_deps", 76 "../../base", 77 "../../base:unix_socket", 78 ] 79 sources = [ 80 "wire_protocol.cc", 81 "wire_protocol.h", 82 ] 83} 84 85source_set("scoped_spinlock") { 86 deps = [ 87 "../../../gn:default_deps", 88 "../../base", 89 ] 90 sources = [ 91 "scoped_spinlock.cc", 92 "scoped_spinlock.h", 93 ] 94} 95 96source_set("ring_buffer") { 97 deps = [ 98 ":scoped_spinlock", 99 "../../../gn:default_deps", 100 "../../base", 101 ] 102 sources = [ 103 "shared_ring_buffer.cc", 104 "shared_ring_buffer.h", 105 ] 106} 107 108source_set("ring_buffer_unittests") { 109 testonly = true 110 deps = [ 111 ":ring_buffer", 112 "../../../gn:default_deps", 113 "../../../gn:gtest_and_gmock", 114 "../../base", 115 ] 116 sources = [ "shared_ring_buffer_unittest.cc" ] 117} 118 119source_set("daemon") { 120 deps = [ 121 ":ring_buffer", 122 ":scoped_spinlock", 123 ":wire_protocol", 124 "../../../gn:default_deps", 125 "../../../protos/perfetto/config/profiling:cpp", 126 "../../base", 127 "../../base:unix_socket", 128 "../../tracing/core", 129 "../../tracing/ipc/producer", 130 "../common:callstack_trie", 131 "../common:interner", 132 "../common:interning_output", 133 "../common:proc_utils", 134 "../common:unwind_support", 135 ] 136 public_deps = [ 137 "../../../gn:libunwindstack", 138 "../../../protos/perfetto/config/profiling:cpp", 139 "../../../protos/perfetto/trace:zero", 140 "../../../protos/perfetto/trace/interned_data:zero", 141 "../../../protos/perfetto/trace/profiling:zero", 142 ] 143 sources = [ 144 "bookkeeping.cc", 145 "bookkeeping.h", 146 "bookkeeping_dump.cc", 147 "bookkeeping_dump.h", 148 "heapprofd_producer.cc", 149 "heapprofd_producer.h", 150 "java_hprof_producer.cc", 151 "java_hprof_producer.h", 152 "page_idle_checker.cc", 153 "page_idle_checker.h", 154 "system_property.cc", 155 "system_property.h", 156 "unwinding.cc", 157 "unwinding.h", 158 "unwound_messages.h", 159 ] 160} 161 162source_set("client") { 163 deps = [ 164 ":ring_buffer", 165 ":scoped_spinlock", 166 ":wire_protocol", 167 "../../../gn:default_deps", 168 "../../base", 169 "../../base:unix_socket", 170 "../common:proc_utils", 171 ] 172 public_deps = [ "../../../gn:libunwindstack" ] 173 sources = [ 174 "client.cc", 175 "client.h", 176 "sampler.h", 177 ] 178} 179 180perfetto_unittest_source_set("unittests") { 181 testonly = true 182 deps = [ 183 ":client", 184 ":daemon", 185 ":wire_protocol", 186 "../../../gn:default_deps", 187 "../../../gn:gtest_and_gmock", 188 "../../../gn:libunwindstack", 189 "../../base", 190 "../../base:test_support", 191 "../../tracing/core", 192 "../common:proc_utils", 193 "../common:unwind_support", 194 ] 195 sources = [ 196 "bookkeeping_unittest.cc", 197 "client_unittest.cc", 198 "heapprofd_producer_unittest.cc", 199 "page_idle_checker_unittest.cc", 200 "parse_smaps_unittest.cc", 201 "sampler_unittest.cc", 202 "system_property_unittest.cc", 203 "unwinding_unittest.cc", 204 "wire_protocol_unittest.cc", 205 ] 206} 207 208source_set("end_to_end_tests") { 209 testonly = true 210 deps = [ 211 ":client", 212 ":daemon", 213 ":wire_protocol", 214 "../../../gn:default_deps", 215 "../../../gn:gtest_and_gmock", 216 "../../../gn:libunwindstack", 217 "../../../protos/perfetto/config/profiling:cpp", 218 "../../../protos/perfetto/trace/profiling:cpp", 219 "../../../test:test_helper", 220 "../../base", 221 "../../base:test_support", 222 ] 223 sources = [ "heapprofd_end_to_end_test.cc" ] 224 if (start_daemons_for_testing) { 225 defines = [ "PERFETTO_START_DAEMONS_FOR_TESTING" ] 226 } 227} 228 229perfetto_fuzzer_test("unwinding_fuzzer") { 230 testonly = true 231 sources = [ "unwinding_fuzzer.cc" ] 232 deps = [ 233 ":daemon", 234 ":ring_buffer", 235 ":wire_protocol", 236 "../../../gn:default_deps", 237 "../../base", 238 "../../tracing/core", 239 "../common:unwind_support", 240 ] 241} 242 243perfetto_fuzzer_test("shared_ring_buffer_fuzzer") { 244 testonly = true 245 sources = [ "shared_ring_buffer_fuzzer.cc" ] 246 deps = [ 247 ":ring_buffer", 248 "../../../gn:default_deps", 249 "../../base", 250 ] 251} 252 253perfetto_fuzzer_test("shared_ring_buffer_write_fuzzer") { 254 testonly = true 255 sources = [ "shared_ring_buffer_write_fuzzer.cc" ] 256 deps = [ 257 ":ring_buffer", 258 "../../../gn:default_deps", 259 "../../base", 260 ] 261} 262