Closed Bug 1956859 Opened 1 year ago Closed 3 months ago

Provide a script which captures a startup profile from Fenix over adb

Categories

(Core :: Gecko Profiler, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
148 Branch
Tracking Status
firefox148 --- fixed

People

(Reporter: mstange, Assigned: mleclair, NeedInfo)

References

Details

(Whiteboard: [fxdroid],[group1])

Attachments

(1 file)

It's too much work to get a startup profile from Firefox for Android using the Gecko profiler.

It would be great to have a script which does the following, using adb:

  1. Terminate any running Firefox processes.
  2. Launch Firefox in a way that simulates either a tap on the icon or an app link intent.
  3. Wait for a number of seconds, defaulting to 10 seconds but configurable with a command line argument.
  4. Send a signal to the Fenix parent process to save the profile to disk (bug 1904639).
  5. Wait for the profile to be collected.
  6. Pull the profile JSON file from the phone.
  7. If samply is installed, run samply load profile.json

We have an existing setup-startup-profiling.py script which we could morph into a startup-profiling.py script with a new record subcommand.

Then all of this could just become a single command: ./mobile/android/fenix/tools/startup-profiling.py record nightly


For comparison, here's what you have to do to get startup profiles from Firefox for Android today:

  1. Go to the Firefox settings and turn off Remote Debugging, in order to avoid startup overhead from it.
  2. Execute adb commands on the host to terminate running Firefox processes and send the intent to launch Firefox.
  3. Wait until startup finishes.
  4. Using your finger on the phone screen, go into the Firefox settings and re-enable Remote Debugging.
  5. On the host machine, go back to the about:debugging tab, click connect, click the phone, click Profile performance, click Capture recording, wait. (that's 5 clicks, see bug 1884893)

Would having something like the new button in about:profiling to restart fenix with profiling work?
I'm also working on adding code to about:logging to be able to upload and share a profile URL easily from Android (bug 1803607). So maybe gluing both works would solve this issue?

(In reply to Julien Wajsberg [:julienw] from comment #1)

Would having something like the new button in about:profiling to restart fenix with profiling work?

Sure, but wouldn't that be quite a bit harder to implement? And I feel like the bar for quality is quite a bit higher in functionality that is exposed through the browser UI, as opposed to something that's just in a developer script.

For example:

  • Startup profiling needs to happen with remote debugging off. How would you get to the about:profiling UI for the phone? Not via about:debugging? Or would you load about:profiling into the Android browser?
  • Setting the startup environment variables for startup profiling can currently only be done via a yaml file which is stored in a place that's only readable but not writable by the app. How would about:profiling create the file? By using adb on the host, I guess?
  • With the current script, you need to invoke deactivate explicitly to turn startup profiling back off. It's easy to forget this. If we exposed something on about:profiling it would need to automatically turn the environment variables off for the next restart, I guess also using adb directly.

I'm also working on adding code to about:logging to be able to upload and share a profile URL easily from Android (bug 1803607). So maybe gluing both works would solve this issue?

Maybe? Seems rather non-specific at the moment. The script approach we know how to do (with the one exception that we haven't verified whether sending a signal with adb works).

(In reply to Markus Stange [:mstange] from comment #0)

  1. Terminate any running Firefox processes.
  2. Launch Firefox in a way that simulates either a tap on the icon or an app link intent.
  3. Wait for a number of seconds, defaulting to 10 seconds but configurable with a command line argument.
  4. Send a signal to the Fenix parent process to save the profile to disk (bug 1904639).

I just tested this and it doesn't actually work - you can only send a signal if you're root, or if the target process is running under the same user. On Android there's one user per app. So Firefox can send a signal to itself but not to processes from other apps. And the adb shell user can't send a signal to Firefox. For a debuggable APK you can use run-as but we need a solution that works with non-debuggable apps.

I wonder how else we can trigger profile collection from a script. Maybe we can add an intent for this?

Assignee: nobody → mleclair
Attachment #9501005 - Attachment description: WIP: Bug 1956859: Can stop the profiler through adb → Bug 1956859: Can stop the profiler through adb r=#android-reviewers
Status: NEW → ASSIGNED
Whiteboard: fxdroid,group1
Whiteboard: fxdroid,group1 → [fxdroid],[group1]
Attachment #9501005 - Attachment description: Bug 1956859: Can stop the profiler through adb r=#android-reviewers → Bug 1956859: Enable profiler control via adb and sync profiler state r=#android-reviewers
Pushed by mleclair@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/567626f5db0d https://hg.mozilla.org/integration/autoland/rev/7842287c62c4 Enable profiler control via adb and sync profiler state r=kaya,profiler-reviewers,mstange
Pushed by chorotan@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c4fc918b8a76 https://hg.mozilla.org/integration/autoland/rev/7570aa94982e Revert "Bug 1956859: Enable profiler control via adb and sync profiler state r=kaya,profiler-reviewers,mstange" for causing test apk fenix failure on ProfilerServiceTest.kt

Backed out for causing test apk fenix failure on ProfilerServiceTest.kt

Backout link

Push with failures

Failure log

Flags: needinfo?(mleclair)
Pushed by mleclair@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/67f1ef2c8867 https://hg.mozilla.org/integration/autoland/rev/11d95756ef45 Enable profiler control via adb and sync profiler state r=kaya,profiler-reviewers,mstange
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 148 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: