Skip to content
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

Profile.print: color Base/Core & packages. Make paths clickable #55335

Merged
merged 14 commits into from
Sep 4, 2024

Conversation

IanButterworth
Copy link
Sponsor Member

@IanButterworth IanButterworth commented Aug 1, 2024

Updated

This PR

Screenshot 2024-09-02 at 1 47 23 PM

master

Screenshot 2024-09-02 at 1 49 42 PM

Todo:

  • Maybe drop the @ prefix when coloring it, given it's obviously special when colored If someone copy-pasted the profile into an issue this would make it confusing.
  • Figure out why Profile.print(format=:flat) is truncating before the terminal width is used up
  • Make filepaths terminal links (even if they're truncated)

@IanButterworth IanButterworth changed the title Profile: color Base/Core & stdlibs in Profile.print() Profile: color Base/Core & packages in Profile.print() Aug 1, 2024
@KristofferC
Copy link
Sponsor Member

Orthogonal but the @Module syntax prevents you from Ctrl-clicking them in e.g. VSCode to take you to the line but if we made them terminal links that functionality would probably be restored.

@tecosaur
Copy link
Contributor

tecosaur commented Aug 2, 2024

if we made them terminal links

FYI I've already got code for that in #51816.

@IanButterworth
Copy link
Sponsor Member Author

I guess the truncation of paths also breaks autolinks. I'll leave the link fixing for after that PR lands.

@tecosaur
Copy link
Contributor

tecosaur commented Aug 2, 2024

IMO the commit that adds uripath could be landed separately, I'm sort of waiting for the StyledStrings/Base printing type piracy to get a bit closer to resolved before pushing that PR again.

Happy to make that PR if that would be helpful, or we can just wait.

@IanButterworth
Copy link
Sponsor Member Author

Sounds good. Doesn't need to hold this up though.

@tecosaur would you mind reviewing for whether there's an easy way to implement this better with annotated strings stuff? If it requires an overhaul then maybe that could be a following PR.

@IanButterworth IanButterworth added the needs news A NEWS entry is required for this change label Aug 2, 2024
stdlib/Profile/src/Profile.jl Outdated Show resolved Hide resolved
stdlib/Profile/src/Profile.jl Outdated Show resolved Hide resolved
@IanButterworth IanButterworth force-pushed the ib/profile_color branch 2 times, most recently from 0963309 to ee5f183 Compare August 11, 2024 17:40
@IanButterworth IanButterworth changed the title Profile: color Base/Core & packages in Profile.print() Profile.print: color Base/Core & packages. Make paths clickable Sep 2, 2024
@IanButterworth
Copy link
Sponsor Member Author

IanButterworth commented Sep 2, 2024

File paths are now clickable in any terminal that supports it, even if they are truncated. See example up top.

I opted to use IDE-specific formats over a generic URI because VSCode doesn't recognize a linenum ending on a generic URI.

@IanButterworth IanButterworth removed the needs news A NEWS entry is required for this change label Sep 2, 2024
@gdalle
Copy link
Contributor

gdalle commented Sep 2, 2024

Looks much more usable! I wonder if coloring the whole file path instead of just the module would make things even clearer? It has the added benefit of nicely separating the function call

@IanButterworth
Copy link
Sponsor Member Author

IanButterworth commented Sep 2, 2024

@gdalle interesting idea..

Screenshot 2024-09-02 at 7 45 27 AM

The underline styling of links in iTerm2 makes it a little more busy than it needs to be, but I think its clearer


iTerm2 does have an option to disable the underlining
Screenshot 2024-09-03 at 3 07 46 PM

And it still highlights/underlines when you hover over with cmd pressed

Screenshot 2024-09-03 at 3 09 31 PM

@IanButterworth
Copy link
Sponsor Member Author

I think the coloring makes the trailing ; superfluous now.

@lgoettgens
Copy link
Contributor

With some of the colors, I find it incredibly hard to read what's really written there. For the modules, this is fine, but for the paths this could be avoided.

@gbaraldi
Copy link
Member

gbaraldi commented Sep 2, 2024

One idea (which might be bad) would be to only colour the stacktraces that are heavier? Something like at least 5% of the samples

@IanButterworth
Copy link
Sponsor Member Author

Maybe bolding lines that have numbers on the far left would help.

@IanButterworth
Copy link
Sponsor Member Author

Yeah I think that helps

Screenshot 2024-09-02 at 1 29 03 PM

@IanButterworth
Copy link
Sponsor Member Author

I think the ; after the path is unnecessary and looks cleaner with just a double space.

Screenshot 2024-09-02 at 1 47 23 PM

@IanButterworth IanButterworth added the merge me PR is reviewed. Merge when all tests are passing label Sep 3, 2024
@IanButterworth
Copy link
Sponsor Member Author

I'm marking this for merge as I think the formatting changes have support, and the clickable links part will need some testing in the wild

@IanButterworth IanButterworth merged commit 48b40ac into JuliaLang:master Sep 4, 2024
7 checks passed
@IanButterworth IanButterworth deleted the ib/profile_color branch September 4, 2024 00:16
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label Sep 11, 2024
KristofferC pushed a commit that referenced this pull request Sep 12, 2024
Updated
## This PR
![Screenshot 2024-09-02 at 1 47
23 PM](https://github.com/user-attachments/assets/1264e623-70b2-462a-a595-1db2985caf64)


## master
![Screenshot 2024-09-02 at 1 49
42 PM](https://github.com/user-attachments/assets/14d62fe1-c317-4df5-86e9-7c555f9ab6f1)



Todo:
- [ ] ~Maybe drop the `@` prefix when coloring it, given it's obviously
special when colored~ If someone copy-pasted the profile into an issue
this would make it confusing.
- [ ] Figure out why `Profile.print(format=:flat)` is truncating before
the terminal width is used up
- [x] Make filepaths terminal links (even if they're truncated)
kshyatt pushed a commit that referenced this pull request Sep 12, 2024
Updated
## This PR
![Screenshot 2024-09-02 at 1 47
23 PM](https://github.com/user-attachments/assets/1264e623-70b2-462a-a595-1db2985caf64)


## master
![Screenshot 2024-09-02 at 1 49
42 PM](https://github.com/user-attachments/assets/14d62fe1-c317-4df5-86e9-7c555f9ab6f1)



Todo:
- [ ] ~Maybe drop the `@` prefix when coloring it, given it's obviously
special when colored~ If someone copy-pasted the profile into an issue
this would make it confusing.
- [ ] Figure out why `Profile.print(format=:flat)` is truncating before
the terminal width is used up
- [x] Make filepaths terminal links (even if they're truncated)
@@ -788,9 +794,34 @@ function flat(io::IO, data::Vector{UInt64}, lidict::Union{LineInfoDict, LineInfo
return false
end

# make a terminal-clickable link to the file and linenum.
# Similar to `define_default_editors` in `Base.Filesystem` but for creating URIs not commands
function editor_link(path::String, linenum::Int)
Copy link
Contributor

Choose a reason for hiding this comment

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

At a glance it looks like path is directly interpolated? This looks a little dodgy to me, what about a path like /tmp/?file=redherring&line=42/file.jl? Will that become say idea:https://open?file=/tmp/?file=redherring&line=42/file.jl&line=1

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

That path isn't a file path? and especially not something that the profiler could return, as far as I understand...?
Though escaping the path generally seems like a good idea.

Also it'd be great to have #55454 finished to use in this function for the generic case.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Ah I see what you're saying.. a dir named ?file=redherring&line=42. Ok

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it'd be great to have #55454 finished to use in this function for the generic case.

From my perspective, that PR is good to go, just awaiting further comment or merging.

IanButterworth pushed a commit that referenced this pull request Sep 24, 2024
In a few places across Base and the stdlib, we emit paths that we like
people to be able to click on in their terminal and editor. Up to this
point, we have relied on auto-filepath detection, but this does not
allow for alternative link text, such as contracted paths.

Doing so (via OSC 8 terminal links for example) requires filepath URI
encoding.

This functionality was previously part of a PR modifying stacktrace
printing (#51816), but after that became held up for unrelated reasons
and another PR appeared that would benefit from this utility (#55335),
I've split out this functionality so it can be used before the
stacktrace printing PR is resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants