Support fetching C++ / Rust source code for local Firefox builds into the profiler
Categories
(DevTools :: Performance Tools (Profiler/Timeline), enhancement)
Tracking
(firefox97 fixed)
Tracking | Status | |
---|---|---|
firefox97 | --- | fixed |
People
(Reporter: mstange, Assigned: mstange)
Details
Attachments
(1 file)
The Firefox Profiler is adding a source view. This view displays the C++ / Rust source code for the selected function, and can display per-line timing data. This way, you can know exactly how many samples were encountered in which line of source code.
In order to show the source code, profiler.firefox.com needs to be able to fetch it, somehow.
For official Firefox builds, it can fetch the source code from hg.mozilla.org.
For local Firefox builds on developers' machines, it will need to get the source code from the local disk. profiler.firefox.com already has a privileged communication channel with the browser: The Profiler WebChannel.
Proposal: Extend querySymbolicationApi
with a /source/v1
entry point
I propose the following format:
Path: /source/v1
Request JSON:
{
"debugName": "XUL",
"debugId": "2DC09FF43A4231FC9C34BB3CFE464B2C0",
"moduleOffset": "0x4b8fb3f",
"file": "/Users/mstange/code/mozilla/gfx/wr/webrender/src/renderer/upload.rs"
}
Response JSON:
{
"symbolsLastModified": null,
"sourceLastModified": null,
"file": "/Users/mstange/code/mozilla/gfx/wr/webrender/src/renderer/upload.rs",
"source": "/* This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n\n//! This module contains the convoluted logic that goes into uploading content into\n//! the texture cache's textures [...]"
}
This would do the following:
- Symbolicate address 0x4b8fb3f in the XUL library, the same way as it would in the
/symbolicate/v5
entry point. - Check the filenames for the frames which 0x4b8fb3f symbolicates to.
- If the requested filename is found, read the file and return it.
This way, the API can only be used to access files which are referred to from the debug data of the symbol information, and not arbitrary files.
Trust is propagated as follows:
- The browser trusts WebChannel messages from https://profiler.firefox.com, because that's the path that is set in the
devtools.performance.recording.ui-base-url
preference. - The browser trusts the symbol files that it uses for symbolication. These symbol files come from the following locations: 1. The profile (which the browser just obtained from itself) contains the absolute paths to the symbol files, or 2. The objdir list contains directories which contain trusted symbol files. The objdir list has been configured by the user on about:profiling.
Assignee | ||
Comment 1•2 years ago
•
|
||
I have implemented this entry point in profiler-get-symbols
in issue #24. We can pick this functionality up in Firefox by updating to the new profiler-get-symbols
version.
I've copied the documentation here: https://github.com/mstange/profiler-get-symbols/blob/master/API.md#sourcev1
The /source/v1
URL is now also supported by profiler-symbol-server.
Assignee | ||
Comment 2•2 years ago
|
||
This updates profiler-get-symbols to the latest version.
The new /source/v1 entry point was implemented in
https://github.com/mstange/profiler-get-symbols/commit/edb78205d1eea1788c04c2da3a2bd366bfbc7b5e
Furthermore, this update also picks up a fix for macOS 12 system library symbolication.
Assignee | ||
Comment 3•2 years ago
•
|
||
It's not easy to manually test this at the moment. You need a local Firefox build and then you can execute something like this on the browser console:
var { createLocalSymbolicationService } = ChromeUtils.import("resource://devtools/client/performance-new/symbolication.jsm.js");
var service = createLocalSymbolicationService(Services.profiler.sharedLibraries, []);
JSON.parse(await service.querySymbolicationApi("/source/v1", '{"debugName":"XUL","debugId":"2DC09FF43A4231FC9C34BB3CFE464B2C0","moduleOffset":"0x3c9bc1f","file":"/Users/mstange/code/mozilla/toolkit/xre/nsEmbedFunctions.cpp"}'))
But the debugId
, moduleOffset
and file
will be different for you.
I'm working on a patch for the Firefox profiler which will use this API, which you can then test in a deploy preview.
Pushed by mstange@themasta.com: https://hg.mozilla.org/integration/autoland/rev/a53238a8224c Add the ability to fetch source code from disk to the Profiler WebChannel's querySymbolicationApi method. r=canaltinova
Comment 5•2 years ago
|
||
bugherder |
Description
•