The Profiler
Android Studio: The IDE Itself
Chapter 5 · The Profiler
Chapter 4 closed on a clean distinction: Logcat and the debugger answer "what is happening and why," while the Profiler answers "how much resource is this using." This chapter is the Profiler itself — CPU, memory, and network, each measuring a genuinely different resource on a genuinely running app.
What the Profiler Actually Measures
The Profiler observes an app while it's actually running on a device or emulator — a real-time measurement, not an analysis of source code sitting at rest (that's static analysis, covered in Chapter 7's own lint material). Nothing in the Profiler can tell you anything about an app that isn't currently executing; it exists entirely to answer questions about live behavior.
CPU Profiler
Recording a method trace shows exactly which methods are consuming CPU time, how often each one is called, and the call stack leading to them. This is the tool for a "why is this screen janky or slow to respond" question — genuinely heavy computation, not a data-loading delay or a memory issue, is what the CPU Profiler is built to reveal.
Memory Profiler
The Memory Profiler tracks heap allocation over time. A healthy pattern shows memory climbing, then dropping back down after garbage collection runs — a sawtooth shape that returns close to its own baseline each time. A pattern that keeps climbing even after repeated garbage collection, never returning to baseline, is a real warning sign of a memory leak — objects being retained somewhere they shouldn't be. Capturing a heap dump at that point shows exactly what's still allocated and, critically, what's still holding a reference to it.
Network Profiler
The Network Profiler inspects the actual HTTP requests and responses a running app makes — timing, payload size, and headers, observed directly rather than inferred. This is the right tool for a "why is this screen slow to load its data" question specifically, as distinct from a CPU-bound slowness the CPU Profiler would reveal instead.
| Profiler | Measures | Typical question it answers |
|---|---|---|
| CPU | Method time, call frequency, call stacks | Why is this screen janky/slow to respond? |
| Memory | Heap allocation over time, leak patterns | Is something being retained that shouldn't be? |
| Network | Real HTTP requests/responses, timing, size | Why is this screen slow to load its data? |
Hands-On Exercises
A Memory Profiler recording shows heap usage climbing, dropping after each garbage collection, but each drop returns to a slightly higher baseline than the previous one, trending steadily upward overall. What does this pattern suggest, and what would be the next step to investigate it?
📄 View solutionA screen takes noticeably longer than expected to display data after the user opens it. A developer immediately opens the CPU Profiler and records a method trace, finding nothing unusual. Using this chapter's own warning box, suggest what they should check next and why.
📄 View solutionExplain why the Profiler can't be used to investigate a bug in code that has been written but never actually run, and what kind of tool (from this course) would be needed instead for that situation.
📄 View solutionChapter 5 Quick Reference
- The Profiler measures a genuinely running app — a different question entirely from static code analysis (Chapter 7)
- CPU Profiler — method time and call frequency; Memory Profiler — heap allocation and leak patterns; Network Profiler — real request/response timing and size
- A memory leak shows as heap usage that never returns to baseline after garbage collection, not just occasional spikes
- Profiling typically follows Logcat/debugging (Chapter 4) — narrow down where first, then measure how much resource that area uses
- Don't assume which pane to check first based on how a slowdown feels — CPU, memory, and network slowness can look identical to a user