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

Trim reversed stacks to prevent sort check from failing #338

Merged
merged 2 commits into from
Jan 5, 2025

Conversation

bobrik
Copy link
Contributor

@bobrik bobrik commented Dec 21, 2024

If the last line of the stack starts with a space, then the space is used in sorting. However, the space is removed when the line is then fed into the flamegraph, which makes the sorting invalid. This commit adds a trim to the reverse process to fix this.

@jonhoo
Copy link
Owner

jonhoo commented Dec 30, 2024

Thank you! I'm curious though — how can this happen in practice? Like, what causes a function to have a leading space in its name? How do you end up with the file that you included in this PR?

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.38%. Comparing base (306edee) to head (40a4ba9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #338   +/-   ##
=======================================
  Coverage   91.37%   91.38%           
=======================================
  Files          20       20           
  Lines        4440     4444    +4     
=======================================
+ Hits         4057     4061    +4     
  Misses        383      383           

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

@bobrik
Copy link
Contributor Author

bobrik commented Dec 30, 2024

I think some symbols can have ;:

0000000000a759a0 l     F .text	0000000000000008              core::array::<impl core::default::Default for [T; _]>::default::h67c9877e6f2a615c
0000000000a759b0 l     F .text	0000000000000008              core::array::<impl core::default::Default for [T; _]>::default::h8cc48dfe0d9bff78
0000000000a75800 l     F .text	0000000000000097              core::array::<impl core::fmt::Debug for [T; N]>::fmt::h24e996bfa7154ca1
0000000000a759d0 l     F .text	0000000000000008              core::array::<impl core::default::Default for [T; _]>::default::he4723b7c57f6b881
0000000000a00af0 g     F .text	0000000000000074              <[u8; 19] as phf_shared::FmtConst>::fmt_const::hb6b803208e5640c0
0000000000a002f0 g     F .text	0000000000000074              <[u8; 3] as phf_shared::FmtConst>::fmt_const::h524dac4335e1334b
0000000000a00370 g     F .text	0000000000000074              <[u8; 4] as phf_shared::FmtConst>::fmt_const::h117038a50e8f7ca3
0000000000a009f0 g     F .text	0000000000000074              <[u8; 17] as phf_shared::FmtConst>::fmt_const::h4e993ac5b3e99e7c

Since the stack frame separator in collapsed files is ;, they split into two, with the second one having a space before the symbol name.

In our script we have:

perf script --no-demangle -i perf.data | ... | c++filt | /usr/bin/inferno-collapse-perf --all | ...  > perf.stacks.collapsed

Arguably, these collapsed stacks are somewhat incorrect, but having a somewhat incorrect flamegraph beats having none.

@jonhoo
Copy link
Owner

jonhoo commented Dec 31, 2024

Oh iiiinteresting. That is indeed pretty broken. I wonder if @brendangregg has thought about how the collapse format for flamegraph more broadly should handle symbols with ; in them?

In the meantime, would you mind making the test collapse hold lines more along the lines of what you'd realistically get with a Rust type like [u8; 3]? The current one feels hand-edited and isn't intuitively obvious how it can happen (which is what prompted this discussion).

If the last line of the stack starts with a space, then the space is used in sorting.
However, the space is removed when the line is then fed into the flamegraph, which
makes the sorting invalid. This commit adds a trim to the reverse process to fix this.
@bobrik bobrik force-pushed the ivan/trim-reverse branch from 183b090 to 63eed27 Compare January 3, 2025 06:49
@bobrik
Copy link
Contributor Author

bobrik commented Jan 3, 2025

Oh iiiinteresting. That is indeed pretty broken. I wonder if @brendangregg has thought about how the collapse format for flamegraph more broadly should handle symbols with ; in them?

Internally we use when we do some pre-processing to prepend cgroup hierarchy to the stack trace. There's little chance of it being in the raw data.

In the meantime, would you mind making the test collapse hold lines more along the lines of what you'd realistically get with a Rust type like [u8; 3]? The current one feels hand-edited and isn't intuitively obvious how it can happen (which is what prompted this discussion).

Good idea, updated with a realistic name.

jonhoo
jonhoo previously approved these changes Jan 5, 2025
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.

Thanks!

src/flamegraph/mod.rs Show resolved Hide resolved
@jonhoo jonhoo merged commit 41de77c into jonhoo:main Jan 5, 2025
17 checks passed
jonhoo added a commit that referenced this pull request Jan 5, 2025
@jonhoo
Copy link
Owner

jonhoo commented Jan 5, 2025

Releasing in #339

jonhoo added a commit that referenced this pull request Jan 5, 2025
@bobrik bobrik deleted the ivan/trim-reverse branch January 6, 2025 21:41
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