• Home
Name Date Size #Lines LOC

..--

include/perfetto/03-May-2024-19046

shared_ring_buffer_fuzzer_corpus/03-May-2024-

test/data/03-May-2024-133132

BUILD.gnD03-May-202410.5 KiB410381

CHANGELOG.mdD03-May-20241.4 KiB3630

README.mdD03-May-20243 KiB9164

bookkeeping.ccD03-May-20247.1 KiB194134

bookkeeping.hD03-May-202414.2 KiB372206

bookkeeping_dump.ccD03-May-20244.1 KiB11670

bookkeeping_dump.hD03-May-20243.9 KiB11978

bookkeeping_unittest.ccD03-May-202411.3 KiB318260

client.ccD03-May-202416.8 KiB508370

client.hD03-May-20245 KiB14980

client_api.ccD03-May-202418.6 KiB555385

client_api_benchmark.ccD03-May-20247 KiB232165

client_api_factory.hD03-May-20241.1 KiB3813

client_api_factory_android.ccD03-May-20241.8 KiB6034

client_api_factory_standalone.ccD03-May-20245.4 KiB182126

client_api_noop.ccD03-May-20242 KiB7043

client_api_unittest.ccD03-May-20244.3 KiB12986

client_unittest.ccD03-May-20244.4 KiB148101

heap_profile_internal.hD03-May-20241.3 KiB4821

heapprofd_client_api.map.txtD03-May-2024461 1917

heapprofd_end_to_end_test.ccD03-May-202459.9 KiB1,7721,429

heapprofd_preload.map.txtD03-May-2024174 1615

heapprofd_producer.ccD03-May-202445.1 KiB1,2781,057

heapprofd_producer.hD03-May-202411.6 KiB336210

heapprofd_producer_unittest.ccD03-May-20248.8 KiB244203

heapprofd_standalone_client_example.ccD03-May-2024989 3614

java_hprof_producer.ccD03-May-20247.5 KiB236186

java_hprof_producer.hD03-May-20243.4 KiB10466

log_histogram.ccD03-May-20241.6 KiB6739

log_histogram.hD03-May-20241.3 KiB4822

main.ccD03-May-20244.2 KiB13288

malloc_interceptor_bionic_hooks.ccD03-May-20248.8 KiB243159

malloc_interceptor_glibc_preload.ccD03-May-20243.4 KiB10970

parse_smaps_unittest.ccD03-May-20242.6 KiB9466

sampler.ccD03-May-20241.6 KiB5223

sampler.hD03-May-20243.1 KiB9543

sampler_unittest.ccD03-May-20241.6 KiB5934

scoped_spinlock.ccD03-May-20242 KiB6839

scoped_spinlock.hD03-May-20242.5 KiB10165

shared_ring_buffer.ccD03-May-202410.6 KiB343248

shared_ring_buffer.hD03-May-20249 KiB274169

shared_ring_buffer_fuzzer.ccD03-May-20243.2 KiB10364

shared_ring_buffer_unittest.ccD03-May-20248.6 KiB280224

shared_ring_buffer_write_fuzzer.ccD03-May-20243.2 KiB10768

system_property.ccD03-May-20245.2 KiB176131

system_property.hD03-May-20242.8 KiB9042

system_property_unittest.ccD03-May-20245.2 KiB159127

unhooked_allocator.hD03-May-20242.7 KiB8949

unwinding.ccD03-May-202416.2 KiB458360

unwinding.hD03-May-20245.6 KiB161101

unwinding_fuzzer.ccD03-May-20242.4 KiB7144

unwinding_unittest.ccD03-May-20246.7 KiB190145

unwound_messages.hD03-May-20241.6 KiB6033

util.hD03-May-20241.1 KiB284

wire_protocol.ccD03-May-20245.7 KiB184148

wire_protocol.hD03-May-20246.3 KiB183107

wire_protocol_unittest.ccD03-May-20246.3 KiB177137

wrap_allocators.ccD03-May-20244.6 KiB13892

wrap_allocators.hD03-May-20242 KiB5835

README.md

1# heapprofd - Android Heap Profiler
2
3heapprofd allows you to attribute memory usage to functions for Android services
4and apps.
5
6For documentation, see https://perfetto.dev/docs/data-sources/native-heap-profiler.
7
8For design doc, see https://perfetto.dev/docs/design-docs/heapprofd-design.
9
10## GN Targets
11### Factories
12android: connects to the system heapprofd. The client API will need to have
13         been built at *exactly* the same version. This means this can only
14         be used by the API shipped in the platform.
15
16standalone: executes an in-process heapprofd. Can be used on old platform
17            versions.
18
19noop: ignores all calls to the client API. This can be used as a stand-in when
20      compiling, or when executing without profiling.
21
22### Interceptors
23bionic: uses bionic [malloc dispatch](
24https://cs.android.com/android/platform/superproject/+/master:bionic/libc/private/bionic_malloc_dispatch.h)
25to intercept allocation functions on Android. This works by placing a library
26on a pre-defined path, which gets [loaded by Bionic](
27https://cs.android.com/android/platform/superproject/+/master:bionic/libc/bionic/malloc_heapprofd.cpp).
28
29glibc: generates a library exposing the allocation functions. This library
30       should be used for `LD_PRELOAD` and uses the glibc specific symbols
31       like `__libc_malloc` to use the system allocator.
32
33### Shared libraries
34
35| GN target                   | factory    | interceptor | distribution |
36|-----------------------------|------------|-------------|--------------|
37| heapprofd_client            | android    | bionic      | platform     |
38| heapprofd_client_api        | android    | none        | platform     |
39| heapprofd_glibc_preload     | standalone | glibc       | unbundled    |
40| heapprofd_standalone_client | standalone | none        | unbundled    |
41| heapprofd_api_noop          | noop       | none        | unbundled    |
42
43
44## Heap profile heapprofd
45
46For development, you might want to get a heap profile of heapprofd while it
47is profiling something else. For that reason, we allow two heapprofds to run
48on the system. The secondary heapprofd can then profile your primary one.
49
50To do this, first make sure that heapprofd is running by setting the property
51
52```
53adb shell su root setprop persist.heapprofd.enable 1
54```
55
56Take note of its PID.
57
58```
59adb shell ps -e | grep heapprofd
60```
61
62Then, move away the primary heapprofd socket to make space for the secondary
63one
64
65```
66adb shell su root mv /dev/socket/heapprofd /dev/socket/heapprofd_primary
67```
68
69Start the secondary heapprofd
70
71```
72adb shell su root start heapprofd_secondary
73```
74
75Now we can start the profile of the primary heapprofd (using the secondary).
76Leave this session running.
77
78```
79tools/heap_profile -p ${PID_FROM_ABOVE}
80```
81
82Now move back the original socket
83
84```
85adb shell su root unlink /dev/socket/heapprofd
86adb shell su root mv /dev/socket/heapprofd_primary /dev/socket/heapprofd
87```
88
89Now all subsequent profiles will be done on the primary heapprofd again, with
90the secondary observing it.
91