lpereira opened PR #8639 from lpereira:show-func-names-in-explore
to bytecodealliance:main
:
Another one in the "let's make debugging a bit easier": show function names in the "explore" tool. (There's a bit of code repetition here to clean up the names, but it's slightly different when we're considering HTML output, so I think that's OK.)
Here's how it works on my machine:
<img width="1023" alt="image" src="https://github.com/bytecodealliance/wasmtime/assets/15001/9bb4b160-1bb9-44d3-a59f-615694f24a99">
lpereira requested pchickey for a review on PR #8639.
lpereira requested wasmtime-core-reviewers for a review on PR #8639.
lpereira updated PR #8639.
jameysharp commented on PR #8639:
Very nice!
This can be further improved by demangling the function names first. For some example code that does that, see: https://github.com/bytecodealliance/wasmtime/blob/54e53cc77a29c8e4eb819333d81ef4158685690a/crates/wasmtime/src/runtime/profiling.rs#L194-L200
I don't think we need to be nearly so careful about sanitizing function names in this setting. These strings are first serialized to JSON, and that should ensure that any string we provide is valid JSON. The JSON string is then used in a
<script>
tag; we might need to escape the JSON for embedding in HTML, but<script>
tags are implicitly treated as CDATA in HTML5, right? Finally, the strings embedded in the JSON are spliced into the DOM usingtextContent
, so they don't need to be escaped at that point.As a result I think we should just give the user whatever they provided, preferably after demangling.
fitzgen submitted PR review:
Thanks! One nitpick below before we merge this.
fitzgen submitted PR review:
Thanks! One nitpick below before we merge this.
fitzgen created PR review comment:
We can avoid looking up the function index via instruction offset since
function_locations
should already return the functions in order:self.function_locations().enumerate().map(|(idx, (offset, len))| { let idx = u32::try_from(idx).unwrap();
fitzgen commented on PR #8639:
Agreed demangling would be great -- also fine with deferring that to a follow up PR.
lpereira requested wasmtime-default-reviewers for a review on PR #8639.
lpereira updated PR #8639.
lpereira updated PR #8639.
lpereira commented on PR #8639:
Pushed the requested changes. Current output here is now this one (notice the pop-up showing the unmangled name):
<img width="656" alt="image" src="https://github.com/bytecodealliance/wasmtime/assets/15001/53a2838d-71d2-452a-a8f1-c47fc7cb334b">
lpereira edited a comment on PR #8639:
Pushed the requested changes. Current output here is now this one (notice the pop-up showing the mangled name):
<img width="656" alt="image" src="https://github.com/bytecodealliance/wasmtime/assets/15001/53a2838d-71d2-452a-a8f1-c47fc7cb334b">
lpereira updated PR #8639.
jameysharp commented on PR #8639:
Ooh, the pop-up is a nice touch. There's a lot more that could be done with
wasmtime explore
eventually.I'd be happy to review this next week, or just as happy if you want to approve it @fitzgen.
lpereira updated PR #8639.
fitzgen submitted PR review:
Thanks! Really excited to get this, and your other PR, in
wasmtime explore
.I have a few comments and suggestions below that we should address before merging this however. I'll also hold off on reviewing the other PR until after this one merges.
Let me know if anything I said isn't clear or something like that. Thanks again!
fitzgen created PR review comment:
Let's revert this change; it just introduces unnecessary parens.
fitzgen submitted PR review:
Thanks! Really excited to get this, and your other PR, in
wasmtime explore
.I have a few comments and suggestions below that we should address before merging this however. I'll also hold off on reviewing the other PR until after this one merges.
Let me know if anything I said isn't clear or something like that. Thanks again!
fitzgen created PR review comment:
Ditto.
fitzgen created PR review comment:
Same thing here. AFAICT, this just changes indentation and adds unnecessary parens around the argument. This illustrates why it is preferrable to avoid stylistic changes in functional PRs: it makes it harder for reviewers to determine if there are any functional changes involved in a particular diff region or not.
fitzgen created PR review comment:
AFAICT, this is the only non-stylistic change to the whole JS file? Can we remove all the other changes to this file?
fitzgen created PR review comment:
Ditto. Let's not change code style when making unrelated changes.
fitzgen created PR review comment:
Ditto.
fitzgen created PR review comment:
I think it would be better to let
demangled_name
be anOption<String>
rather than making a clone ofname
and then have the JS choose the demangled name when available and fall back to the plain name.
fitzgen created PR review comment:
Instead of stringifying the name with the index here, and then forcing the consumer of this API in
crates/explore/src/lib.rs
to parse the name out from stringified name out, can we just give the caller the various components before stringification? That is, return an iterator that yields items of type( u32, // wasm function index Option<String>, // name, if available usize, // text section offset usize, // length of function in text section )
I think we could also update the existing
function_locations
method, and perhaps rename it, rather than defining a whole new method, since that method exists to basically enablewasmtime-explore
.
lpereira submitted PR review.
lpereira created PR review comment:
Alright.
lpereira created PR review comment:
OK.
lpereira submitted PR review.
lpereira submitted PR review.
lpereira created PR review comment:
Sure. It was the auto-formatting tool that my editor uses. I'll have to force-push to fix this easily.
lpereira submitted PR review.
lpereira created PR review comment:
OK.
lpereira updated PR #8639.
lpereira commented on PR #8639:
Alright, force-pushed (sorry!) due to the formatting changes, but it should be a whole lot clearer now. I'll rebase the other PR once this one lands.
lpereira updated PR #8639.
fitzgen submitted PR review:
Thanks! Looks just about ready to merge, couple tiny things still to go first.
fitzgen submitted PR review:
Thanks! Looks just about ready to merge, couple tiny things still to go first.
fitzgen created PR review comment:
I think this condition is backwards, we either want to
!==
or we want to swap the arms.
fitzgen created PR review comment:
I think
function_loactions
is only used by this method, so we can we remove it or make it non-pub
, as I suggested previously?Also I like the named struct with named fields, that's indeed better than a large-ish tuple, but the docs here should match that now.
And since this is really more than just function locations and names (it also has an index, for example) maybe we should call this method
function_metadatas
and the structFunctionMetadata
? Feel free to take-or-leave this last one...
lpereira updated PR #8639.
lpereira submitted PR review.
lpereira created PR review comment:
Good catch, let me clean this up.
lpereira submitted PR review.
lpereira created PR review comment:
Oops!
lpereira commented on PR #8639:
Alright, @fitzgen, pushed a new revision that should address your comments.
fitzgen submitted PR review:
Looks great, thanks! And thanks for your patience with review :)
fitzgen merged PR #8639.
Last updated: Nov 22 2024 at 17:03 UTC