tree: 12120cdf9437331c3af0dbb6188611879fc1d728 [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_integrationtest.cc
  30. heapprofd_producer_unittest.cc
  31. heapprofd_standalone_client_example.cc
  32. java_hprof_producer.cc
  33. java_hprof_producer.h
  34. log_histogram.cc
  35. log_histogram.h
  36. main.cc
  37. malloc_interceptor_bionic_hooks.cc
  38. malloc_interceptor_glibc_preload.cc
  39. parse_smaps_unittest.cc
  40. README.md
  41. sampler.cc
  42. sampler.h
  43. sampler_unittest.cc
  44. scoped_spinlock.cc
  45. scoped_spinlock.h
  46. shared_ring_buffer.cc
  47. shared_ring_buffer.h
  48. shared_ring_buffer_fuzzer.cc
  49. shared_ring_buffer_unittest.cc
  50. shared_ring_buffer_write_fuzzer.cc
  51. system_property.cc
  52. system_property.h
  53. system_property_unittest.cc
  54. unhooked_allocator.h
  55. unwinding.cc
  56. unwinding.h
  57. unwinding_fuzzer.cc
  58. unwinding_unittest.cc
  59. unwound_messages.h
  60. util.h
  61. wire_protocol.cc
  62. wire_protocol.h
  63. wire_protocol_unittest.cc
  64. wrap_allocators.cc
  65. wrap_allocators.h
third_party/perfetto/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.