Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 0 additions & 65 deletions .github/workflows/integration-tests-macrobenchmark.yml

This file was deleted.

35 changes: 0 additions & 35 deletions .sauce/sentry-uitest-android-macrobenchmark.yml

This file was deleted.

142 changes: 0 additions & 142 deletions scripts/parse-macrobenchmark-log.py

This file was deleted.

2 changes: 1 addition & 1 deletion sentry-android-integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This directory is a separate Gradle build that includes the SDK build, so run it
symlinks to the SDK build's, so both builds use the same Gradle, JDK and settings.

* [Sample app](./sentry-samples-android)
* [Macrobenchmark](./sentry-uitest-android-macrobenchmark) - cold start of the sample app, run locally or within SauceLabs (see /.sauce/*.yml)
* [Macrobenchmark](./sentry-uitest-android-macrobenchmark) - cold start of the sample app, run locally on a connected device
* [Espresso-based UI tests](./sentry-uitest-android) - run on an emulator in the AGP matrix workflow
* [Maestro-based critical UI tests](./sentry-uitest-android-critical) - run by the UI Tests Critical workflow
* [App size test](./test-app-size) - built by the SDK Size Analysis workflow
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,7 @@ Connect a device, then:
Results print to the console and are written to
`build/outputs/connected_android_test_additional_output/.../*-benchmarkData.json`.

## Running on Sauce Labs

The `Integration Tests - Macrobenchmark` workflow (manual trigger) runs the same benchmark on a
Sauce Labs real device. It reports numbers only — it is not a PR gate, because cloud devices run
with unlocked CPU clocks and the run-to-run spread swamps most SDK-init changes.

Getting the numbers *back off* the device is the awkward part, so if you are changing this, know
what has already been ruled out:

- **`artifacts.download.match` in `.sauce/*.yml` cannot reach the device.** It filters a
hardcoded list of assets Sauce hosts for the job (`device.log`, `junit.xml`, `video.mp4`,
`network.har`, `crash.json`, `screenshots.zip`); nothing enumerates device storage. A
`*-benchmarkData.json` pattern there matches nothing.
- **Macrobenchmark's own reporting channels don't survive.** The readable summary goes into the
instrumentation status bundle, which only Studio and AGP consume, and `benchmarkData.json` is
written to the app's external media dir, which Sauce never pulls.
- **The Real Device Access API can pull device files, but not on our account.** It offers
`pullFile` and `executeShellCommand`, and `GET /rdc/v2/devices/status` even lists the whole
public fleet — but `POST /sessions` answers `deviceClasses=[PRIVATE_DEVICE]` and there is no
parameter to request a public device. It would need leased private devices. That route would
also return the per-iteration perfetto traces, so it is worth revisiting if we ever get them.

So `SentryStartupBenchmark` echoes its own `benchmarkData.json` into logcat in chunks, which
reaches CI inside `device.log`, and `scripts/parse-macrobenchmark-log.py` reassembles it and
writes a `timeToInitialDisplay` table to the job summary. Note this recovers the metrics only —
the perfetto traces are megabytes each and cannot go through logcat, so sub-millisecond work
still needs a local device.

### Device hygiene (do this for trustworthy numbers)
## Device hygiene (do this for trustworthy numbers)

- **Wake and unlock the device first** — the launch check fails with "Unable to confirm activity
launch completion" on a dozing/locked screen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package io.sentry.uitest.android.macrobenchmark

import android.util.Log
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.ExperimentalMetricApi
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.TraceSectionMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import java.io.File
import org.junit.AfterClass
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -47,59 +43,10 @@ class SentryStartupBenchmark {
startActivityAndWait()
}

// Not private: @AfterClass needs a public static method.
companion object {
private const val TARGET_PACKAGE = "io.sentry.samples.android"

// Matches the android.os.Trace section name in SentryAndroid.init.
private const val INIT_TRACE_SECTION = "SentryAndroid.init"

private const val BENCHMARK_DATA_SUFFIX = "-benchmarkData.json"

/** Kept in sync with `scripts/parse-macrobenchmark-log.py`. */
private const val LOG_TAG = "SentryBenchmarkData"

/** Well under logcat's ~4 KB per-message cap, so a chunk is never silently truncated. */
private const val CHUNK_LENGTH = 2000

/**
* Echoes the benchmark results into logcat so CI can recover them.
*
* Macrobenchmark reports its numbers two ways, and on Sauce Labs neither one arrives: the
* human-readable summary goes into the instrumentation status bundle (which only Studio and AGP
* read), and `<pkg>-benchmarkData.json` is written to the app's external media dir, which Sauce
* cannot pull — it only returns assets it produces itself, and logcat is one of them.
*
* Safe to run at this point because `ResultWriter` writes the file synchronously as each result
* is appended; only its *reporting* is deferred to the end of the run. Locally this is just
* extra logcat noise — Gradle still copies the real file into the build directory.
*/
@JvmStatic
@AfterClass
fun logBenchmarkDataToLogcat() {
val benchmarkData = findBenchmarkData()
if (benchmarkData == null) {
Log.w(LOG_TAG, "No *$BENCHMARK_DATA_SUFFIX found, cannot report results to CI")
return
}

// Dropping the indentation makes the JSON compact enough to survive as a few logcat
// messages. Only structural whitespace is affected: JSON forbids raw newlines inside
// strings, so no value can span lines or start with the indentation being trimmed.
val compactJson = benchmarkData.readText().lineSequence().joinToString("") { it.trimStart() }
val chunks = compactJson.chunked(CHUNK_LENGTH)
chunks.forEachIndexed { index, chunk ->
Log.i(LOG_TAG, "[${index + 1}/${chunks.size}]$chunk")
}
}

private fun findBenchmarkData(): File? {
val context = InstrumentationRegistry.getInstrumentation().targetContext
// This is where Macrobenchmark writes to for some reason.
@Suppress("DEPRECATION") val mediaDirs = context.externalMediaDirs.toList()
return (mediaDirs + context.externalCacheDir).filterNotNull().firstNotNullOfOrNull { dir ->
dir.listFiles()?.firstOrNull { it.name.endsWith(BENCHMARK_DATA_SUFFIX) }
}
}
}
}
Loading