# How to Read Any Profiler

> Summary, Top-Down, Bottom-Up, Flame Chart. Every profiler shows the same four views because every profiler reduces a recording to the same shape, a call tree with two numbers per node. Learn that shape once and the tabs stop being tool-specific trivia.

**Date:** 2026-11-05T00:00:00.000Z
**Tags:** Performance, Profiling, Debugging

## The intuition

Open a profiler you've never used, on a platform you've never profiled,
and the tabs already look familiar: one aggregate number, two ways to
walk a tree, a wide colored chart. That's not a coincidence.

Almost every CPU profiler reduces its recording down to the same shape
before it ever draws a UI: a call tree where each node carries two
numbers, total time (How long a function took including everything it called.) and
self time (How long a function took on its own, excluding everything it called.).
Everything else on screen is just a different view built from those two
numbers.

* **Summary**: one aggregate number for whatever's selected. Answers "is
  this slow," not "where."
* **Top-down**: the tree, root to leaf. Answers "what called this
  expensive thing."
* **Bottom-up**: the same tree, leaf to root, sorted by self time.
  Answers "what's expensive, regardless of who called it."
* **Flame chart**: the same tree again, drawn as nested bars, width
  proportional to time.

Four views, one underlying tree. Learn the shape once and the tabs stop
being tool-specific trivia. They're the same four questions asked of
every profiler you'll ever open.

The running example below is one accidentally-quadratic function,
shown throughout this post in Android Studio's Perfetto-based System
Trace. The views themselves aren't Android-specific. Chrome DevTools
and Xcode Instruments show the same shape under different tab names,
covered later in the comparison table.

```kotlin
// ❌ List.contains() is a linear scan, called once per id, so the
// whole function costs O(n²) as the list grows
fun dedupe(ids: List<String>): List<String> {
    val result = mutableListOf<String>()
    for (id in ids) {
        if (id !in result) result.add(id)
    }
    return result
}

// ✅ a Set's membership check is O(1), so the whole function drops to O(n)
fun dedupe(ids: List<String>): List<String> {
    val seen = mutableSetOf<String>()
    val result = mutableListOf<String>()
    for (id in ids) {
        if (seen.add(id)) result.add(id)
    }
    return result
}
```

`dedupe` shows up as its own named row in every screenshot ahead, same
as framework calls like `AndroidOwner:onTouch` or `Compose:recompose`.
Those are instrumented automatically, by the framework. Your own code
isn't, until you wrap the call site yourself:

```kotlin
import androidx.tracing.trace

trace("dedupe") { dedupe(ids) }
```

That's `androidx.tracing`'s `trace()`, a thin wrapper around
`android.os.Trace.beginSection("dedupe")` / `Trace.endSection()` that
handles the matching end call for you. Without it, `dedupe`'s time is
still there, just folded silently into whatever caller you can
actually see named. That's the aggregation problem this whole post is
about, one level earlier than any profiler tab.

Safe to ship as-is, too. R8 doesn't strip these calls, since it can't
prove a real platform call like `beginSection` has no side effects,
so they stay in the release APK either way.

They're cheap regardless: `beginSection`/`endSection` check an
internal enabled flag before doing any real work.

Before Android 12 (API 31), the OS goes further and disables
app-level tracing in a release build that isn't debuggable, or,
from API 29 on, explicitly marked `profileable`. Older than that, the
call is a true no-op no matter what.

From API 31 on, [tracing is always enabled for every app](https://developer.android.com/reference/kotlin/androidx/tracing/Trace#forceEnableAppTracing\(\)),
which only means it *can* emit data once something is actively
capturing a trace, not that it's recording by default.

## Picking a capture task

![Android Studio Profiler's task picker, showing Capture System Activities (System Trace), View Live Telemetry, Find CPU Hotspots (Java/Kotlin Method Recording), Find CPU Hotspots (Callstack Sample), Analyze Memory Usage (Heap Dump), Find Memory Leaks with LeakCanary, and Track Memory Consumption (Java/Kotlin Allocations, Native Allocations)](/posts/how-to-read-any-profiler/profiler-task-picker.webp)

*Android Studio's profiler task picker. Three of these feed the call tree this post is about. View Live Telemetry is a live, unrecorded monitor, and the rest are memory tasks. Only the three are covered here.*

Every view in this post comes out of a call tree, but a call tree first
has to get recorded. Android Studio alone offers three different ways
to record one:

* **System Trace** (Capture System Activities): the whole system, not
  just your own calls, including the frame pipeline (`Choreographer`,
  vsync). The task behind every screenshot in this post, and the right
  default to reach for first.
* **Find CPU Hotspots, Callstack Sample**: samples the call stack at a
  fixed interval, covering both your Kotlin/Java code and native code
  (via simpleperf). Lower overhead than instrumented tracing, at the
  cost of possibly missing a call shorter than the sampling interval.
* **Find CPU Hotspots, Java/Kotlin Method Recording**: instruments
  every method call with a real timestamp, not just the ones you've
  manually wrapped like `dedupe` above. That precision costs overhead
  heavy enough that Android recommends five seconds or less per
  recording, and it skews absolute timing, so treat its numbers as
  relative (this run vs. that run), not as a frame-budget number.

The other five tasks in the picker aren't alternate ways to get that same
call tree, they solve different problems:

* **View Live Telemetry**: not a recording, a live readout of CPU,
  threads, memory, and interactions, for deciding what's worth
  capturing.
* **Analyze Memory Usage (Heap Dump)**: a snapshot of every object
  alive in memory, with retained/shallow size per class.
* **Find Memory Leaks with LeakCanary**: LeakCanary's own leak
  analysis, run on your dev machine instead of on-device.
* **Track Memory Consumption (Java/Kotlin Allocations)**: every
  allocation and deallocation over a time window, not just one
  snapshot.
* **Track Memory Consumption (Native Allocations)**: the same
  allocation timeline, for the native C/C++ heap, sampled by default.

All five build a different data shape, a memory graph or a live gauge,
not a call tree. This post's model doesn't apply to them.

For the `dedupe()` bug in this post, System Trace is the right call
from the start. The whole point is catching a duration that climbs
*across* calls, and that only shows up once you can see time ordered
across a full recording, not a short instrumented window. Reach for
Method Recording instead when the question is narrower: "exactly how
many times did this get called," confirmed by a number instead of
eyeballing a climbing `dur` column.

## Which thread, out of forty

A System Trace records every thread scheduled during that window, not
just your app's. Expand the **Threads** panel on a real device and
you'll see dozens of rows, most of them system bookkeeping that never
touches your code.

Three matter for a UI-rendering bug:

* **The main thread**, named after your app's process (`mi.composeplay2`
  in this post's screenshots): runs `Choreographer`, input dispatch,
  measure/layout/draw, and any of your own code that never handed off
  to another thread. `AndroidOwner:onTouch` and `dedupe` both live here.
* **RenderThread**: takes the draw commands the main thread produced and
  issues them to the GPU. Split off the main thread since Android 5.0
  (Lollipop), so a slow frame can be the main thread's fault,
  RenderThread's, or both.
* **GPU completion**: how long the GPU itself took on a frame the two
  threads above already handed off. Rarely the first place to look, but
  it rules out the other two when neither shows an obvious stall.

Everything else falls into a few categories, almost none of which are
where an app bug hides:

* **`Binder:<pid>_<n>`**: the thread pool handling calls to and from
  system services. Worth opening only if cross-process communication
  itself is the suspected bottleneck.
* **`HeapTaskDaemon`, `Jit thread pool`, `Signal Catcher`, `Profile
  Saver`**: ART runtime housekeeping, garbage collection, JIT
  compilation, crash-signal handling, profile persistence. You'll see
  their *effect* on your own thread (a GC pause stealing CPU time, like
  the gap covered in the Events tab section ahead) far more often than
  you'll need to open them directly.
* **Your own background threads**, if your app started any (a coroutine
  dispatcher's worker pool, a custom `ExecutorService`): worth checking
  only once the bug you're chasing has actually moved off the main
  thread.

Clicking a thread's row, not the overview graph above it, is what
filters every other view in this post down to that one thread. Summary,
Top-down, Bottom-up, and the Events tab all read from whichever thread
is currently selected.

## Summary: one number, no location

![Android Studio System Trace, Summary tab, mi.composeplay2 thread selected over the dedupe() burst's time range, showing thread state breakdown and a Longest running events table with dedupe entries near the top](/posts/how-to-read-any-profiler/summary-tab-dedupe.webp)

*Summary for the dedupe() burst, with both the time range and the thread selected. dedupe already dominates the Self Time column, even though its ancestor dispatch calls still post the bigger Wall Duration.*

Select just a time range and Summary stays nearly empty, only Time
Range and Duration. Select the thread too, and the "Longest running
events" table fills in, the biggest individual chunks of work in that
selection.

Six of `dedupe`'s twelve calls alone fill more than half that top-10
list, each one's Self Time well above the framework dispatch calls
sitting above them. Those framework calls still post the bigger Wall
Duration, though, since their Duration includes `dedupe`'s own time
plus everything else they did.

Each row there actually carries four numbers, not one, two independent
axes stacked together:

| Column | Axis | Measures |
|---|---|---|
| Wall Duration | Total, wall-clock | Real elapsed time for this call and everything it called |
| Wall Self Time | Self, wall-clock | Real elapsed time this call's own code took, not its callees' |
| CPU Duration | Total, CPU-only | Time a CPU core was actually busy running this call and its callees |
| CPU Self Time | Self, CPU-only | Same CPU-only measure, just this call's own code |

Both axes come down to the shape of the code, not the specific app.
`AndroidOwner:onTouch` and `dedupe` are the real names from the
screenshot above, stood up here in a simplified stand-in so the
mechanism is visible in two lines instead of buried in a real call
stack:

```kotlin
fun onTouch(event: MotionEvent) = trace("AndroidOwner:onTouch") {
    recordGesture(event)   // just a call, same as the one below
    dedupe(ids)             // also just a call, from here. Nothing in
                            // onTouch's own body marks a difference
}

fun dedupe(ids: List<String>) = trace("dedupe") {   // <- this is the difference:
                                                      //    dedupe opens its OWN
                                                      //    section, recordGesture
                                                      //    never does
    for (id in ids) {
        if (id !in result) result.add(id)   // real work: Wall Duration, CPU Duration
    }
    // a GC pause can land anywhere in here: the thread is suspended, so it
    // still counts toward Wall Duration, but not toward CPU Duration
}
```

The two calls look identical from inside `onTouch`, same line shape,
right next to each other. What splits them isn't position in the
code, it's whether the callee opens its own trace section.

`recordGesture()` never does, so its time stays folded into `onTouch`'s
Self Time no matter how long it runs. `dedupe()` does, in its own
definition below, so the instant execution enters it, the profiler
starts counting that time against `dedupe`'s own section instead.

`onTouch`'s Duration still includes all of it, GC pause and all, but
its Self Time only covers `recordGesture()`, the part that never
handed off to a child section.

Duration vs. Self is the same split the Intuition section opened with,
total time vs. self time. It's exactly what Top-down and Bottom-up
read off this same call tree next.

Wall vs. CPU is the second axis. Wall-clock counts every microsecond
that passed for real. CPU time counts only the microseconds a core
was actually running this call. CPU time can never exceed wall time,
the gap between them is exactly how long the thread spent
descheduled, blocked, or paused mid-call. The GC pause in the snippet
above is one concrete case of that gap, covered again further down in
the Events tab section.

That's still not the view for this specific bug, though. The table
caps at ten rows and sorts by duration, not call order, so only the
largest handful of the twelve calls make the list, and not in the
order they ran.

You can tell something named `dedupe` is expensive. You can't tell
whether that cost is constant, climbing, or random from this table
alone, because Summary was never built to preserve order, only
magnitude.

## Top-down: what called this

![Android Studio System Trace, Top Down tab, tree expanded from mi.composeplay2 through dispatchInputEvent, deliverInputEvent, ViewPostImeInputStage, AndroidOwner:onTouch down to dedupe, showing Total/Self/Children columns in microseconds and percentages](/posts/how-to-read-any-profiler/top-down-dedupe.webp)

*Top Down for the same trace. dedupe is a single row here, Total 1,194,813µs, 61.18% of the thread's selected time, Self equal to Total since it has no children of its own.*

Top-down starts at the root of the call tree (the thread itself here)
and expands downward into whatever it called. Each row shows two
numbers for that node:

* **Total**: itself plus everything under it
* **Self**: just that node, nothing it called

Following `dispatchInputEvent` →
`deliverInputEvent` → `ViewPostImeInputStage` → `AndroidOwner:onTouch`
down to `dedupe` is the view for "I know roughly where in my code this
happened, show me the path that got there."

That single `dedupe` row is also the aggregation from the Intuition
section made concrete: its Total, 1,194,813µs, is (within rounding)
the sum of all twelve individual call durations the Events tab listed
separately. Top-down folded twelve calls sharing the same call stack
into one row the moment you stopped looking at raw events and started
reading a tree.

## Bottom-up: what's expensive, regardless of caller

![Android Studio System Trace, Bottom Up tab for the thread. dedupe's row shows Total 1,194,813µs and Self 1,194,813µs, both 61.18%, Children 0, 0.00%. The thread's own row shows Self 429,887µs, 22.01%, and AndroidOwner:onTouch shows Self 142,490µs, 7.30%, every other row's Self column is far smaller](/posts/how-to-read-any-profiler/bottom-up-dedupe.webp)

*Bottom Up for the same trace. dedupe's Self column, 1,194,813µs, is bigger than the thread's own unattributed self time (429,887µs, time on this thread outside any named section) and every other function's self time put together.*

Bottom-up flips Top-down's direction: each row is a function, and
expanding it shows its *callers*, not its callees. The Self and Total
figures on a row are summed across every place that function was
called from anywhere in the recording, not just one path. That's the
view for "I don't know which caller is the problem yet, I just want
the single most expensive function, full stop."

Scanning the Self column directly, ignoring tree position entirely,
makes this trace's bug obvious: `dedupe` alone accounts for more self
time (1,194,813µs) than the thread's own unattributed time
(429,887µs) and every other function's self time combined. If
`dedupe()` showed up this high in Bottom-up no matter which screen or
gesture triggered it, that would point at the function itself, not at
how any one caller is using it.

## Flame chart: the same tree, drawn as width

![Android Studio System Trace, Flame Chart tab. mi.composeplay2 spans the full width at the bottom, with dispatchInputEvent, deliverInputEvent, ViewPostImeInputStage, and AndroidOwner:onTouch each stacked above it at nearly the same width, and dedupe as one wide merged bar on top spanning roughly the same width as AndroidOwner:onTouch below it, with several much thinner unrelated bars to its right at the same row depth](/posts/how-to-read-any-profiler/flame-chart-dedupe.webp)

*Flame Chart for the same trace. All twelve dedupe calls collapse into the one wide bar on top, same width as AndroidOwner:onTouch underneath it, because they all share the identical call stack. The thin bars to its right are unrelated leaves elsewhere in the thread, not fragments of dedupe.*

A flame chart draws the exact same call tree as a picture: each node is
a horizontal bar, width proportional to time, stacked above its
parent, root at the bottom. Wider bars are more expensive, visually,
without reading a single number.

`dedupe` being called twelve times doesn't produce twelve bars here,
same as Top-down. Every call sharing that stack folds into the one bar
on top.

> **Two different things share this name**
>
> Android Studio's and Perfetto's Flame Chart tab *merges* every call
> with the same stack into one bar, the same aggregation Top-down and
> Bottom-up do, just drawn as width instead of a number. Chrome
> DevTools' main-thread track looks similar but isn't merged at all,
> each box is one real call in its real chronological position.
>
> Reading the wrong one as the other is an easy mistake. A Chrome-style
> track can show a bug climbing over time by eye. A merged flame chart
> tab cannot, because every call already got folded into one bar before
> it was drawn.

## The one thing none of these give you

![Android Studio System Trace, Events tab, sorted by Name so every dedupe call clusters together, Wall Duration climbing from 1.72ms to 273.88ms down the rows](/posts/how-to-read-any-profiler/events-tab-dedupe-instances.webp)

*12 dedupe() calls, sorted by name, same order they ran in. Duration climbs from 1.72ms to a 273.88ms peak, then settles in the 150-190ms range, the quadratic blowup (with GC noise layered on top), invisible in all four aggregate views above.*

Run `dedupe()` on a growing list and feed it a slightly longer input
each call. Summary gives you one total. Top-down and Bottom-up give you
one Total/Self pair per unique call path, not per call. The merged
Flame Chart tab folds every call into one bar.

All four views already threw away the one piece of information that
would show an accidentally-quadratic function red-handed: each
individual call's own duration, in the order it happened.

That data still exists. Every profiler records a timestamp and
duration per call, it's just not what any of the four aggregate views
choose to show you.

In Android Studio, the fix is sorting, not querying: the **Events**
tab (next to Bottom Up, once you select a thread) lists every named
section on that thread. Sort by Name, and every `dedupe` call clusters
together in Start Time order, Wall Duration right next to it, no SQL
involved.

Read top to bottom, a flat duration column means the cost per call is
constant. A climbing one is the quadratic blowup, visible the moment
you stop aggregating and look at each call on its own.

That climb isn't perfectly smooth, though, and the Wall-vs-CPU split
from the Summary section explains why. `dedupe()` allocates a growing
list on every call, and past a certain size that triggers real
garbage collection pauses, time the thread sits descheduled, not time
it spends computing.

Wall Duration counts that pause. CPU Duration doesn't. The largest
calls show a noticeably wider wall-vs-CPU gap than the smallest ones,
GC pressure stacking on top of the real quadratic cost. That's exactly
what a real device trace looks like once the clean idealized curve
meets an actual heap.

## The query layer isn't tool-specific either

Android Studio's Events tab is enough when you're looking at one trace,
once, by eye. It stops being enough the moment the question changes
shape:

* Compare this run's `dedupe` durations against last week's baseline.
* Filter across a trace with tens of thousands of events instead of 281.
* Read a trace that didn't come out of Android Studio at all.

That's what the SQL layer is actually for, scripting the same question
Events answers manually.

Two things first: the trace file itself, exported from Android
Studio's **Past Recordings** tab (**Export recording**, not every
capture type supports it), and `trace_processor` installed locally:

```bash
curl -LO https://get.perfetto.dev/trace_processor
chmod +x ./trace_processor
```

Every trace shares the same `slice` table, so `query.sql` just asks
it directly:

```sql
SELECT ts, dur FROM slice WHERE name = 'dedupe' ORDER BY ts;
```

```bash
# reads an Android-captured trace
trace_processor query -f query.sql android-trace.perfetto-trace

# reads a trace Chrome DevTools exported as JSON, same query, same tables
trace_processor query -f query.sql chrome-trace.json
```

The file is optional. For a one-off query, skip it and pass the SQL
straight in as a string:

```bash
trace_processor query android-trace.perfetto-trace \
  "SELECT ts, dur FROM slice WHERE name = 'dedupe' ORDER BY ts"
```

Perfetto's `trace_processor` parses both an Android system trace and
Chrome DevTools' exported JSON trace (the Trace Event Format Chrome has
used since `chrome://tracing`) into the same `slice`/`track`/`thread`
SQL tables. The query above runs unmodified against either file. The
SQL layer was never Android-specific, it just happens to be the tool
Android ships.

Xcode Instruments doesn't have an equivalent. `xctrace export` gets you
structured data out of a `.trace` file, but by XPath against the
trace's table of contents, into XML, not SQL:

```bash
xctrace export --input recording.trace \
  --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-profile"]' \
  --output time-profile.xml
```

You can still get a per-call, time-ordered list this way. It's just a
script you write yourself against XML instead of a query against a
database that already has the right columns.

## Which view, in which tool

| What it shows | Android Studio / Perfetto | Chrome DevTools | Xcode Instruments |
|---|---|---|---|
| One aggregate number for a selection | Summary | Summary | Top Functions |
| Call tree, root to leaf | Top Down | Call Tree | Call Tree |
| Call tree, leaf to root, sorted by self time | Bottom Up | Bottom-Up | Call Tree, Invert Call Tree checked |
| Merged call stacks, width = time | Flame Chart (merged) | main thread track (not merged, chronological) | Flame Graph |
| Per-instance, time-ordered, scriptable | Events tab (manual), `trace_processor` (SQL, scriptable) | `trace_processor` (SQL, via JSON import) | `xctrace export` (XPath → XML, no SQL) |

## When to reach for a profiler

A profiler answers "why is this slow," not "is this slow." That
question usually arrives first, from somewhere else: a CI gate flagging
a regression, a teammate saying a gesture feels janky, a dropped-frame
metric climbing in production. Opening a profiler before that signal
exists means reading call trees for a problem you haven't confirmed is
real yet.

It's also slow on purpose, not by accident. Capturing a trace, picking
a capture task, reading four aggregated views, then writing a query for
the one thing they don't show, is minutes of focused attention per
trace.

That cost makes sense once, for diagnosis. It doesn't scale to
running on every commit.

That's the actual line: diagnosis (why) stays manual, detection (did
this regress) doesn't have to. Wrap the suspect call in the same named
trace section a profiler already reads, then record its duration on
every CI run instead of waiting for someone to notice:

```kotlin
// records dedupe()'s own duration on every CI run, via the same named
// trace section every profiler screenshot in this post reads
@Test
fun dedupeDuration() = benchmarkRule.measureRepeated(
    packageName = "com.example.app",
    metrics = listOf(TraceSectionMetric("dedupe", TraceSectionMetric.Mode.Sum)),
    iterations = 10,
    setupBlock = { startActivityAndWait() },
) {
    triggerTheFlowThatCallsDedupe()
}
```

This produces a number, not a verdict. Each run's result still needs
comparing against a stored baseline to decide pass or fail. The
profiler only gets opened once that comparison fails, to answer why,
which is the question the rest of this post is actually about.

## Variations and tradeoffs

* **Aggregation is the default, not a bug.** Every one of the four main
  views exists specifically to collapse repeated calls into one
  number, because that's what makes "what's slow" answerable in under
  a second for the 95% of cases where the cost per call really is
  constant. The quadratic-loop bug above is exactly the other 5%, the
  case where aggregating away the per-call order hides the actual
  shape of the problem.
* **This mental model is for CPU/wall-time profiling specifically.**
  A call tree with self/total time is the shared shape behind
  sampling and tracing CPU profilers. A heap profiler's retained-size
  graph or a GPU frame profiler's pipeline-stage breakdown is a
  genuinely different data shape. The same four tab names sometimes
  get reused by convention, but they're not built from the same
  underlying tree, so this post's mapping doesn't transfer to them.
* **Not having a SQL layer is a real cost, not trivia.** If you need
  the per-instance, time-ordered answer on iOS and don't want to parse
  XML by hand, the honest options are scripting against
  `xctrace export`'s output or converting the trace into a format
  something else can query. There's no first-party shortcut the way
  `trace_processor` is one for Android and Chrome.


---

Canonical page: https://recomposed.blog/how-to-read-any-profiler