• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Quickstart: Heap profiling
2
3## Prerequisites
4
5* A host running macOS or Linux.
6* A device running Android 10+.
7* A _Profileable_ or _Debuggable_ app. If you are running on a _"user"_ build of
8  Android (as opposed to _"userdebug"_ or _"eng"_), your app needs to be marked
9  as profileable or debuggable in its manifest.
10  See the [heapprofd documentation][hdocs] for more details.
11
12[hdocs]: /docs/data-sources/native-heap-profiler.md#heapprofd-targets
13
14## Capture a heap profile
15
16Download the `tools/heap_profile` (if you don't have a perfetto checkout) and
17run it as follows:
18
19```bash
20curl -LO https://raw.githubusercontent.com/google/perfetto/master/tools/heap_profile
21chmod +x heap_profile
22
23./heap_profile -n system_server
24
25Profiling active. Press Ctrl+C to terminate.
26You may disconnect your device.
27
28Wrote profiles to /tmp/profile-1283e247-2170-4f92-8181-683763e17445 (symlink /tmp/heap_profile-latest)
29These can be viewed using pprof. Googlers: head to pprof/ and upload them.
30```
31
32## View profile
33
34Upload the `raw-trace` file from the output directory to the [Perfetto UI](
35https://ui.perfetto.dev) and click on diamond marker in the UI track labeled
36_"Heap profile"_.
37
38![Profile Diamond](/docs/images/profile-diamond.png)
39![Native Flamegraph](/docs/images/syssrv-apk-assets-two.png)
40
41## Next steps
42
43Learn more about memory debugging in the [Memory Usage on Android Guide](
44/docs/case-studies/memory.md) and more about the [heapprofd data-source](
45/docs/data-sources/native-heap-profiler.md)
46