tree: 4c019e89afda3f04ad88aa2d877e616e068d70f6 [path history] [tgz]
  1. include/
  2. shared_ring_buffer_fuzzer_corpus/
  3. test/
  4. bookkeeping.cc
  5. bookkeeping.h
  6. bookkeeping_dump.cc
  7. bookkeeping_dump.h
  8. bookkeeping_unittest.cc
  9. BUILD.gn
  10. CHANGELOG.md
  11. client.cc
  12. client.h
  13. client_api.cc
  14. client_api_benchmark.cc
  15. client_api_factory.h
  16. client_api_factory_android.cc
  17. client_api_factory_standalone.cc
  18. client_api_noop.cc
  19. client_api_unittest.cc
  20. client_unittest.cc
  21. heap_profile_internal.h
  22. heapprofd.cc
  23. heapprofd.h
  24. heapprofd_client_api.map.txt
  25. heapprofd_end_to_end_test.cc
  26. heapprofd_preload.map.txt
  27. heapprofd_producer.cc
  28. heapprofd_producer.h
  29. heapprofd_producer_unittest.cc
  30. heapprofd_standalone_client_example.cc
  31. java_hprof_producer.cc
  32. java_hprof_producer.h
  33. log_histogram.cc
  34. log_histogram.h
  35. main.cc
  36. malloc_interceptor_bionic_hooks.cc
  37. malloc_interceptor_glibc_preload.cc
  38. parse_smaps_unittest.cc
  39. README.md
  40. sampler.cc
  41. sampler.h
  42. sampler_unittest.cc
  43. scoped_spinlock.cc
  44. scoped_spinlock.h
  45. shared_ring_buffer.cc
  46. shared_ring_buffer.h
  47. shared_ring_buffer_fuzzer.cc
  48. shared_ring_buffer_unittest.cc
  49. shared_ring_buffer_write_fuzzer.cc
  50. system_property.cc
  51. system_property.h
  52. system_property_unittest.cc
  53. unhooked_allocator.h
  54. unwinding.cc
  55. unwinding.h
  56. unwinding_fuzzer.cc
  57. unwinding_unittest.cc
  58. unwound_messages.h
  59. util.h
  60. wire_protocol.cc
  61. wire_protocol.h
  62. wire_protocol_unittest.cc
  63. wrap_allocators.cc
  64. wrap_allocators.h
src/profiling/memory/README.md

heapprofd - Android Heap Profiler

heapprofd allows you to attribute memory usage to functions for Android services and apps.

For documentation, see https://perfetto.dev/docs/data-sources/native-heap-profiler.

For design doc, see https://perfetto.dev/docs/design-docs/heapprofd-design.

GN Targets

Factories

android: connects to the system heapprofd. The client API will need to have been built at exactly the same version. This means this can only be used by the API shipped in the platform.

standalone: executes an in-process heapprofd. Can be used on old platform versions.

noop: ignores all calls to the client API. This can be used as a stand-in when compiling, or when executing without profiling.

Interceptors

bionic: uses bionic malloc dispatch to intercept allocation functions on Android. This works by placing a library on a pre-defined path, which gets loaded by Bionic.

glibc: generates a library exposing the allocation functions. This library should be used for LD_PRELOAD and uses the glibc specific symbols like __libc_malloc to use the system allocator.

Shared libraries

GN targetfactoryinterceptordistribution
heapprofd_clientandroidbionicplatform
heapprofd_client_apiandroidnoneplatform
heapprofd_glibc_preloadstandaloneglibcunbundled
heapprofd_standalone_clientstandalonenoneunbundled
heapprofd_api_noopnoopnoneunbundled

Heap profile heapprofd

For development, you might want to get a heap profile of heapprofd while it is profiling something else. For that reason, we allow two heapprofds to run on the system. The secondary heapprofd can then profile your primary one.

To do this, first make sure that heapprofd is running by setting the property

adb shell su root setprop persist.heapprofd.enable 1

Take note of its PID.

adb shell ps -e | grep heapprofd

Then, move away the primary heapprofd socket to make space for the secondary one

adb shell su root mv /dev/socket/heapprofd /dev/socket/heapprofd_primary

Start the secondary heapprofd

adb shell su root start heapprofd_secondary

Now we can start the profile of the primary heapprofd (using the secondary). Leave this session running.

tools/heap_profile -p ${PID_FROM_ABOVE}

Now move back the original socket

adb shell su root unlink /dev/socket/heapprofd
adb shell su root mv /dev/socket/heapprofd_primary /dev/socket/heapprofd

Now all subsequent profiles will be done on the primary heapprofd again, with the secondary observing it.