Record Java/Kotlin methods

Recording the Java/Kotlin methods called during your app's code execution lets you see the callstack and CPU usage at a given time, filtered to Java/Kotlin methods. This data is useful for identifying sections of code that take a long time or a lot of system resources to execute. If you want a full view of the callstack including native call frames, use the callstack sample profiling task.

When you record Java/Kotlin methods using the Android Studio profiler, you can choose the recording type:

  • Tracing: Instruments your app at runtime to record a timestamp at the beginning and end of each method call. Timestamps are collected and compared to generate method tracing data, including timing information. You should use tracing when you care about the exact methods being called. Because tracing is an intensive process, if you're using this option it's best to keep your recording around five seconds or less.

  • Sampling (legacy): Captures your app's call stack at frequent intervals during your app's Java- or Kotlin-based code execution. The profiler compares sets of captured data to derive timing and resource usage information about your app's Java- or Kotlin-based code execution. You should use sampling if you care more about timing than the exact methods being called.

Java/Kotlin methods overview

After you run the Find CPU Hotspots task the Android Studio Profiler provides the following information:

  • CPU Usage: Shows CPU usage of your app as a percentage of total available CPU capacity by time. Note that the CPU usage includes not only Java/Kotlin methods but also native code. Highlight a section of the timeline to filter to the details for that time period.
  • Interactions: Shows user interaction and app lifecycle events along a timeline.
  • Threads: Shows the threads that your app runs on. In most cases, you'll want to first focus on the topmost thread that represents your app.

To identify the methods or call stacks that take the most time, use the flame chart or top down chart.