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

Add colour palette for python traces #240

Merged
merged 16 commits into from
Oct 16, 2022
Merged

Conversation

mrob95
Copy link
Contributor

@mrob95 mrob95 commented May 4, 2022

Adds a new colour palette for python. Aiming to distinguish four cases:

  • User python code
  • python code imported from an installed package
  • python code imported from the standard library
  • native calls

I've tested it out in a few scenarios and it definitely makes the output more understandable at a glance:
image
image

@mrob95 mrob95 changed the title Add colour palette for python traces WIP: Add colour palette for python traces May 6, 2022
@mrob95
Copy link
Contributor Author

mrob95 commented May 6, 2022

I have mainly been testing this with the austin profiler.

@benfred Do you think this could be adapted to work with py-spy as well? It looks to me like py-spy removes a lot of the info which would allow us to tell the difference between user code and library code, but it would be great if we could make it work.

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

This looks great! I left some inline notes.

use crate::flamegraph::color::BasicPalette;

pub fn resolve(name: &str) -> BasicPalette {
if name.starts_with("native@") { // austin-specific format for native calls
Copy link
Owner

Choose a reason for hiding this comment

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

I worry about encoding generator-specific detection into here. Is there no other way to detect native calls that isn't austin-specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it's a bit nasty to be doing profiler specific checks here. Unfortunately since getting profiles which combine Python stack traces with native calls is pretty involved, we are at the mercy of how the profiler decides to format things.

As far as I know the only profilers which support native calls are austin and py-spy, so if we can support both of those then maybe it's fine.

All austin native calls are prefixed with native@, e.g.

native@7f8b5cbb69a6:ufunc_generic_fastcall:12022

py-spy looks like this:

ufunc_generic_fastcall (numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so)

I've tagged the author of py-spy in this PR, it would be good to get his input on the best way of parsing this. We could easily do a check for .so or .dll, but I suspect that if the native extension is built with debug symbols then we would get a reference to a source file, which could have any extension.

Alternatively, I'm happy to remove this branch and ignore native calls for now. For me at least it is very rare to need to go down into native calls when profiling Python.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm really torn here. I'd love to hear from the py-spy maintainer too, but I think given the state of the landscape I'm then okay with putting in place checks specifically for austin/py-spy's markers for native calls.

src/flamegraph/color/palettes.rs Outdated Show resolved Hide resolved
src/flamegraph/color/palettes.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 7, 2022

Codecov Report

Base: 90.21% // Head: 90.33% // Increases project coverage by +0.11% 🎉

Coverage data is based on head (08a4194) compared to base (8c0a28c).
Patch coverage: 98.41% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
+ Coverage   90.21%   90.33%   +0.11%     
==========================================
  Files          19       19              
  Lines        4179     4241      +62     
==========================================
+ Hits         3770     3831      +61     
- Misses        409      410       +1     
Impacted Files Coverage Δ
src/flamegraph/color/mod.rs 86.56% <50.00%> (-0.30%) ⬇️
src/flamegraph/color/palettes.rs 99.04% <100.00%> (+0.12%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mrob95 mrob95 force-pushed the mr-python-colours branch from d154fd5 to 9c9d855 Compare May 8, 2022 18:49
src/flamegraph/color/palettes.rs Outdated Show resolved Hide resolved
src/flamegraph/color/palettes.rs Show resolved Hide resolved
@mrob95 mrob95 force-pushed the mr-python-colours branch from 841c7f0 to 90a1c7f Compare May 23, 2022 20:47
@jonhoo
Copy link
Owner

jonhoo commented Oct 15, 2022

Was it intentional that you also made changes to the flamegraph submodule?

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

A few more thoughts

src/bin/flamegraph.rs Outdated Show resolved Hide resolved
src/flamegraph/color/palettes.rs Outdated Show resolved Hide resolved
src/flamegraph/color/palettes.rs Outdated Show resolved Hide resolved
src/flamegraph/color/palettes.rs Outdated Show resolved Hide resolved
src/flamegraph/color/palettes.rs Outdated Show resolved Hide resolved
@mrob95
Copy link
Contributor Author

mrob95 commented Oct 15, 2022

Was it intentional that you also made changes to the flamegraph submodule?

Whoops, nope. Reverted that. To be honest I had forgotten about this PR!

@jonhoo
Copy link
Owner

jonhoo commented Oct 15, 2022

Heh, yeah, sorry, I've been falling really behind on OSS stuff!

@mrob95 mrob95 force-pushed the mr-python-colours branch from 293252e to 3e4048f Compare October 15, 2022 20:13
@mrob95 mrob95 force-pushed the mr-python-colours branch from 3e4048f to ed6ab63 Compare October 15, 2022 20:18
@mrob95
Copy link
Contributor Author

mrob95 commented Oct 15, 2022

BTW, you may be glad to hear that inferno helped us track down and report an O(n^2) in boto3 :)

@mrob95 mrob95 changed the title WIP: Add colour palette for python traces Add colour palette for python traces Oct 15, 2022
Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

Also, that's so cool to hear :D

@jonhoo jonhoo merged commit 7d054ac into jonhoo:main Oct 16, 2022
@jonhoo
Copy link
Owner

jonhoo commented Oct 16, 2022

Published in 0.11.11 🎉

jedbrown added a commit to jedbrown/flamegraph that referenced this pull request Jun 26, 2023
As a side-effect of avoiding duplication, this adds the "python"
variant, which was added to inferno:

jonhoo/inferno#240

This commit does change the order shown in `--help`.
djc pushed a commit to flamegraph-rs/flamegraph that referenced this pull request Jun 27, 2023
As a side-effect of avoiding duplication, this adds the "python"
variant, which was added to inferno:

jonhoo/inferno#240

This commit does change the order shown in `--help`.
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.

2 participants