Skip to content

Allow addons to inject profiles directly into the profiler via the postMessage API #4835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 15, 2023

Conversation

gregtatum
Copy link
Member

@gregtatum gregtatum commented Dec 6, 2023

I'm prototyping an addon to visualize Firefox Translations taskcluster runs, but I need a way to inject my profiles directly into the profiler UI.

My code is still a prototype that I got working locally:
https://github.com/gregtatum/taskcluster-webext

Here is an example injection:
https://github.com/gregtatum/taskcluster-tools/blob/main/extension/profiler_content.js

This is an example profile:
https://share.firefox.dev/3GOQafr

@gregtatum gregtatum requested review from julienw and mstange December 6, 2023 03:22
@gregtatum
Copy link
Member Author

For fun, here is a 10 hour profile. https://share.firefox.dev/3R1NC1S

@gregtatum gregtatum force-pushed the taskcluster-load branch 2 times, most recently from 4a5d76e to 98c05cf Compare December 6, 2023 03:39
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (0ada127) 88.38% compared to head (930d041) 88.39%.

Files Patch % Lines
src/actions/receive-profile.js 95.65% 1 Missing ⚠️
src/components/app/ProfileLoader.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4835   +/-   ##
=======================================
  Coverage   88.38%   88.39%           
=======================================
  Files         301      301           
  Lines       26876    26910   +34     
  Branches     7268     7286   +18     
=======================================
+ Hits        23754    23786   +32     
- Misses       2906     2908    +2     
  Partials      216      216           

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

@mstange
Copy link
Contributor

mstange commented Dec 6, 2023

This is great! I've wanted a way to postMessage profiles into the profiler for a different reason: To make samply work on macOS when Safari is the default browser. Safari doesn't allow network requests from the profiler to localhost (because the profiler is https and localhost is http), so a potential workaround would be to open a localhost page with a button which opens the profiler in a new tab and postMessages the profile into it. The only trouble is the question when to call postMessage - the localhost page can't know when the profiler page is done loading. Oh, and the profiler wouldn't have a way to request symbols. (I suppose the localhost page could send a message channel along with the initial postMessage, as a way to initiate bidirectional communication...)

@gregtatum
Copy link
Member Author

I added a way to poll the page for when it's ready. In an addon it seems like you can just wait a tick and it'll be ready.

@gregtatum
Copy link
Member Author

The codecoverage failure is a false positive as far as I can tell, since most of them are assertions for states that shouldn't happen.

@gregtatum
Copy link
Member Author

I force pushed a new version of the code that removes the mentions of an addon, as this works with a plain webpage (barring any unforeseen CSP issues).

Copy link
Contributor

@julienw julienw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks interesting!

I left a few comments, tell me what you think!
Especially I don't see if/why the change to the action PROFILE_LOADED adding a dataSource property is needed.

r=me with the comments added and the changes to the PROFILE_LOADED action removed (unless we discussed otherwise).

@gregtatum gregtatum merged commit 103fd66 into firefox-devtools:main Dec 15, 2023
@@ -82,6 +82,7 @@ class ProfileLoaderImpl extends PureComponent<Props> {
case 'unpublished':
case 'none':
// nothing to do
/* istanbul ignore next */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, is that one or 2 lines too high? :-)

@julienw julienw mentioned this pull request Dec 18, 2023
julienw added a commit that referenced this pull request Dec 18, 2023
[Greg Tatum] Allow pages to inject profiles directly into the profiler via the postMessage API (Merge PR #4835)
[Carla Severe] Change and move the text about operations in the memory track tooltip (#4848)
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.

3 participants