Skip to content

Collecting traces

echolot collect -c echolot.yml -n 5
echolot analyze .echolot/traces -c echolot.yml

The first command captures N repeats of a scenario into .echolot/traces/ beside the config, as <scenario>_iter000.perfetto-trace and on; the second merges them into one report. The directory keeps the traces of every scenario recorded into it, and analyze reads one scenario's set out of it: the one --scenario names, else the config's one among those there, in the order of their iteration numbers. The sets put aside in directories under it are not read unless one is named, and what was read and what was left out is said on stderr and under the report's header (A set's directory). A glob reads exactly what it names, as it always did: .echolot/traces/coldStart_iter*.perfetto-trace is the same set, where coldStart stands for the config's scenario.name, and .echolot/traces/*.perfetto-trace would merge two scenarios into one report, every median in it mixing them. That directory is the one echolot counts and hunt sets aside, and compare compares the reports analyze builds from it, so the default is the place to keep them; -o exists for the rare trace that belongs elsewhere.

Repeating is not belt-and-braces. A single run cannot tell a regression from a random spike — on a live cold start the spread between iterations reaches tens of percent. Both threshold calibration and report merging stand on the distribution across repeats; without them, both are guessing.

A second collect into the same directory does not overwrite the first: the existing <scenario>_* set moves into a sibling directory stamped with when it was recorded (.echolot/traces/cold_start-20260815-153720/), and the log says so. The set from before a change is the baseline every after-the-fix comparison stands on, and it is the first thing lost otherwise — a macrobenchmark's output directory is cleaned by gradle on the next run, a rename inside it goes with the cleaning. If you record around the tool, copy the traces out before re-recording; echolot reflect flags a re-record that did not.

The set moves when the first new trace is about to take its place, and not before. A collect that stops earlier — no device, a typo in the mode, a gradle build that fails, a benchmark that writes nothing — leaves it where it was, so the traces line of echolot and the next analyze still see it. In launch and command modes the first trace of the set is read before it takes its name (While it runs, and when it fails): it waits beside the set in .<scenario>-first/, and a round that stops on it, or is interrupted before it is let in, leaves the set where it was too. Everything of this scenario moves, a probe capture saved beside the set included; another scenario's traces stay, and so do those of a scenario whose name merely begins with this one's: re-recording startup leaves startup_warm_* alone.

Beside each trace it records, collect keeps a short account of how it recorded it, <trace>.recording.json: the scenario, the runner, the reset policy, whether the force-stop before the repeat found the app still running, and how the phone was powered (see Power). The trace cannot say any of that itself, and analyze carries it into the report's recording block, where compare sets it against the other side's (see How the two were recorded). It moves with its trace when a set is set aside; copy it along if you move traces by hand, or that set's runner reads as unknown.

The account also keeps two things collect reads of the device once a round, before the first repeat, in launch and command modes:

  • animation_scales, the window, transition and animator scales of Developer options. An animation lasts its length times its scale: on an SM-A515F a list scroll recorded with all three at 5 against one at 1 gave 5 to 17 rows that held in compare, and nothing said the device had animated five times slower. UI-test setups set them to 0 on purpose, so collect records whatever they are rather than refusing.
  • always_finish_activities, "Don't keep activities": the system destroys an activity as soon as it leaves the screen, so a return to a living process creates it again. On the SM-A515F HOME and am start of the launcher activity came back WARM in 431–469 ms with it on and HOT in 144–179 ms with it off. It changes little in a cold start and everything in a scenario that returns to the app (reset_policy: none, or a command that goes home and back).

The option is read from ActivityManager, not from the setting it keeps. adb shell settings put global always_finish_activities 0 changes the setting and not the running system, which reads it at boot: the option stays on, and the account says so. Switch it in Developer options, which change both, or restart the phone after settings put. The scales take effect at once either way.

The report's header names any scale that is not 1, and says when the option was on (see What the device was set to do); compare says when either differs between the two sides. In gradle mode neither is read: the macrobenchmark drives the device, and a run with AGP's animationsDisabled turns the scales to 0 for its own length.

The account also keeps how the repeat started, under launch: which repeat of the set it was and which recording of that repeat (attempt, 2 and on for one recorded again), am start -W's state (COLD, WARM, HOT; null in command mode) and total_time_ms, cold (true for a stopped app that started cold, false for one that did not, null where there is nothing to judge by), activity and asked, the activity the launch ended on as am start -W named it and the one it started (null in command mode; see A launch that ended elsewhere), notes, the lines collect printed under the repeat, and no_launch: true on a repeat that started nothing with reset_policy: none. Before, they were in its output alone, and an agent that had cut that output with tail recorded a whole round again to read them back. echolot reads them off the set with no device and prints a starts line: startup: 5 COLD · set aside, not cold: startup_iter001-warm.perfetto-trace (WARM). A round that kept no repeat at all says startup: no repeat kept · set aside, not cold: ….

Three modes

runner:
  mode: launch              # launch | command | gradle
  iterations: 5
  duration_ms: 12000
  reset_policy: force-stop  # force-stop (cold) | none (nothing between repeats)

duration_ms is sized for a start, and a freeze does not fit in it. Hunting one needs the block plus the five seconds the system waits before declaring an ANR — forty-five is a working number, and twelve finds neither. See ANRs.

The numbers are digits alone, in the unit the key's name ends with: duration_ms: 12000. A value such as 12s stops collect with a sentence before the device is touched. A reset_policy other than force-stop or none gets a warning that says force-stop will run, and then it does.

Launch and command modes build nothing: they record the app that is installed on the phone. After a change to its code — echolot mark --apply, a marker added by hand, mark --remove — build and install the variant the config measures before the next collect, or the round measures the old build. mark --apply ends with the gradle task that does it. When the code has temporary markers, collect reads the build on the phone for them and stops before a round that could not hold them (The build on the phone). analyze says it afterwards both ways: when none of the code's temporary markers is in the traces, and when the traces hold markers the code no longer has. Gradle mode builds and installs the app itself, as part of the macrobenchmark's task.

launch — we drive it

HOME, force-stop, a wait for the app's process to be gone, the cooldown when runner.cooldown asks for one, a last look for the process, start recording, am start -W, wait, pull. A cold start. With reset_policy: none nothing is reset between repeats, and that is not a warm start: the app is still in front from the repeat before, so am start -W has nothing to start and only the first repeat can measure one. collect says so before it records more than one, marks each repeat that started nothing with [!], and ends with a [!] line that names those traces: they hold no launch. Their accounts say so (no_launch), and echolot's next line leaves them out of the analyze it offers, while a repeat that recorded a launch is there to read: startup: 2 UNKNOWN (0), 1 COLD · started nothing, left out of `next`: ….

HOME comes first because the app is still on screen from the repeat before. Stopped there, an app whose activity is bound to a service in a second process of its own was started again by the system at once, for that activity: am_proc_start … top-activity in adb logcat -b events, 65–95 ms after the kill on an A51. am start -W then said WARM, and the trace held neither the process start nor bindApplication. From the background, the same app stayed dead after the force-stop, 8 times of 8. The wait after it lasts until pidof finds no process of the app, five seconds at most, and half a second more: the old process was gone at the first look, and the new one was there a moment later.

The device cools after the stop, not before it. Cooled with the app in front, a job the app had scheduled during the wait was due by the time the force-stop came, and the system started the process for it 95–112 ms after the kill (am_proc_start … service in the events log). On an A51, 47 of 59 repeats that had waited for the device began warm, against 0 of 51 that had not; stopped first, 70 starts of the same app began cold 70 times, 31 of them after a wait. Right before the recording collect looks for the process once more, and a process something started while the device cooled is stopped again, with a line under the repeat's own: was running again after the 95s cooling wait (pid 4242), and was stopped again before the recording. A set with a cooldown says at its start that the app is stopped before each wait.

A process the last look finds is stopped once more if that stop leaves it there (was stopped again, twice, before the recording): a recording begun with the process up is known not to be cold before it starts.

A repeat that was stopped and started warm all the same gets a line under its own: not a cold start, with the pid when the process was running again before the recording began. Its trace holds neither the process start nor bindApplication, and in a set of cold starts it is another measurement: one such repeat in five made the report's windows diverge 3.7x and put the warm run's pid in its header. So it is set aside, out of the set, as <scenario>_iterNNN-warm.perfetto-trace (-hot, -relaunch, or -not-cold when am start gave no state), with its account beside it, and the repeat is recorded again: set aside, out of the set: repeat 2 is recorded again (1 of the 5 re-recordings the set is given). That name is no repeat's, so the paths collect prints, the next line and echolot's count of the set leave it out, and it moves with its set when the set is set aside.

A set is given as many recordings more as it has repeats, and no more: a device that starts the app again after every stop would otherwise be recorded forever. Past them, a repeat that is not cold leaves the set one cold start short, and the next recording is the next repeat's: [2/5] after the line that says they are spent, with repeat: 2, attempt: 1 in its account. The line at the end names every recording set aside and says whether the set is whole: Each was recorded again, and the set holds 5 cold starts, or The set holds 3 cold starts of the 5 asked for. A set with no cold start at all is an error, exit 2, that names the recordings set aside. On an A51, 51 of 124 starts of one day came out warm before the stop moved ahead of the cooldown, and a block of five kept one to three cold starts.

analyze reads the same account. Given a trace collect set aside among cold ones, a glob that took the whole directory say, it leaves it out of the medians and says which: Left out: startup_iter001-warm.perfetto-trace (WARM), in its output, in report.md under the runs, and in report.json as not_cold. A set made only of such traces is read as given.

A launch that ended elsewhere

A launch ends on the activity the app drew when it was done, and that is not always the one am start started. Wikipedia opens the page read last by itself when that was less than a day ago: 2 of its 13 cold starts on an SM-F711B ended on PageActivity, in 497 and 572 ms against 273–317 for the feed, with WebView's start inside, and both were recorded as an ordinary COLD. A splash, a login gate or an onboarding redirect does the same. am start -W names the activity in its Activity: line, in the short form (com.example.app/.MainActivity); collect keeps it beside the trace with the one it started, and a repeat that ended elsewhere gets a line under its own:

  [1/10] cold_start_iter000.perfetto-trace  13.9 MB, am start -W: 572 ms (COLD)
      the launch ended on org.wikipedia.page.PageActivity, not on the org.wikipedia.main.MainActivity it started: the app went on to another activity by itself

The line is said once while the repeats after it end on the same activity: a splash that hands over to the main activity ends every launch elsewhere, and that is the app's start. At the end of the set a [!] line counts where the launches ended when they did not all end on one activity (PageActivity in repeat 1, MainActivity in the other 9), or says that every launch ended on another activity than the one started.

A launcher that is an <activity-alias> is no other activity: am start -W names the activity behind the alias (android:targetActivity), and the first time a launch ends there collect asks the device what the alias stands for (cmd package resolve-activity -n <the alias>), or reads the project's manifests where the device does not say. A launch that ended on the alias's activity says nothing, and the record keeps it as target.

am start -W returns at the first frame, so a splash that draws a frame and then hands over to the main activity by itself is not one of these: the launch ended where it started. The trace holds the hand-over as a second launch, and the first repeat's look at its trace says it, under that repeat's line:

      [!] repeat 1 handed its start over: `SplashActivity` drew the launch's first frame at 181 ms, and 263 ms later the app went on by itself to `MainActivity`. `window: launch` runs through that launch, 690 ms in all, and analyze says so

See A start the app hands over.

Such a repeat is not recorded again, as a warm one is. Which repeat is the odd one out is the set's to say and not the activity started's: Wikipedia's was the first of its set, and a splash's set ends elsewhere every time. analyze reads the activity most repeats ended on, the one started where as many ended on each, and leaves the others out by name: Left out: cold_start_iter000.perfetto-trace (repeat 1, ended on org.wikipedia.page.PageActivity); the other 9 ended on org.wikipedia.main.MainActivity, in its output, in report.md and in report.json as ended_elsewhere. For a set collect recorded before it kept this, or one a macrobenchmark recorded, it reads the trace's last performCreate: inside the window instead; a trace from before Android 12 names no activity there, and is read. With as many on each and none of them the one started, every repeat is read and the report says the medians mix two journeys. To measure the start alone, record it where nothing sends the app elsewhere: for Wikipedia, before a scenario that reads a page, not right after it.

A permission dialog over the launch

An app that asks for a permission before its first frame has the system's dialog started over it, and the platform's launch ends on the dialog. A debug build that asks for POST_NOTIFICATIONS at its start, on an SM-A515F with Android 13 and the permission never granted, does that in every repeat: am start -W names the permission controller's GrantPermissionsActivity, and the launch the trace records is com.google.android.permissioncontroller's, so scenario.window: launch finds none of the app's. collect says so under the first repeat the dialog took, reads the runtime permissions the app holds ungranted (dumpsys package), and names the command that grants the likely one:

  [1/5] coldStart_iter000.perfetto-trace  14.2 MB, am start -W: 812 ms (COLD)
      [!] a permission dialog took the launch: it ended on com.google.android.permissioncontroller's GrantPermissionsActivity, which came up over com.example.app before its first frame. Every launch ends there until the permission is granted, and `window: launch` finds no launch of the app in such a trace: grant it once before recording, `adb shell pm grant com.example.app android.permission.POST_NOTIFICATIONS`, or tap Allow on the phone

Under scenario.window: launch the round stops there, before the rest are recorded: no repeat after it would hold a launch of the app, and the stop says what analyze would. A window cut by anchors is measured with the dialog up, and its round goes on: the end of the set says it again. The permissions are kept beside each trace (launch.ungranted in its account), so that analyze names the same command. Granted once, the dialog does not come again, and the next round's launches are the app's: after pm grant the same build gave its launch window.

The scenario that needs nothing more is scenario.window: launch: its window is the launch this mode starts, and the trace says where it ends, so nobody picks an end anchor before the first recording. echolot scan drafts the two together, this runner and that window, for an app with a launcher Activity and no macrobenchmark, and echolot ui writes that draft as echolot.yml at a press. See A window that is the launch. For a project whose macrobenchmark measures the launch, scan drafts the same window with the gradle runner.

The activity this mode starts is runner.activity: a component, com.example.app.demo/com.example.app.MainActivity, or a class's full name, com.example.app.MainActivity, which starts in project.package — so the line holds for every variant, whatever suffix its package has. A name that starts with a dot is refused: the manifest reads it under the app's namespace, and a package with a suffix is another name. Left out, the device is asked for the package's launcher. A debug build with a leak detector has two, and the device then answers with its chooser: collect stops, lists the launchers the device has, and names the one the project's own manifest declares as the line to write. scan writes the key in the launch draft, the enabled launcher of the app's manifest by its full name — an <activity-alias> by the alias, the component the launcher opens.

am start -W prints TotalTime, which the runner reports — an independent check that the window in the report is plausible. TotalTime: 0 is the system saying it timed no start, usually because the activity was already in front and nothing was launched; collect counts those launches and leaves them out of the spread.

am start of an app or an activity that is not on the device prints Error: Activity class {…} does not exist. and exits 0. Taken as a launch, that recorded five traces of the device and no app, and an agent spent its whole loop on them. So before the set collect asks the device whether the package is installed (pm path), and an app that is not there stops it with a sentence, before anything is recorded. After each launch, an Error: line from am start stops the set at that repeat: a runner.activity with a typo in it, or a build installed under another activity. The repeat's own trace is not kept, and the ones before it are.

When the code has temporary markers, the build that is there is read for them next, and one that lacks any stops the set before it starts: see The build on the phone.

command — something else drives it

We record the trace around a command of your choosing. Anything that can move the app goes here: adb input, uiautomator, maestro, your own script.

runner:
  mode: command
  reset_policy: none
  command: >
    adb shell am start -n com.example.app/.MainActivity &&
    adb shell input swipe 500 1500 500 600 400

The command comes from the project's own config — the same level of trust as the gradle task next to it. If it outlasts the recording window, the runner says the trace covers only its beginning.

It runs with ANDROID_SERIAL set to the device being recorded, so a bare adb shell … inside it reaches that device — with a second one plugged in it would otherwise stop at "more than one device", whatever --device said.

The scenario may install the app itself, so the build on the phone is read for the code's temporary markers once more after the first repeat when it lacked them before the set: see The build on the phone.

gradle — the macrobenchmark writes its own

runner:
  mode: gradle
  gradle_task: ":benchmark:connectedBenchmarkBenchmarkAndroidTest"
  gradle_args: ["-Pandroid.testInstrumentationRunnerArguments.class=…"]
  project_root: ../my-app        # where ./gradlew lives
  gradle: ./gradlew              # the wrapper, relative to project_root (default)
  timeout_s: 3600                # the whole task, build included (default)

Macrobenchmark drops traces per iteration into an artifact directory whose path depends on the build variant and the device model — awkward to find by hand. The runner takes everything that appeared after the run started.

The benchmark runs as many iterations as its own measureRepeated asks for, so -n and runner.iterations do not reach it, and collect says so when either is given. timeout_s bounds the whole gradle run — the build, the install and every iteration — and a run that outlasts it is stopped with its whole process tree. gradle is the command in front of the task, run from project_root. Where the Gradle build is in a folder of its own, as in a repository with android/settings.gradle beside a C++ core, echolot scan run from the root writes project_root: "android" into the draft, and every other path in it from the root.

A task that fails harvests nothing, whatever the benchmark wrote before it failed: the traces of a half-finished run stay in the module's output directory, and the previous set stays in .echolot/traces.

A task can also end well and write no trace. The connected test task does that when an APK it needs did not install: it prints the phone's reason, runs no test and ends BUILD SUCCESSFUL. collect reads what the task printed and names the APK, the reason and the fix:

collection error: gradle finished, but `app-release-unsigned.apk` did not install on the phone, so the benchmark did not run and wrote no trace. The phone said: INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates from …
→ the APK is not signed, and a phone installs only signed ones. Sign it. With this computer's debug key add these four to `runner.gradle_args`, …

A release build whose build type sets signingConfig = null where its keys are not, on CI only say, comes out unsigned on every other computer. Four arguments sign it with the computer's debug key, the one every debug build is signed with (in ~/.android, or where ANDROID_USER_HOME says):

runner:
  gradle_args:
    - "-Pandroid.injected.signing.store.file=/Users/me/.android/debug.keystore"
    - "-Pandroid.injected.signing.store.password=android"
    - "-Pandroid.injected.signing.key.alias=androiddebugkey"
    - "-Pandroid.injected.signing.key.password=android"

A scenario's own runner.gradle_args takes the place of the shared list, so where a scenario has one, they go into that one. With no install that failed, the sentence says to check that the task is a macrobenchmark, that it ran, and that runner.project_root is the project that wrote the traces.

The connected test task uninstalls the app it tested when it ends, passed or failed, and an install that was on the phone before the round goes with it, its data too. The next launch round then stops on an app that is not installed. So when collect can tell which phone the round runs on (the one --device, runner.device or ANDROID_SERIAL names, or the one adb lists), it asks whether the app is there before the task and after it, and says when the round took it away:

  [!] com.example.app is no longer installed on R58M123ABC: the connected test task uninstalls the app it tested when it ends, passed or failed, …

Install the app again before a launch or command round. To have the round leave it installed, add -Pandroid.injected.androidTest.leaveApksInstalledAfterRun=true to runner.gradle_args (Android Gradle plugin 8.2 and later). collect does not pass it on its own: what is on the phone after a round stays what the plugin documents. An app that was not there before the round gets no line, and neither does a round whose phone collect cannot tell: several attached and none named, or no adb on PATH, which gradle mode does not need.

A startup macrobenchmark needs no end anchor. Every trace it writes holds the launch it drove, so its scenario can be scenario.window: launch, as in launch mode: see A window that is the launch. echolot scan drafts that window with this runner for a benchmark class that measures the launch: one that constructs StartupTimingMetric and names no TraceSectionMetric. The other classes get theirs by what they measure:

the class what scan drafts for its window
measures frames (FrameTimingMetric) and not the launch window: whole: each trace the benchmark writes is one repeat of its measure block. A TraceSectionMetric beside it is a section inside the scroll, not its end, and a section the test writes itself (trace(…), a traced(…) helper) is a slice of the benchmark's own process, which no window is read from; the _evidence names them
measures the launch (StartupTimingMetric) and names no section window: launch
names a section (TraceSectionMetric) start: bindApplication and the section as end: it is the developer's own statement of where "ready" is, so it comes before the launch
only sets StartupMode start: bindApplication and an end to pick from a probe: it may measure no launch

scan says which kind each class is, and names each kind in the module's line: drives com.example.app, a cold start and frame timing. It reads the class's own file: a benchmark whose metrics are listed in a shared helper names none of them there, and keeps an end to pick.

A module with one class is one scenario:. A module with several is a scenario for each under scenarios:, named after its class, with the class filter in the scenario's own runner.gradle_args and the task in the runner: they share:

scenarios:
  StartupBenchmark:
    window: {name: launch, _source: derived, _evidence: "StartupTimingMetric in …"}
    runner:
      gradle_args:
        - "-Pandroid.testInstrumentationRunnerArguments.class=com.example.benchmark.StartupBenchmark"
  ListScrollBenchmark:
    window: {name: whole, _source: derived, _evidence: "FrameTimingMetric in …"}
    runner:
      gradle_args:
        - "-Pandroid.testInstrumentationRunnerArguments.class=com.example.benchmark.ListScrollBenchmark"

runner:
  mode: gradle
  gradle_task: ":benchmark:connectedBenchmarkAndroidTest"

The first is the one collect and analyze take without --scenario: a class that measures the launch before one that only sets StartupMode, and one that measures frames last, though it starts each repeat cold. A section named by a constant, TraceSectionMetric(AppTraces.LIST_SHOWN), is looked up in the class's file first and then across the project's sources, so a constants object in another module is read too. When no declaration is found, the draft keeps end: "?" and its _evidence names the constant to look up.

A class whose tests start the app in different ways is a scenario for each test instead: one test with StartupMode.COLD, another with WARM or HOT, or two with different CompilationModes. A filter by the class ran them all, and one set of traces held ten cold starts with no compiled code, ten cold, ten warm and ten hot: a median over them is none of the four. Each test's scenario is named after it, and its filter, …class=<Class>#<test>, runs that test alone. scan reads the modes in the test's own body, or in a function of the same file the test calls, startup(CompilationMode.None()) beside a startup that passes StartupMode.COLD. A cold start comes first, and of the cold ones the compilation an installed app has, Partial (Macrobenchmark's default), before None. The platform may record no launch for a hot start, which brings back an activity that is still there; that scenario's _evidence says so. A class with several tests that all start the app one way stays one scenario, named after the class, since its filter runs them all; a class with one test is named after the test. A benchmark module whose build type the app does not have, benchmark { matchingFallbacks += "release" }, installs the app's release to run against, and scan names that build in the module's lines.

A class with a MacrobenchmarkRule that cannot run by itself, an abstract one or one with no @Test, is not drafted: a filter by it runs nothing. A repository of several apps keeps its startup benchmark in such a class of a shared library, and each app's test module runs it under a class of its own, class StartupBenchmarks : BaseStartupBenchmarks(). scan drafts each class that extends it and can run, through others that cannot, in its own module: that module's tasks, a filter on that class, and the tests and what they measure read from the classes it extends. A class of the same name in another package is not one of them: a supertype is taken by its full name, or by its simple name where the source imports it or shares its package. Of several such modules, the draft takes the one whose targetProjectPath names the app module read, else the first found, and a note says which and lists the others. A class that nothing here extends is named in a note, and no benchmark is drafted from it.

A benchmark module whose script turns some of its variants off has no task for them, and scan lists and drafts only the tasks that remain. It reads androidComponents { beforeVariants { variant.enable = … } } and the older variantFilter { setIgnore(true) }, with their selectors, for each variant: its build type, flavours and name, so variant.buildType in ["release", "nonMinifiedRelease"] is decided rather than guessed. Where that turns off the build the draft would start from, androidx.baselineprofile's benchmarkRelease say, the draft starts from the app's build a remaining task runs against, its package and mapping with it, and the output says what to let the script build to measure the other. A condition on anything else, a property or a file, is not read: the tasks stay listed, and the output and the runner's _evidence say which may not exist. A filter in the build code the script runs is not read either, and a note says where it is. The app's own filter leaves its variants out of the table the same way. Where the build to start from sets signingConfig = null, outright or in one branch of an if, the output and the draft say it is, or may be, built unsigned: an unsigned APK does not install.

A filter that sits in an if on a Gradle property is read with that property. if (!isBenchmarkEnabled()) { beforeVariants { variant -> variant.enable = false } }, in the module's script or in a convention plugin it applies, with isBenchmarkEnabled() reading providers.gradleProperty("benchmark"), turns every variant off unless the build passes -Pbenchmark=true. scan lists the tasks there are with the property, says they exist only with it, and the draft passes it in each gradle_args. The property is read from providers.gradleProperty, hasProperty, findProperty, property and properties[…], also through a function of the build code with no parameters that returns one. A side of || that reads only a property Android Studio passes on a sync (android.injected.…) counts for nothing: a build from the command line never has it. A filter in an if that runs only where a property is passed is in no build without it, and is left out.

The class filter in gradle_args runs every test of the class. A test that starts no launch inside its recording writes a trace with no launch in it, and analyze refuses such a trace under this window, naming it. In a set it leaves that trace out and names it, on stderr and under the report's Traces line, while the traces with a launch are more than half of the set; so does a trace that carried the app's process under a name cut to fifteen characters, which a round of fifteen has held once, and the sentence then names the process the mask took in its place. See A trace that gives no window.

The macrobenchmark chose what to record, so this mode builds no trace config of its own. environment, atrace_categories, buffer_kb, duration_ms, reset_policy and sampling are inert here, and collect says so when it finds them — they look like they apply, and copying them in from a launch-mode config is the obvious mistake. What the traces carry is the benchmark's decision, and the report says which platform state it actually found, and whether a callstack sampler ran. On the run these notes come from that was the clock and memory but no thermal.

project_root is both where the task runs and where the traces are looked for. A relative one is taken from the directory echolot.yml is in, the way -o and the investigation are, and it defaults to that directory. It matters as soon as echolot.yml does not sit beside gradlew: ./gradlew is a relative path, and it used to be looked for in whatever directory echolot happened to be started from, so the same config ran in two places depending on the shell.

"Everything that appeared after the run started" is a deliberate rule rather than a convenience. A benchmark module keeps every trace it has ever written — the directory this was first run in held fifteen from twelve days earlier — and gathering by name would quietly merge two sittings into one report and take medians across them.

Two practical notes. On an emulator the run refuses to start without a suppress:

-Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.suppressErrors=EMULATOR,LOW-BATTERY,UNLOCKED

And the task name is often ambiguous, because the baselineprofile plugin adds flavours. ./gradlew :benchmark:tasks | grep -i connected lists the options.

A directory the benchmark wrote by itself

A run started by hand, or a CI job's artefacts, leaves the traces where the benchmark wrote them, and analyze takes that directory as it stands:

echolot analyze benchmark/build/outputs/connected_android_test_additional_output/<variant>/connected/<device>/ \
  -c echolot.yml --test StartupBenchmark_cold

It reads one test's latest sitting out of it. The test is the one --test names, as analyze lists it (StartupBenchmark_cold, StartupBenchmark_startup[mode=COLD]) or as a class filter does (StartupBenchmark#cold, with or without its package, which takes every parameter set of the method). Without the flag it is the one the scenario's runner.gradle_args runs: gradle mode runs the scenario's test by that filter, so a CI job that analyses with the config collect records with reads the test collect would have run. Without either, it is the only test there, and a directory of several is refused with the command that reads each:

error: connected holds the traces of 2 Macrobenchmark tests, and a report is of one. Read one, with this command's other options:
  echolot analyze connected --test ScrollBenchmark_scroll  # 5 traces from 2026-11-26 18:00
  echolot analyze connected --test StartupBenchmark_cold   # 10 traces from 2026-11-26 17:51, 10 more of an earlier sitting

The sitting is the set of files benchmarkData.json lists for the test: the benchmark rewrites it on every run, and a release that names each test's trace files there (profilerOutputs) names that run's. Where it lists none of the test's, a sitting is a run of iteration numbers that rise in the order the iterations were written, and the one that begins last is read. The traces of the test's other sittings, the other tests and the directories under it are left out, and stderr says so as the run starts, as the report does under its header:

> Read from `connected`: the 10 traces of the Macrobenchmark test `StartupBenchmark_cold`, its latest sitting, 2026-11-26 17:51:03–17:56:39. Left out: 10 traces of an earlier sitting of it, begun 2026-11-14 10:02; the other test, `ScrollBenchmark_scroll` (5).

report.json keeps the same as directories. Older releases of the library wrote .trace rather than .perfetto-trace, and both are read.

Several scenarios

A project that guards a cold start and a feed scroll names both in one config, under scenarios: instead of scenario::

scenarios:
  cold_start:
    start: {name: "bindApplication"}
    end: {name: "Choreographer#doFrame*"}
  feed_scroll:
    start: {name: "feed_scroll_start"}
    end: {name: "feed_scroll_end"}
    runner:
      mode: command
      command: "adb shell input swipe 500 1500 500 300 600"
runner:
  mode: launch
  iterations: 5

Each scenario holds its window, and the runner keys it changes, laid over runner: for it alone: here the cold start is launched by collect, and the scroll is driven by a command, five times each. The same macrobenchmark task can serve both with another class in gradle_args, and echolot scan drafts it that way for a benchmark module with several classes: see gradle.

Each scenario may carry thresholds of its own. Two journeys of one app can differ two- or threefold in how long their slices and waits normally run, so thresholds calibrated on one of them hide rows in the other, or fill its report with rows that are only its normal run. A detectors: under a scenario's name is laid over the config's for that scenario alone, a threshold at a time, and echolot calibrate --scenario feed_scroll prints the section that goes there: see Calibrating.

echolot collect --scenario feed_scroll
echolot analyze .echolot/traces --scenario feed_scroll

The name goes into the traces' names, so the two sets live side by side in .echolot/traces/, and a new round of one sets aside that scenario's previous traces and no other's. Given the directory, analyze reads the named scenario's set out of it, and without --scenario refuses one that holds two of the config's scenarios, with the command that reads each. collect, analyze and calibrate take --scenario; without it they take the first scenario and say so on stderr. analyze first looks at what its traces were recorded as: collect keeps the scenario in each trace's .recording.json, and a trace from before that is read by its name, feed_scroll_iter000. A set recorded as one of the config's scenarios is measured as that one, and one recorded as two of them is refused (#815).

Each scenario keeps its own latest report too: analyze writes it to .echolot/out/<scenario>/ unless -o says otherwise, and the report names its scenario, in report.json and at the top of report.md. echolot report --scenario reads that scenario's report, the first one's without the flag. compare refuses two reports of different scenarios, and compares a report it is given with the latest report of that report's own scenario. A config with one scenario: keeps .echolot/out/.

An investigation is about one scenario too: echolot hunt --scenario feed_scroll "<question>" opens it on that one, and inside it the commands take its scenario when no --scenario is given.

Inside it means said so. collect --hunt <n> and analyze --hunt <n> run inside investigation <n>, the open one: the round collect pushes aside is recorded under it, analyze files a copy of its report there, both count as its work, and its scenario is the default. Without --hunt a run is outside any investigation, whatever is open: nothing of it is filed, the investigation is not counted as worked on, the first scenario is the default, and stderr says [i] outside investigation #<n>. A cold-start baseline recorded with a scroll investigation open used to be filed into it, renew it as worked on that day, and in a config with several scenarios be measured as the scroll (#498). A --hunt that names a number not open exits 2 before anything is recorded. A round of the investigation that a run outside it pushes aside is still recorded under the investigation: it is its evidence, whoever moved it.

echolot status lists each scenario on a line of its own, with its traces and its latest report, and marks the open investigation's. Its next step names the scenario, --scenario feed_scroll: the open investigation's, else the first.

In CI, the GitHub Action measures the scenario its scenario input names, one a step or one a leg of a matrix, each kept under its own artifact-name: Comparing shows the matrix.

Which device

In launch and command modes, in the order they are consulted:

  1. --device <serial> on the command line;
  2. runner.device — usually in local.yml, since a serial belongs to one machine rather than to the project;
  3. the one device adb devices lists in state device.

When none of them settles it, collect stops before anything is recorded and says why: adb sees no devices at all; several are ready and none was named; the device is unauthorized (accept the "Allow USB debugging?" prompt on its screen); it is offline (replug, or adb kill-server); or, on Linux, no permissions — adb can see it but may not open it, which a udev rule for the phone's USB vendor fixes. A serial that is named but not attached is refused with the list of those that are.

The chosen device reaches everything that runs on its behalf. In command mode the scenario gets it as ANDROID_SERIAL. In gradle mode the task picks its own device, and the connected test tasks run on every device adb lists unless ANDROID_SERIAL names one — so --device or runner.device is passed to gradle as ANDROID_SERIAL. With neither, an ANDROID_SERIAL already in your environment passes through untouched, and collect says it is using it.

The screen

A launch behind a dark, locked screen starts nothing that can be measured. On the SM-A515F, connected over USB and not charging, its screen dozing and its lock screen up, am start -W answered LaunchState: UNKNOWN (0) and no TotalTime. The traces held the app's process and no start, and the report could only say that the window's end anchor was missing.

So in launch and command modes collect reads the screen before the set and again before each repeat:

  • a screen that is asleep, dozing or showing a screensaver is woken;
  • a lock screen that asks for nothing is dismissed;
  • a lock screen that asks for a PIN, a pattern or a password stops collect before anything is recorded. Unlock the phone and collect again.

A screen that was on and unlocked gets no line. Whatever collect did to it gets one.

The screen can go dark during a set: a repeat can wait minutes for runner.cooldown, longer than a screen timeout. stay_on_while_plugged_in (Developer options, Stay awake) keeps the screen on only while the phone charges, and the A51 above was connected and not charging. When the screen went dark between repeats, the line says whether the phone was charging. A phone that locks with its screen stops the set there.

am start -W answering UNKNOWN after a force-stop means the system measured no start. If the screen went dark or locked since the check, collect stops at that repeat, and the traces recorded before it are kept; the repeat's own trace is not. On a screen that is on and unlocked the repeat is kept, and its line says that no start was measured.

In gradle mode the macrobenchmark drives the device, its screen included. collect reads from it only what runner.cooldown waits on, the power before the task, and whether the app is installed before and after it.

Power

A phone that is not charging records its set on a battery that drains, and one that runs low turns battery saver on, which slows it partway through a set. An SM-A515F ran a whole session on battery, 49% to 45%, and a later hunt on it from 44% to 39%, with nothing said: the read before each repeat knew the phone was not charging, and said it only when the screen went dark. Macrobenchmark refuses to start below 25% (LOW-BATTERY), charging or not.

So the read collect makes before the set and before each repeat (see The screen) also takes mIsPowered and mBatteryLevel from dumpsys power, and battery saver from settings get global low_power:

  • a phone that is not charging and is under runner.min_battery stops collect before anything is recorded. The default is 25, Macrobenchmark's mark; 0 turns the check off. A charging phone is not stopped: its level rises. In gradle mode the floor applies before the task, when collect can tell which phone the round runs on;
  • a phone that is not charging above it gets one line, and so does battery saver: [!] power: R58M123ABC is not charging, 49%. The set runs on a draining battery, …;
  • a change between repeats, the cable out or saver on, is said before the repeat that found it: [!] power before repeat 4 of 8: not charging, 71%, and charging, 72% before. ….

A charging phone with saver off gets no line. Each trace's account keeps power (charging or not charging), battery_saver (on or off) and battery_level; what the device did not print is null, never charging or off. analyze carries the first two into the report's recording block, and compare says when the two sides differ in them, or when one side's repeats do (see How the two were recorded). charging is the phone plugged in: a port too weak to keep up drains it all the same, and the level in each account shows that.

runner:
  min_battery: 25    # percent; 0 turns the check off. Belongs in local.yml

The build on the phone

A temporary marker reaches a trace only through a build, and launch and command modes record the build that is installed on the phone. A hunt ran mark --apply and then recorded five cold starts with nothing built in between. None of its markers was in the traces, the hunt put that down to the trace, and it ended without the breakdown the markers were placed for.

So when the code has temporary markers — the prefixed names on lines tagged // echolot:mark, in the checkout the config is in — collect reads the build on the phone for them before the set:

  • pm path lists the app's APKs, and the phone's own unzip and grep pick every name with the prefix out of their code. A marker's name is a string in the app's code, so the build holds it exactly when it was built with the marker in.
  • A build that lacks any of the code's markers stops collect before anything is recorded. The sentence names them, the files they are in, and the step that puts them on the phone, with the gradle task mark --apply names:
collection error: the build of com.example.app on R58M123ABC lacks 1 of the
2 temporary markers in the code (AGENTTMP_feed_load in
app/src/main/kotlin/FeedViewModel.kt), so no trace of it would hold it.
Build and install the app with `./gradlew :app:installBenchmark`, then
collect again. …
  • A build that has them all gets a line that says so, and the set goes on.

Any one marker the build lacks stops it. A build holds every marker its code had, whatever the scenario runs, so a round's new markers missing from a build that has the older ones are caught here. In the traces they would read as code the scenario does not run, and analyze warns only when the traces hold none of the code's markers. A build made from this code that still lacks a marker leaves out the file it is in: a test source, another module or flavour. Move the marker into code the app runs, or take it out. A name the code puts together at run time, "AGENTTMP_load_$id", is looked for by its fixed start, the only part of it that is a string in the build.

When the phone cannot answer — no unzip, a grep that cannot read the code, an APK the shell may not open — collect says the build could not be read and records the set as before, and analyze says afterwards if the traces lack the markers. The search first reads a short input whose answer is known and counts the code files it found, so a phone whose tools behave differently reads as "could not be read", never as a build without the markers. The line says which tool could not: what grep printed for that input, pm path listing no APK, unzip listing no code, or the status grep ended with on the code. How grep -z ends each name it prints is its own: toybox, on Android, ends it with a zero byte, as GNU grep does, and BSD grep with a line break. Either is read.

The reading costs one adb shell call, and only when the code has temporary markers. On the SM-A515F a large Kotlin app's APK, with 30 MB of code in three files, took about 2 s, and a small app's 0.3 s. It runs before the device is held still, so runner.cooldown takes the heat of it.

In command mode the scenario may install the app itself. A build that lacks markers before the set gets a line instead of a stop, and is read again once the first repeat has recorded: the set stops there if it still lacks them, and that repeat's trace is not kept.

The time the app was installed is not asked. Held against the time the files were written, it says when the build went on the phone, which is another question: a checkout, a rebase or a formatter makes a file newer than a build that has its markers, an APK built before them and installed after reads as new, and a time says nothing of a marker in a file the build leaves out.

In gradle mode the macrobenchmark builds the app from the code, and the build is not read.

The device's state

A duration is the work done over the speed it was done at, and a phone does not keep its speed. On the SM-A515F, eight launches of a large app recorded back to back all ran with the kernel throttling the big cluster, the first one included, and the clock they ran at fell repeat by repeat, from 2066 to 1915 MHz: the clock 7% lower at the last repeat than at the first, for an app nobody changed. At the start of five of the eight recordings the throttle was already on, left there by the repeat before.

Four keys under runner: hold the device still around a set. Each is off unless set, and a device's numbers belong in local.yml:

runner:
  cooldown:                 # before each repeat
    sensor: cpu             # battery (the default), cpu, gpu or skin
    max_c: 34
    timeout_s: 600
  fixed_performance: true   # the platform's fixed performance mode
  airplane_mode: true       # no radio while the set runs
  brightness: 128           # 0–255, auto-brightness off
  • cooldown waits before each repeat until the sensor reads at or below max_c. Eight more starts on the same phone, each waiting for its cpu sensor to read 34 °C, ran at 2032 to 2049 MHz with no drift, and none began with the throttle on. Each still throttled during its own start, since one start of that app is enough to trip it: what the wait gives is the same phone at the start of every repeat. The starts' own spread stayed what the app gives it, 8.6% back to back and 11.4% with the wait. The wait costs time: 91 to 203 seconds a repeat there, 17 minutes for the set against 2. battery is read from dumpsys battery, which every device has; cpu, gpu and skin from the thermal HAL, dumpsys thermalservice, from Android 10 on. A sensor the device does not have stops collect before anything is touched, naming the ones it has. The kernel's own zones, the ones that trip the throttle, are closed to the shell on a production build. The HAL's sensors are smoothed and lag them, so max_c goes a little above the sensor's reading at rest: 34 for the A51's cpu, which reads about 31 there. A device that does not cool within timeout_s is recorded anyway, and the line says so; the report's environment shows how hot it ran. In launch and command modes the app is stopped before the wait: nothing of it runs while the device cools, and a job it scheduled during the recording is not yet due when the stop comes (launch). The account collect keeps beside each trace, <trace>.recording.json, holds the cooldown and the sensor's reading before that repeat. When the kernel throttled anyway, the report reads it: a set cooled before every repeat was heated by the scenario itself, and waiting longer would not help, so the report says to compare it only with sets recorded the same way; a set recorded without cooldown is told to set it.
  • fixed_performance asks for the platform's fixed performance mode, which holds the clock at a level the device can keep. Whether a device has one is up to its power HAL: the A51 takes the command and moves no frequency limit. collect reads the limits before and after, and says which it was.
  • airplane_mode turns the radio off. An app that goes to the network at start does something else without it, so record both rounds of a comparison alike.
  • brightness holds the screen at one level, auto-brightness off.

Whatever collect changed, it puts back when the set ends, a failed set included, and says so a line each. In gradle mode the macrobenchmark runs its repeats back to back, so cooldown waits once, before the task.

While it runs, and when it fails

A macrobenchmark round is minutes of silence. collect writes where it stands to .echolot/log/collect.json — when it starts, after every iteration it drives, and when it ends — and echolot turns that into a collect line: running: coldStart, 7/15 iterations, started 3m ago, or the macrobenchmark drives the iterations in gradle mode. A run whose process is gone without finishing reads interrupted. One that failed reads failed 2m ago: followed by the line of the output that names the cause, such as the exception the benchmark threw, and the fix when the failure is a known one. That line stays until a newer set of traces exists.

A gradle round whose tests failed reads them from the result file the task wrote, build/outputs/androidTest-results/connected/…/TEST-<device>.xml, rather than from the console, which can name the failed task and none of its tests: the cause is StartupBenchmark.startupWarm failed: java.lang.IllegalStateException: …, and the error lists how many failed and which passed. A line of gradle's for a task it ran is never the cause unless that task FAILED, whatever words its name holds.

The traces such a round wrote before it failed are not collected into the set, and the set before stays where it was. They are copied beside it, into .echolot/traces/<scenario>-failed-<when>/, under the names the benchmark gave them, which name their tests; the error lists how many each test wrote and whether it passed, and the analyze that reads one test's. Left in the module's output directory, they would be gone with the task's next run.

A collect.json that does not parse, or one that holds what collect never writes there, such as text where it writes a time, gives no line: it describes no run, and the next collect writes it anew.

In launch and command modes collect reads the first repeat's trace before it records the rest, with the window analyze would cut. When the app drew no frame in it, or the end anchor opened and never closed, the scenario did not reach its screen (no network, an error screen, a dialog in the way), and every repeat after it would record the same: the round stops there, with that reason and nothing kept. A window that closes before the app's first frame is not one of them: bindApplication to activityStart in a cold start draws nothing because nothing was drawn yet, and its round goes on. Under scenario.window: launch the round stops too when the trace holds no launch of the app, with the reason analyze would give, such as a permission dialog over the launch or an app that crashed while it started. The trace waits for this reading beside the set, and the set from before moves only once it is let in: a round that stops here leaves .echolot/traces as it found it. With -n 1 the trace is kept and marked [!]. An end anchor that did not occur at all is marked and the round goes on, since a wrong name in the config reads the same; echolot probe on the trace says which, and the mark names the trace's slices that read like the anchor.

Ctrl-C, or Stop in echolot ui, puts the phone back as a failure does and ends with one line, collect interrupted after 2 of 5 repeats: their 2 traces are kept in .echolot/traces, and exit code 130. A trace whose copy from the phone was cut short is deleted, so the traces kept are whole ones. The recordings set aside as not cold are named on the same line, and when no repeat was kept yet they are what it names: collect interrupted before the first of 5 repeats was kept: the recording set aside as not cold is kept in .echolot/traces: startup_iter000-warm.perfetto-trace.

The run log, .echolot/log/runs.jsonl, keeps the same cause and fix at the head of the run's error, followed by as much of the full message as fits in the 800 characters it keeps.

Five gradle failures come with the one thing that fixes them:

the output says what it is the fix
Perfetto SDK / binary verification the SDK half of the tracing could not be set up in the app — usually a stale libtracing_perfetto.so in its code_cache reinstall, or pm clear where the device allows it; or turn that half off with -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.perfettoSdkTracing.enable=false in runner.gradle_args
ERRORS (not suppressed): EMULATOR, … the benchmark refuses the device or its state fix the state, or …androidx.benchmark.suppressErrors= with the names it lists, EMULATOR,LOW-BATTERY for one in runner.gradle_args
No online devices found / no devices/emulators found / device offline gradle found no device it could use adb devices should list one as device; a serial named with --device or runner.device reaches gradle as ANDROID_SERIAL and has to be one of those listed
INSTALL_PARSE_FAILED_NO_CERTIFICATES the APK is not signed, and a phone installs no APK that is not sign it: four -Pandroid.injected.signing.* arguments in runner.gradle_args sign it with this computer's debug key (gradle mode lists them); or give gradle the keys the build script signs with
INSTALL_FAILED / signatures do not match the APK did not install uninstall the app from the device first — a build signed differently cannot go over the one that is there

Anchors the code no longer writes

Before the first repeat, in every mode, collect holds the scenario's anchors against the code, and echolot does the same for each scenario, on an anchor line marked !. A name the app writes is a string in its Kotlin or Java, so an anchor that no string there is, or can be put together into at run time, is said, with what the code has that reads like it:

[!] end anchor `list_shown_mark` is in no Kotlin or Java string here; the code has
`list_shown` (app/src/main/java/com/example/app/Marks.kt:4) — the traces are the
scenario's whatever it is called: put the name right in echolot.yml before `analyze`

The platform's own sections are in no file of a project and are never said: bindApplication, an Activity's activityStart and performCreate:…, Choreographer#doFrame*, reportFullyDrawn*, RecyclerView's RV …, Compose's and androidx.startup's. A name with the temporary markers' prefix that the code no longer has is said as one. Any other name the code does not hold, with nothing in it that reads like it, may be a library's: it is said as a question, with the command that answers it (one recording, then echolot probe), and no more once a report of the scenario has found it in its recordings. An end anchor that is still scan's ? is said whatever the code holds, and next says to pick it from one recording before recording five.

None of this stops the round. The build on the phone is not the code, and a set recorded under a wrong name is still the scenario's: analyze cuts the window as it reads the traces, so the same set is read again once the name is right. When a report's recordings do not hold an anchor, its warning names their slices that read like it, The trace holds list_shown, which reads like it, where it used to send the reader to probe.

Android 15: what a force-stop adds to a cold start

On Android 15 am force-stop leaves a package in the stopped state, and the app's next start takes it out of it: system_server sends PACKAGE_UNSTOPPED, and the app is sent BOOT_COMPLETED (and LOCKED_BOOT_COMPLETED when it is direct-boot aware), as after a reboot. An app with a receiver for it runs that receiver on its main thread between bindApplication and its first activity. In 25 of 25 Wikipedia cold starts on an SM-F711B the window held broadcastReceiveComp: android.intent.action.BOOT_COMPLETED, 2.1–6.1 ms. A user whose process the system reclaimed gets none of it on the next start. reset_policy: force-stop and a startup macrobenchmark stop the app before every repeat, so every repeat runs it.

collect says so under the first repeat when its window holds the receiver, with its time, and the report says it above the findings, over the set:

> ⚠️ The main thread ran the app's `BOOT_COMPLETED` receiver inside the window: `broadcastReceiveComp: android.intent.action.BOOT_COMPLETED` 2.63 ms (2.13–6.1), in 9 of 9 repeats. On Android 15 `am force-stop` leaves an app stopped, …

report.json keeps it as window.boot_receivers. Its time is inside the window, the medians and the rows: it is the reset's work, not the start's, and nothing to look for in the start's code. For Wikipedia that is a few milliseconds; an app that schedules work, opens a database or syncs in its boot receiver has all of that in every cold start recorded this way.

The shell has no reset for an app that is not debuggable that both leaves the package unstopped and makes the next start cold. The nearest is am kill, which kills the app's process without stopping the package. Its price, on the SM-F711B (Android 15):

  • it kills nothing while the app is in front, nor 0.3 s after HOME; one second after HOME it did, and the next launch was COLD. It prints nothing either way, so whatever runs it has to look with pidof;
  • it leaves the app's alarms and jobs in place, which a force-stop cancels: the system may start the process for one of them before the launch, and the start is warm;
  • the package is stopped already when the round begins if anything force-stopped it before, and the first start carries the receiver all the same.

It is a command-mode recipe, not a reset_policy, so collect neither stops nor checks anything: the command says whether the start was cold.

scenarios:
  cold_start_unstopped:
    window: launch
    runner:
      mode: command
      reset_policy: none
      command: >
        adb shell input keyevent KEYCODE_HOME && sleep 1 &&
        adb shell am kill com.example.app && sleep 0.5 &&
        ! adb shell pidof com.example.app &&
        adb shell am start -W -n com.example.app/.MainActivity | grep -q 'LaunchState: COLD'

A repeat whose kill left the process there, or whose launch was not cold, fails the command, and collect stops at it. Otherwise read the receiver's time off the report and leave it out of what you look for.

pm clear is deliberately unsupported

reset_policy accepts force-stop and none; anything else is named in a warning and runs as force-stop. Wiping application data changes the scenario rather than repeating it: a cold start with an empty database and a real user's cold start are different things, and only one of them is worth measuring.

What the trace config must contain

The runner builds the perfetto config itself, but if you capture by hand (recipe in echolot/claude/skills/echolot/references/collect.md), four things are mandatory and a fifth decides whether the report can tell a slower machine from a slower app:

sched/sched_switch — without it there is no thread_state, and what stands on it goes: runnable_starvation, uninstrumented_cpu and io_wait go silent, anr_risk keeps only its slice source and loses a stall in code nobody traced, and the CPU clock weighting under Device loses its input. What a project with no instrumentation still gets is under Detectors for code nobody traced.

linux.process_stats with scan_all_processes_on_start — the only source of process names. Without it process.name is empty and the config matches nothing.

atrace_apps with the package name — otherwise the trace holds system slices only.

android.surfaceflinger.frametimeline — SurfaceFlinger's own record of every frame, and the only source frame_jank has. It is a separate data source rather than an atrace category:

data_sources: { config { name: "android.surfaceflinger.frametimeline" } }

Android 12 and up. On anything older the data source does not exist, perfetto records the rest without complaining, and the detector is silent — which reads exactly like "no bad frames". If jank is the question and the report says nothing, check the Android version before believing it.

linux.system_info — one packet the tracing service writes at the head of the trace: each core with the frequencies it can run at and, where the kernel says, its capacity.

data_sources: { config { name: "linux.system_info" } }

trace_processor groups the cores by those into little, medium and big, and the report's environment.cores says how much of the app's CPU time went to each kind and how busy each was. The clock alone cannot say it: it is weighted by where the app's threads ran, and a fast core at a low clock reads like a slow core at its own. On one phone a list scroll ran 89–92% of the app's CPU time on its single 2.84 GHz core and a tab switch 92–94% of it on the 2.42 GHz cluster, at the same 1630–1778 MHz mean. Without the packet every core is of one unknown kind and the report has no cores. It is written before the scenario starts and moves no time, so compare does not count it as another way of recording: a set recorded before collect asked for it compares with one recorded after. A tracing service that has no such source records the rest.

aidl — the atrace category that names a binder call's method. The server writes AIDL::java::IPackageManager::getPackageInfo::server inside its reply, and binder_txn's detail puts the method beside the process that answered: system_server IPackageManager.getPackageInfo 89% where it said system_server 85% and left the method to guess. It writes a slice around every AIDL call in every process, so its volume follows the device's traffic. On an SM-F711B with a large app, a 12 s cold start held 2,200–2,400 of them, a hundred in the app, and took 5.3–5.6% of the 128 MB buffer against 5.0–5.1% without; a 40 s list scroll held about 9,400 and took 80.7% against 80.1%. The method came with 350 of the app's 443 synchronous calls on the cold start, and with all 75 on the scroll.

It is not silent the way linux.system_info is. A native client in the app writes a slice of its own around its call, inside the scenario, and that slice takes the self time of the one the call sits in: on that scroll 163 of the 209 ms of Choreographer#scheduleVsyncLocked's self time on the main thread went to AIDL::cpp::IDisplayEventConnection::requestNextVsync::cppClient, a main_thread_block row of its own. So compare says a set recorded without the category was recorded differently, and names binder_txn and main_thread_block. A project's own runner.atrace_categories replaces the default list, and records aidl only if it names it.

The platform state — power/cpu_frequency, thermal/thermal_temperature, thermal/cdev_update, sched/sched_blocked_reason, and linux.sys_stats polling memory once a second:

      ftrace_events: "power/cpu_frequency"
      ftrace_events: "sched/sched_blocked_reason"
      ftrace_events: "thermal/thermal_temperature"
      ftrace_events: "thermal/cdev_update"
data_sources: { config {
    name: "linux.sys_stats"
    sys_stats_config { meminfo_period_ms: 1000 vmstat_period_ms: 1000 }
} }

Not mandatory, and the one thing on this page that changes what a comparison means. A duration is the work done divided by the speed the machine was doing it at: the same code on a lower clock takes longer, and compare without these numbers reports that as a regression. With them it says the clock moved instead. runner.environment: false leaves them out for a device whose buffer cannot afford them, and the report then says the device state was not recorded — never that it held steady. io_wait goes silent as well: the disk flag it reads comes from sched/sched_blocked_reason, one of these events.

power/cpu_idle is deliberately not in that list. It fires on every idle transition on every core, which is the largest source of events on the page, and it would add nothing: the clock is read only over intervals where the app's own threads held a core, and a core running a thread is not idle.

What this costs, measured on an SM-A515F (Android 13, eight cores, two cpufreq policies) over three twelve-second cold starts: cpu_frequency produced 4564–4940 samples per trace — about 400 a second, 1.6% of all ftrace events in the same trace — and the buffer never overran. Thermal came to 160 samples and memory to 396. The cost is not the reason to turn this off.

One of the four delivers less than it looks. sched/sched_blocked_reason carries io_wait, which works, and caller, which perfetto turns into a kernel function name by reading /proc/kallsyms. That file is unreadable on a production build, so blocked_function comes back empty there — on the A51 it was empty for all 6683 uninterruptible-sleep intervals in the trace, with and without symbolize_ksyms, while io_wait was filled in for 6486 of them. Expect the name of the blocking function on a userdebug kernel and nowhere else; io_wait is what tells disk waiting from other blocking everywhere.

There is also a requirement on the app itself: slices arrive only if it is profileable or debuggable. The manifest needs <profileable android:shell="true" />.

Callstack sampling

runner:
  sampling: 100    # Hz. `true` means 100; `false`, or no key, leaves it off

uninstrumented_cpu finds a thread that burned CPU with no slice around it, and without samples that is all it can say. What the thread was running takes another round: markers around the likely code, a new recording, another look. A callstack sampler records the answer alongside. Many times a second it notes which functions were on the stack of each thread that held a CPU, and the samples go into the same trace, on the same clock as everything else. The report reads them in the round that finds the blind spot: the row names what ran in the samples that fell there, and the nearest frame of the project's own code under it (Analysing). The Perfetto UI shows the same samples as a flame graph for any stretch of time you select.

It is off unless asked for, because it costs the app time. On the SM-A515F (Android 13, a user build), six cold starts of about 1.36 s recorded the way collect records them took 186 ms longer at 100 Hz than six without a sampler, 95% sure between 68 and 263 ms. The two kinds of start alternated, so the device's heat fell on both alike. A sampled set therefore compares only with another sampled at the same rate. The report says on its header whether a sampler ran, and compare warns when two rounds were not recorded alike. Two sampled rounds give compare more than rows: under a blind spot that moved, the functions whose share of its stacks moved (Inside what moved).

Three choices in the recording are deliberate, and the first two were settled on that device:

  • No process filter. The sampler judges a process once, by its name at its first sample, and drops one that does not match for the rest of the recording. A process just forked from zygote still carries zygote's name, so a filter by package name lost the cold start in four recordings of seven and got nothing of it at all. Without the filter every process is sampled, and only those that are profileable or debuggable come back with a stack, which in practice means the app's.
  • The app's frames, not the kernel's. Kotlin and Java frames come back by name, interpreted, JIT-compiled and compiled ahead of time alike. Frames of the framework, compiled into the system image, come back without one, and the unwinder mostly stops at them: in the blind spots of six sampled cold starts, 69% of the stacks ended there. A minified build's frames carry their minified names, a.b.c, until project.mapping names the build's mapping.txt — see below.
  • A buffer of its own, the size of buffer_kb, so the samples can never push out the sched and atrace events every detector reads.

true means 100 Hz. A higher rate buys more samples and costs about the same — 250 Hz, filtered to the app, had cost the same start 156 ms — but the unwinding falls behind: at 100 Hz every one of the app's samples in the window came with a stack, wherever a recording got stacks at all; at 250 Hz 77 to 85% did, and at 1 kHz one in seven came without, every one of them in the busiest seconds. Perfetto advises staying under 200 for Java and Kotlin stacks, and collect warns above that.

Two requirements. The app has to be profileable or debuggable, which is the same <profileable android:shell="true" /> the slices need. And the device needs Perfetto's sampler, traced_perf: the recordings above ran on Android 13, and Perfetto documents CPU profiling for Android 15 and up. When the recording asks for samples and no sampler starts, the report says so rather than showing none.

What the report says, on the line under Device:

the report says what happened
Sampled callstacks at 100 Hz: 1482 samples of this process in the window, 99% with a stack a sampler ran and unwound the app
… they came with a stack in 5 of 6 repeats and with none in the rest the sampler lost the process as it started in one repeat, which has no stacks to read
… none with a stack the app is not profileable or debuggable, or the sampler lost the process as it started; another round tells which
… none of the samples in the window is this process's the recording was filtered by process name and missed the start
The recording asked for callstack samples … and none arrived the device's sampler did not run

The last three are warnings. A profileable app does lose every stack of a cold start now and then: on the SM-A515F it happened in one recording of six, and the other five had a stack on every sample. The sampler asks a process for access to its memory once, at its first sample; that time it did not get it, and every sample after that was written without a stack.

What the report reads is the trace, never the config, so a trace recorded some other way says the same. In gradle mode the benchmark records with its own config and runner.sampling does not apply, but the report still says whether its traces hold samples.

A minified build

A benchmark build is meant to run what the release runs, and that usually means minified: the frames of the app's code, and of the libraries it ships, come back with the names R8 gave them, a.b.c. Name the build's mapping in the config:

project:
  package: com.example.app.benchmark   # as installed on the device
  mapping: app/build/outputs/mapping/benchmark/mapping.txt

echolot scan writes the key into the config it drafts when the variant to measure is minified: its build type sets minifyEnabled, or starts with initWith from one that does, as a benchmark build type started from release usually is. The flag may be set in the project's build code rather than in the app's script: a plugin of buildSrc or build-logic that the script applies, by its id or by its class (plugins.apply(AppPlugin::class)), and that configures buildTypes { getByName("release") { … } }, itself or in a class it makes. scan reads that block, leaves out one under a library's extension, and the _evidence names its file. Build types the build code configures all at once (buildTypes.configureEach { … }), and a flag set to an expression, are not read; the notes and the draft say which. The benchmarkRelease that the androidx.baselineprofile plugin adds, which no build script names, is minified as release is, and scan takes it as the variant to measure: it is profileable whatever the manifest says. The path is where AGP writes the mapping when the variant is built, so it may name a file that is not there yet. gradle mode builds the variant with the first collect; in launch mode it is there once you build the variant. Until then analyze says so, on stderr and at the top of the report, and makes the report without it: R8's names stay as recorded.

analyze reads the file into a deobfuscation packet and hands it to trace_processor after each trace, the way Perfetto's own tools attach one; the trace on disk is not touched. The packet names no package, so trace_processor names back the frames of whatever package the build was installed under: a benchmark build installed as com.example.app.benchmark comes back by its names while project.package says com.example.app, and the header counts its methods as the app's. Another app's frames are renamed too where their minified names are ones this mapping lists, and the report reads none of them: only the measured process's stacks. A packet without a package takes trace_processor v59.1 or newer, the one echolot pins; an older binary of your own (toolchain.tp_binary) leaves every frame as R8 wrote it, and doctor fails its R8 checks with it. A method R8 gave the same name as another — overloads usually share one — comes back as both, Store.load | Store.save, because a sample has no line to tell them apart.

Reading a mapping costs seconds, and each trace loads more slowly with it. Wikipedia's Android app, built for a benchmark, wrote one of 158 MB; reading it took 1.3 to 6.5 s on an M3 Pro, by how busy the machine was. So the packet is kept in the project's .echolot/cache/mapping/ under the mapping's contents, and the next analyze of the same build reads it back in 70 ms: analyze of one cold start with that mapping went from 3.8 s to 1.9 s. The four packets used last are kept, 2.2 MB each for that mapping. A rebuilt mapping is another packet, never the old one; deleting the folder costs the next analyze one read of the mapping.

The runtime also writes frames as text, and trace_processor sees none of those: both sides of a lock in ART's contention slice, and every thread of an ANR record. They carry a line, and the line is what R8's own retrace goes by. analyze names back the lock's two frames with the same mapping before it places them (From a row to a line), and echolot anr names back a record's (A minified build). One frame comes back as the method the runtime stood in, at the line it came from, and the methods it was inlined into, by the names R8's retrace gives. What a build writes depends on how it was built. A test app built three ways with R8 9.0 wrote this on an SM-A515F with Android 13:

the build the lock slice the ANR record
line numbers kept, -renamesourcefileattribute SourceFile, minimum API 24 a.a.run()(SourceFile:6) a.a.run(SourceFile:6)
no -keepattributes a.a.run()(r8-map-id-…:6) a.a.run(r8-map-id-…:6)
line numbers kept, minimum API 26 a.a.run()(SourceFile:-1) a.a.run(unavailable:20)

The last build has no line table at all: R8 maps the offsets of the instructions instead. The ANR record prints the offset where the line would be, and that is named exactly. The lock slice prints -1, and its frames are named by the methods R8 kept, with no line; their declarations are then the place, as for a release build that kept its names.

The header says how the app's sampled methods came back, and what the mapping made of the lock slices:

the report says what happened
… of the app's … sampled methods read as minified, a.b.c a minified build and no project.mapping
project.mapping named … of the app's … sampled methods back the mapping is this build's; any still minified arrived that way
… still read as minified after project.mapping renamed … a mapping from another build: it renames the frames it happens to match, wrongly, and misses the rest
project.mapping named back the … frames R8 wrote into the lock slices code names the real methods, and the evidence keeps the frames as recorded
… of the … frames R8 wrote into the lock slices have no place in project.mapping a mapping from another build: no range of their method holds their line
… had no place in it and keeps R8's method name a line the mapping has no range for, which the right one can leave in a synthetic class R8 merged: one frame, or frames named after this very mapping, say nothing against it
project.mapping named back … of the app's … sampled methods, and they did not read as minified the build recorded keeps its names, or the mapping is another build's
the lock slices name their files after mapping …, and project.mapping is … another build's mapping, told by its id: the frames stay as recorded
project.mapping names …, and no file was there the variant has not been built since the config named it: build it and analyze again

The warnings about the sampled methods wait for a tenth of them. Some code arrives minified from elsewhere — SDKs ship that way — and no mapping of this build names it: a build that kept its names had 38 of its 3,309 sampled methods so on the SM-A515F, a little over 1%. Another build's mapping is told by what it misses: R8's names are short and reused, so it knows a few of this build's names, renames those wrongly, and leaves the rest as they were. The names it got wrong cannot be told from right ones; the ones it left are what gives it away. A build that kept its names leaves nothing minified, and the sign is the other way round: the mapping names back none of its methods.

The lock slices' frames carry a line, and another build's mapping is told by lines no range of the method holds. The right mapping leaves such a line too, now and then: R8 merges lambdas of several classes into one synthetic class and writes no range for a line the runtime prints there. On the Wikipedia app that was one of a lock's two frames, while the other frame, in a class of the same kind, came back right. So one such frame is counted and not warned about, and from two of them and a tenth of the frames up, the header warns. Such a frame gets its class back and keeps R8's method name, with no line. A build that names its files after its mapping, r8-map-id-<id> when it kept no source file names, says outright which mapping it has: when no frame carries the mapping's own pg_map_id, nothing is named back, and when they carry it, the mapping is this build's whatever lines it misses, and the header says so. And a class R8 kept is in the mapping under its own name, so its frame is named back on the strength of a line in one of R8's ranges only when something else shows the build is minified: a frame of a class or a method R8 renamed, a file R8 named, or a sampled method the mapping named back. A build that kept its names keeps its lines.

Composable names

A Compose app that carries androidx.compose.runtime:runtime-tracing can name every composable call in a trace, and the composables detector ranks the app's own by the time they hold (Analysing). The names come through the app's Perfetto SDK, which is off until something switches it on:

runner:
  compose_names: true

Before the first repeat, collect asks the app which version of tracing-perfetto it carries and takes that version's library for the device's ABI, tracing-perfetto-binary from Gradle's cache or from Google's Maven, checked against the SHA-1 published beside it and kept in ~/.cache/echolot. It pushes the library into the app's own media directory, switches cold-start tracing on, and adds the SDK's track_event source to the recording. After the set it switches it off and removes the library, a failed set included.

On an SM-A515F with a Compose app built for it, three cold starts each came back with all 921 composable calls of the start, and the report ranked the app's own with their files and lines. It costs the start: loading the SDK took the app 54 to 87 ms, and a cold start of about 580 ms ran 67 ms longer on the median. So a round with names compares only with another with names, the report says which it was, and compare warns when two were not recorded alike.

Two things the device decides:

  • Android 11 or later, the library's own minimum. An app without runtime-tracing has no receiver to switch, and collect stops with a sentence before anything is recorded.
  • The recording starts differently. perfetto --background-wait, which collect otherwise waits on, waits for every process on the device that has the Perfetto SDK to start its data source. Frozen background apps never answer, and on that device it came back after 22 seconds, past the end of a 12-second recording. With names on, the recording detaches at once and the scenario starts two seconds later.

With reset_policy: none nothing stops the app between repeats, and the names do not stop it either: the scenario finds the app on the screen it was left on. If the app is running, collect switches the SDK on in that process (ENABLE_TRACING, the switch Macrobenchmark uses for a process that is alive), and the names arrive from the next frame on; the line before the first repeat says the Perfetto SDK on in the running app. A running process cannot switch the SDK off again, so it keeps it until it ends, and nothing switches it on at the app's next start. An app that was not running gets the cold-start switch and is left stopped, as it was found, and the scenario's own start is the one that loads the SDK. With force-stop every repeat is a cold start, and the switch is for those.

In gradle mode the macrobenchmark makes the recording, and its own flag switches the SDK on: -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.perfettoSdkTracing.enable=true in runner.gradle_args.

Merging repeats

Numbers are merged by median — not by mean (one outlier would drag the conclusion along) and not by maximum (then any random hiccup becomes a "finding"). The one exception is Max, the longest single occurrence: it is the longest any repeat saw, and each repeat's own is in spread.max_ms.

The whole point of repeating is the Runs column:

Where Runs N Total, ms
m.example.app 3/3 80 56.92
RenderThread 1/3 30 39.02

The first row reproduces, the second happened once. Without that column they look equally convincing and the agent goes off investigating an accident.

A detector reports a row only where it clears a threshold, and a row missing from one repeat may have been there below it. So analyze of several recordings runs each detector a second time with its calibrated thresholds at zero and no limit on rows, and looks up there every row some repeat reported. Runs counts the repeats where the thing happened; where that differs from the repeats where it cleared the bar, the cell says so: 5/5, over the bar in 1, with fired: "1/5" in report.json. The median and spread cover every repeat it happened in.

A row is named with the numbers the runtime picks anew in each run left out: a lock owner's tid (Lock contention on a monitor lock (owner tid: #)), a frame's number (Choreographer#doFrame #), the number of a pool or unnamed thread (Thread-#, pool-#-thread-#), an object's identity hash, new in every process, which ViewRootImpl writes after the name of a window (draw-VRI[MainActivity]@#). Every detector folds a name this one way before it adds anything up, so a pool's workers are one row with all of them counted in Threads, in a report of one recording as in a set, and one wait seen in every run is one row, 3/3. The names the trace had under a folded one, up to twenty, are kept in the row's variants in report.json. Line numbers in a lock note, and the project's own markers, keep their digits.

The kernel keeps fifteen characters of a thread's name, and a number in it is as wide as the runtime made it, so a wider one moves the cut. A process's binder thread is HwBinder:1234_1 under a four-digit pid and HwBinder:12345_ under a five-digit one; the twelfth pool's worker is pool-12-thread- where the third's is pool-3-thread-1. A name of fifteen characters that the cut left in the middle of such a number, or of the -thread- around it, is folded as the name whole: HwBinder:#_# and pool-#-thread-# (#1077). The same build started on two days, its pid under 10000 on one and over it on the other, would otherwise read in compare as rows gone and rows new. The row's variants keep the name as the trace had it, cut. A name of any other length, or one the cut left on a word (DefaultDispatch, every coroutine worker), keeps its own fold.

Two warnings come out of merging:

  • the runner prints the am start -W spread and flags it above 30% — the device is under load and thresholds from such runs will be noisy (a launch that reports TotalTime: 0 was not timed, and is counted apart);
  • the report flags repeat windows that diverged more than twofold — those are not repeats of one scenario, and a median over them means nothing.

The recordings are put in one order, whatever order the paths were given in: the same set is the same report. It is the order they were recorded in, by each trace's own clock, and for a set of which some trace does not say when, by directory and then by file name with numbers read as numbers (_iter2 before _iter10), so that a set merged from several rounds keeps each round together (#848). It is the order of every spread.values list. The pid and window times in the header are the first recording's, and the header says so.