tree: 79258751423f01a64544731aec50e0fc441d4139 [path history] [tgz]
  1. shared_ring_buffer_fuzzer_corpus/
  2. bookkeeping.cc
  3. bookkeeping.h
  4. bookkeeping_unittest.cc
  5. bounded_queue.h
  6. bounded_queue_unittest.cc
  7. BUILD.gn
  8. client.cc
  9. client.h
  10. client_unittest.cc
  11. heapprofd_end_to_end_test.cc
  12. heapprofd_integrationtest.cc
  13. heapprofd_producer.cc
  14. heapprofd_producer.h
  15. interner.h
  16. interner_unittest.cc
  17. main.cc
  18. malloc_hooks.cc
  19. proc_utils.cc
  20. proc_utils.h
  21. proc_utils_unittest.cc
  22. process_matcher.cc
  23. process_matcher.h
  24. process_matcher_unittest.cc
  25. queue_messages.h
  26. README.md
  27. record_reader.cc
  28. record_reader.h
  29. record_reader_unittest.cc
  30. sampler.cc
  31. sampler.h
  32. sampler_unittest.cc
  33. shared_ring_buffer.cc
  34. shared_ring_buffer.h
  35. shared_ring_buffer_fuzzer.cc
  36. shared_ring_buffer_unittest.cc
  37. socket_listener.cc
  38. socket_listener.h
  39. socket_listener_unittest.cc
  40. system_property.cc
  41. system_property.h
  42. system_property_unittest.cc
  43. unwinding.cc
  44. unwinding.h
  45. unwinding_fuzzer.cc
  46. unwinding_unittest.cc
  47. wire_protocol.cc
  48. wire_protocol.h
  49. wire_protocol_unittest.cc
src/profiling/memory/README.md

heapprofd - Android Heap Profiler

Googlers, for design doc see: http://go/heapprofd-design

Using convenience script

Use the tools/heap_profile script to heap profile a process. See all the arguments using tools/heap_profile -h, or use the defaults and just profile a process (e.g. system_server):

tools/heap_profile --name system_server

This will create a heap dump when Ctrl+C is pressed.

The resulting profile proto contains four views on the data

  • space: how many bytes were allocated but not freed at this callstack the moment the dump was created.
  • alloc_space: how many bytes were allocated (including ones freed at the moment of the dump) at this callstack
  • objects: how many allocations without matching frees were done at this callstack.
  • alloc_objects: how many allocations (including ones with matching frees) were done at this callstack.

Googlers: Head to http://pprof/ and upload the gzipped protos to get a visualization.

Speedscope can also be used to visualize the heap dump, but will only show the space view.

Manual

To start profiling the process ${PID}, run the following sequence of commands. Adjust the INTERVAL to trade-off runtime impact for higher accuracy of the results. If INTERVAL=1, every allocation is sampled for maximum accuracy. Otherwise, a sample is taken every INTERVAL bytes on average.

INTERVAL=128000

adb shell su root setenforce 0
adb shell su root start heapprofd

echo '
buffers {
  size_kb: 100024
}

data_sources {
  config {
    name: "android.heapprofd"
    target_buffer: 0
    heapprofd_config {
      sampling_interval_bytes: '${INTERVAL}'
      pid: '${PID}'
      continuous_dump_config {
        dump_phase_ms: 10000
        dump_interval_ms: 1000
      }
    }
  }
}

duration_ms: 20000
' | adb shell perfetto --txt -c - -o /data/misc/perfetto-traces/trace

adb pull /data/misc/perfetto-traces/trace /tmp/trace

While we work on UI support, you can convert the trace into pprof compatible heap dumps. To do so, run

prodaccess
/google/bin/users/fmayer/third_party/perfetto:trace_to_text_sig/trace_to_text \
profile /tmp/trace

This will create a directory in /tmp/ containing the heap dumps. Run

gzip /tmp/heap_profile-XXXXXX/*.pb

to get gzipped protos, which tools handling pprof profile protos expect. Head to http://pprof/ and upload the gzipped protos to get a visualization.