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

heapprofd - Android Heap Profiler

These are temporary instructions while heapprofd is under development. They are subject to frequent change and will be obsoleted once heapprofd is integrated into Perfetto.

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 every second for a default of 1 minute. Head to http://pprof/ and upload the gzipped protos to get a visualization.

Manual

Currently heapprofd only works with SELinux disabled.

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 -t -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.