Add profiler-cli for querying profiles#5963
Add profiler-cli for querying profiles#5963canova wants to merge 8 commits intofirefox-devtools:mainfrom
profiler-cli for querying profiles#5963Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5963 +/- ##
==========================================
- Coverage 85.33% 83.73% -1.61%
==========================================
Files 323 327 +4
Lines 32262 34266 +2004
Branches 8895 9484 +589
==========================================
+ Hits 27532 28692 +1160
- Misses 4298 5146 +848
+ Partials 432 428 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This is ready for review! |
Was too fast 😓 |
90b59aa to
11d68ca
Compare
| 'function-include filter requires a non-empty filter string.' | ||
| ); | ||
| } | ||
| const funcIndexes = new Set(filter.split(',').map(Number)); |
There was a problem hiding this comment.
surprised we have a comma-separated string of numbers here - we have proper arrays for things like merge-call-node, why not here?
There was a problem hiding this comment.
It's mainly because the filter-samples transform accepts a string as a filter, and the idea was to make it more generic so it can accept a bunch of filterType as an argument. But it kinda restricts us in this case:
profiler/src/types/transforms.ts
Lines 371 to 381 in 8c0afb1
But that's not necessarily a restriction that we have to follow, we can always change it something like this instead:
'filter-samples':
| { readonly type: 'filter-samples'; readonly filterType: 'marker-search' | 'outside-marker'; readonly filter: string }
| { readonly type: 'filter-samples'; readonly filterType: 'function-include' | 'stack-prefix'; readonly funcIndexes: number[] }
| { readonly type: 'filter-samples'; readonly filterType: 'stack-suffix'; readonly funcIndex: number }I don't know if we should do it here in a follow-up as it wouldn't need any upgrader, let me know what you think.
| } | ||
| } | ||
| } | ||
| // Memoize bottom-up: does this stack contain any frame for funcIndex? |
There was a problem hiding this comment.
I think this function is computing a bunch of things that we already have code to compute. Haven't reviewed in detail yet.
There was a problem hiding this comment.
Yeah, I reviewed that one more time and improved it. Put it as a separate commit so it's easier to review: d1ebfbb
| } | ||
| } | ||
|
|
||
| // Assembly annotation |
There was a problem hiding this comment.
We don't really have enough information to make Assembly annotation work properly. We only have the mapping between source line and assembly instruction for instructions that were sampled. The symbolication API doesn't give us this information for the rest of the instructions yet.
There was a problem hiding this comment.
Yeah, but I wanted to do exactly what assembly view in the browser does, and I believe this behavior matches it. When I look at the assembly view in the browser I only see a single line in there with all the sample information summed up. And I use the same selectors to fetch this information. So I think it makes sense to keep them in sync. WDYT?
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| export type Slice = { |
There was a problem hiding this comment.
This whole file could use some comments. I wrote this code but I don't like it very much - and that includes the name! It's supposed to make a tree representation of the information you'd get from looking at a visual CPU usage graph, by applying a threshold operation to the entire time series, and then gradually increasing the threshold and seeing where "above water level" things split into separate islands. I suppose we can land it without comments and then I'll make a PR to add them
There was a problem hiding this comment.
Ah yeah, that's a good point. I kept it as is for now.
Previously only filtering by marker was possible. This patch adds some more filtering options that will only be used in the cli for now. They are not exposed in the profiler web frontend.
It will be used later by the profiler-cli.
|
Thanks for the first look @mstange! I merged the "idle filtering" PR and rebased this PR on top of the recent main, so you'll see 2 less commits here. |
Fixes #5953 (we can move follow-ups that we have there once this lands).
This PR is the rebased, squashed and split version of #5663. I also did some reviews on top and updated the code further to fix some issues.
(This PR currently depends on #5968. Please review that one first)
It adds a new command-line tool,
profiler-cli, for querying Firefox Profiler profiles from a terminal. The CLI is published as a separate npm package (@firefox-devtools/profiler-cli, alpha) and is the intended entry point for most usersWhat's in here:
New
src/profile-query/library: ReusableProfileQuerierclass that loads a profile (file,profiler.firefox.comURL, or share link) and exposes methods for profile/thread info, samples (top-down / bottom-up / hot functions), markers, functions, zoom (view range) stack, and per-thread filter stack. All query methods return structured result objects; formatting lives in the CLI layer.New
profiler-cli/package: Node CLI (profiler-cli, short aliaspq) with a persistent daemon architecture so subsequent commands against the same profile are fast. Sessions are stored under~/.profiler-cli/.How to do manual testing locally:
yarn installandyarn build-profiler-clialias profiler-cli="node $(pwd)/profiler-cli/dist/profiler-cli.js" && alias pq="node $(pwd)/profiler-cli/dist/profiler-cli.js"pqandprofiler-cliin this terminal session.