Name Date Size #Lines LOC

..--

include/perfetto/H25-Apr-2025-19548

shared_ring_buffer_fuzzer_corpus/H25-Apr-2025-

test/data/H25-Apr-2025-133132

BUILD.gnH A D25-Apr-202510.8 KiB423393

CHANGELOG.mdH A D25-Apr-20251.4 KiB3630

README.mdH A D25-Apr-20253 KiB9164

bookkeeping.ccH A D25-Apr-20257.1 KiB195134

bookkeeping.hH A D25-Apr-202514.2 KiB373207

bookkeeping_dump.ccH A D25-Apr-20254.1 KiB11670

bookkeeping_dump.hH A D25-Apr-20253.9 KiB11778

bookkeeping_unittest.ccH A D25-Apr-202511.2 KiB312254

client.ccH A D25-Apr-202519.1 KiB568419

client.hH A D25-Apr-20255.6 KiB16087

client_api.ccH A D25-Apr-202519.7 KiB589405

client_api_benchmark.ccH A D25-Apr-20257 KiB232165

client_api_factory.hH A D25-Apr-20251.1 KiB3813

client_api_factory_android.ccH A D25-Apr-20251.7 KiB5933

client_api_factory_standalone.ccH A D25-Apr-20256 KiB206143

client_api_noop.ccH A D25-Apr-20252 KiB7043

client_api_unittest.ccH A D25-Apr-20254.3 KiB12986

client_unittest.ccH A D25-Apr-20254.4 KiB148101

heap_profile_internal.hH A D25-Apr-20251.3 KiB4921

heapprofd.ccH A D25-Apr-20254.2 KiB13186

heapprofd.hH A D25-Apr-2025890 298

heapprofd_client_api.map.txtH A D25-Apr-2025501 1917

heapprofd_end_to_end_test.ccH A D25-Apr-202561.5 KiB1,8351,469

heapprofd_preload.map.txtH A D25-Apr-2025174 1615

heapprofd_producer.ccH A D25-Apr-202545 KiB1,2831,062

heapprofd_producer.hH A D25-Apr-202511.8 KiB340215

heapprofd_producer_integrationtest.ccH A D25-Apr-20258.7 KiB273202

heapprofd_producer_unittest.ccH A D25-Apr-20257.8 KiB223185

heapprofd_standalone_client_example.ccH A D25-Apr-2025989 3614

java_hprof_producer.ccH A D25-Apr-20257.7 KiB243193

java_hprof_producer.hH A D25-Apr-20253.7 KiB11675

log_histogram.ccH A D25-Apr-20251.6 KiB6739

log_histogram.hH A D25-Apr-20251.3 KiB4822

main.ccH A D25-Apr-2025759 224

malloc_interceptor_bionic_hooks.ccH A D25-Apr-20258.8 KiB243159

malloc_interceptor_glibc_preload.ccH A D25-Apr-20255.5 KiB183122

parse_smaps_unittest.ccH A D25-Apr-20252.6 KiB9466

sampler.ccH A D25-Apr-2025883 299

sampler.hH A D25-Apr-20253.2 KiB9645

sampler_unittest.ccH A D25-Apr-20251.4 KiB5329

scoped_spinlock.ccH A D25-Apr-20252 KiB6839

scoped_spinlock.hH A D25-Apr-20252.5 KiB10165

shared_ring_buffer.ccH A D25-Apr-202510.8 KiB347249

shared_ring_buffer.hH A D25-Apr-20259.1 KiB281173

shared_ring_buffer_fuzzer.ccH A D25-Apr-20253.3 KiB10566

shared_ring_buffer_unittest.ccH A D25-Apr-20258.6 KiB280224

shared_ring_buffer_write_fuzzer.ccH A D25-Apr-20253.4 KiB11071

system_property.ccH A D25-Apr-20255.2 KiB176131

system_property.hH A D25-Apr-20252.8 KiB9042

system_property_unittest.ccH A D25-Apr-20255.3 KiB161129

unhooked_allocator.hH A D25-Apr-20252.7 KiB8949

unwinding.ccH A D25-Apr-202519.5 KiB564441

unwinding.hH A D25-Apr-20255.8 KiB170117

unwinding_fuzzer.ccH A D25-Apr-20252.9 KiB7750

unwinding_unittest.ccH A D25-Apr-20256.8 KiB195150

unwound_messages.hH A D25-Apr-20251.6 KiB6033

util.hH A D25-Apr-20251.1 KiB284

wire_protocol.ccH A D25-Apr-20255.8 KiB188152

wire_protocol.hH A D25-Apr-20255.9 KiB16997

wire_protocol_unittest.ccH A D25-Apr-20256.3 KiB179137

wrap_allocators.ccH A D25-Apr-20254.6 KiB13992

wrap_allocators.hH A D25-Apr-20252 KiB5935

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/main/+/main: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/main/+/main: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