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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ where
}
stack.push(' ');
stack.push_str(&line[samples_idx..]);
// Trim to handle the case where functions names internally contain `;`.
// This can happen, for example, with types like `[u8; 8]` in Rust.
// See https://github.com/jonhoo/inferno/pull/338.
let stack = stack.trim();
jonhoo marked this conversation as resolved.
Show resolved Hide resolved
reversed.push(&stack);
}
let mut reversed: Vec<&str> = reversed.iter().collect();
Expand Down
167 changes: 167 additions & 0 deletions tests/data/flamegraph/fractional-samples/with-space-reversed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions tests/data/flamegraph/fractional-samples/with-space.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cksum;_start;__libc_start_main;main;cksum 31.23
cksum;cksum 6.1
cksum;cksum;__GI___fread_unlocked;_IO_file_xsgetn;_IO_file_read;entry_SYSCALL_64_fastpath_[k];sys_read_[k];vfs_read_[k];__vfs_read_[k];ext4_file_read_iter_[k] 1.4
cksum;main;core::array::<impl core::default::Default for [T; _]>::default::h67c9877e6f2a615c 19.0
noploop;[unknown] 2.567
noploop;main 274.321
12 changes: 12 additions & 0 deletions tests/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,18 @@ fn flamegraph_reversed_stack_ordering_with_fractional_samples() {
test_flamegraph(input_file, expected_result_file, options).unwrap();
}

#[test]
fn flamegraph_reversed_stack_ordering_with_space() {
let input_file = "./tests/data/flamegraph/fractional-samples/with-space.txt";
let expected_result_file = "./tests/data/flamegraph/fractional-samples/with-space-reversed.svg";

let mut options = flamegraph::Options::default();
options.hash = true;
options.reverse_stack_order = true;

test_flamegraph(input_file, expected_result_file, options).unwrap();
}

#[test]
fn flamegraph_should_warn_about_no_sort_when_reversing_stack_ordering() {
let mut options = flamegraph::Options::default();
Expand Down
Loading