Generate markers to include in the Firefox Profiler from adb commands
Running node adb-markers.js
will start a server on localhost:2222
.
In Firefox 125 or later configured for remote profiling a Firefox instance on Android:
- on the host computer, in
about:config
, set thedevtools.performance.recording.markers.external-url
preference tohttps://localhost:2222/markers
. - use the 'power' preset (or any configuration that uses the 'power' feature) when starting the profiler.
- when capturing the profile, the Firefox Profiler will automatically fetch additional markers from
adb shell dumpsys batterystats
andadb logcat
, and add them to the profile.
- ensure USB power profiling works, and
https://localhost:2121/profile
returns valid profiles. - Load
https://localhost:2222/profile
in the Firefox Profiler.
GET /markers?start=<start timestamp in ms>&end=<end timestamp in ms>
returns JSON data containing markers that can be added to a gecko profile by the Firefox Profiler front-end. The data contains: an array of categories, a markers data table, and an array of marker schemas.
The start timestamp should beprofile.meta.startTime + profile.meta.profilingStartTime
from the profile and the end timestamp should beprofile.meta.startTime + profile.meta.profilingEndTime
.GET /profile
will return a profile retrieved fromhttps://localhost:2121/profile
extended with markers fromadb
. You can view it by loading it in the Firefox Profiler.GET /reset
will issueadb
commands meant to put the phone in a state where it will produce the data this script expects:adb shell dumpsys battery unplug
: Android only adds data to battery stats when using the device on battery or when charing the battery. It stops adding data once the battery is full. This command works around the issue by mocking an unplugged battery state.adb shell dumpsys batterystats --reset
: resets the batterystats history. For unkown reasons, the timestamps drift slowly over time (eg. off by a few minutes after a few days), so resetting the history when starting a profiling session increases the accuracy of marker timestamps.adb shell dumpsys batterystats --enable full-history
: make the batterystats history include events about processes.
- Debugging APIs:
GET /dump
: dump the raw output ofadb shell dumpsys batterystats -c
(-c
here means 'checkin', ie the machine readable output format of batterystats).GET /dump-verbose
: dump the (mostly) human readable output ofadb shell dumpsys batterystats
.GET /events
: dump the batterystats events in plain text.GET /events.json
: dump the batterystats events as JSON objects.GET /logcat.json
: dump the last 1000 logcat messages as JSON objects.