Skip to content

Add setup_profiling_device.sh to disable the profiling rate limiter - #253

Merged
sdzhong merged 1 commit into
mainfrom
profiling-rate-limiter-script
Aug 10, 2026
Merged

Add setup_profiling_device.sh to disable the profiling rate limiter#253
sdzhong merged 1 commit into
mainfrom
profiling-rate-limiter-script

Conversation

@sdzhong

@sdzhong sdzhong commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds setup_profiling_device.sh, a one-shot helper that disables the Android Framework profiling rate limiter on a connected device or emulator.

On API 35+ the Sentry SDK uses the platform ProfilingManager (Perfetto) backend. The framework rate limits profiling requests there — per the profiling limitations docs, they are "not guaranteed to be fulfilled." The result is sparse or missing profiles when testing locally or generating automated demo data, which reads as a broken SDK when it isn't.

The docs give a one-line workaround:

adb shell device_config put profiling_testing rate_limiter.disabled true

This script wraps it with the parts that are easy to get wrong by hand:

  • Skips API < 35, where the legacy profiler is used and the framework rate limiter doesn't apply — so it's safe to run unconditionally. Relevant here since minSdkVersion is 21.
  • Pins the namespace with device_config set_sync_disabled_for_tests persistent first, so the platform config updater can't resync and silently revert the flag mid-session.
  • Reads the flag back and fails loudly if it didn't stick. Some locked-down retail devices deny the write.
  • Finds adb via $ANDROID_HOME, $ANDROID_SDK_ROOT, the sdk.dir in local.properties that Gradle already reads, and the default macOS SDK path — Android Studio doesn't put platform-tools on PATH.
  • Handles device selection — clear errors for zero devices, multiple devices, or a serial that isn't attached.

Why this matters now

This is the same framework rate limiter that gates the Perfetto profiling path newly enabled by SDK 8.51.0 (#247). This app leans on profiling harder than most demos — io.sentry.traces.profiling.session-sample-rate, .lifecycle, and .start-on-app-start in the manifest, plus InitContentProvider writing an app-start profiling config so the profiler runs before Sentry.init.

Also

Adds a step to the README Run section pointing at the script.

Note on automated data generation

The TDA harness that drives the released APK lives outside this repo, so this script can't wire itself in there. If that harness runs on a managed device farm (Firebase Test Lab, SauceLabs, BrowserStack) where arbitrary pre-launch adb isn't available, API 35+ profiling data will stay rate-limited regardless — worth knowing before treating it as an SDK problem.

Testing

Verified against two live emulators — a google_apis API 36 AVD and an existing API 34 one:

Case Result
API 36, explicit serial Both device_config calls run; flag reads back true
API 36, second run Idempotent, same result
API 34 Early-exits cleanly, device left untouched (null)
No serial, 2 devices attached Exits 1, prints the device list
Serial not attached Exits 1 immediately
No SDK on PATH, ANDROID_HOME unset Resolves adb via local.properties

Confirmed independently of the script's own output:

$ adb -s emulator-5556 shell device_config get profiling_testing rate_limiter.disabled
true
$ adb -s emulator-5556 shell device_config get_sync_disabled_for_tests
persistent

Two bugs were caught and fixed during this verification: adb resolution failing when platform-tools isn't on PATH (the common Android Studio setup), and a typo'd serial hanging forever in adb wait-for-device with no output.


🤖 Generated with Claude Code

On API 35+ the Sentry SDK uses the platform ProfilingManager (Perfetto)
backend. The Android Framework rate limits profiling requests there and
does not guarantee they are fulfilled, so profiles come back sparse or
missing when testing locally or generating automated demo data.

This wraps the workaround from the Sentry profiling docs:

  adb shell device_config put profiling_testing rate_limiter.disabled true

The script adds the bits that are easy to miss by hand:

- skips API < 35, where the legacy profiler is used and the framework
  rate limiter does not apply
- pins the namespace with set_sync_disabled_for_tests first, so the
  platform config updater cannot silently revert the flag mid-session
- reads the flag back and fails loudly if it did not stick, which some
  locked-down retail devices will do
- handles device selection when more than one is attached

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sentry

sentry Bot commented Aug 7, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Android com.example.vu.android 24.12.26 (241226) release
Android com.example.vu.android 24.12.26 (241226) debug
Android com.example.vu.android 24.12.26 (241226) release

⚙️ android Build Distribution Settings

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (410e6f1) to head (5c42597).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #253   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         16      16           
  Lines        883     883           
  Branches      67      67           
=====================================
  Misses       883     883           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sdzhong
sdzhong merged commit 21c77a4 into main Aug 10, 2026
7 checks passed
@sdzhong
sdzhong deleted the profiling-rate-limiter-script branch August 10, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants