Skip to content

Commit

Permalink
Add support for combined stack + ustack DTrace collapse (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter authored Aug 3, 2024
1 parent 1c60840 commit 0c0213b
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/collapse/dtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl CollapsePrivate for Folder {
}
}
}
true
matches!(state, State::EndOfLine)
}

fn clone_and_reset_stack_context(&self) -> Self {
Expand Down Expand Up @@ -492,6 +492,51 @@ mod tests {
<Folder as Collapse>::collapse(&mut folder, &bytes[..], io::sink())
}

#[test]
fn test_collapse_dtrace_would_end_stack() {
let mut folder = Folder::default();
assert!(!folder.would_end_stack(b"function_name"));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" "));
assert!(!folder.would_end_stack(b""));
assert!(!folder.would_end_stack(b""));
assert!(!folder.would_end_stack(b" function_name "));
assert!(folder.would_end_stack(b" 256 "));

assert!(!folder.would_end_stack(b" "));
assert!(!folder.would_end_stack(b" "));
assert!(!folder.would_end_stack(b""));
assert!(!folder.would_end_stack(b"function_name"));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" "));
assert!(folder.would_end_stack(b" 12 "));

assert!(!folder.would_end_stack(b"function_name"));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(folder.would_end_stack(b" 3 "));

assert!(!folder.would_end_stack(b"function_name"));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" 5function_name "));
assert!(!folder.would_end_stack(b" "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(folder.would_end_stack(b" 3 "));

assert!(!folder.would_end_stack(b"function_name"));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" 5424 f"));
assert!(!folder.would_end_stack(b" "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(!folder.would_end_stack(b" function_name "));
assert!(folder.would_end_stack(b" 3 "));
}

/// Varies the nstacks_per_job parameter and outputs the 10 fastests configurations by file.
///
/// Command: `cargo test bench_nstacks_dtrace --release -- --ignored --nocapture`
Expand Down
8 changes: 8 additions & 0 deletions tests/collapse-dtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ fn collapse_dtrace_compare_to_flamegraph_bug() {
test_collapse_dtrace(test_file, result_file, options).unwrap()
}

#[test]
fn collapse_dtrace_stack_ustack() {
let test_file = "./tests/data/collapse-dtrace/stack-ustack.txt";
let result_file = "./tests/data/collapse-dtrace/results/stack-ustack.txt";

test_collapse_dtrace(test_file, result_file, Options::default()).unwrap()
}

#[test]
fn collapse_dtrace_should_log_warning_for_only_header_lines() {
test_collapse_dtrace_logs(
Expand Down
4 changes: 4 additions & 0 deletions tests/data/collapse-dtrace/results/stack-ustack.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
libc.so.1`_lwp_start;libc.so.1`_thrp_setup;cru-ds-fdsync-v1`std::sys::unix::thread::Thread::new::thread_start;cru-ds-fdsync-v1`core::ops::function::FnOnce::call_once{{vtable.shim}};cru-ds-fdsync-v1`std::sys_common::backtrace::__rust_begin_short_backtrace;cru-ds-fdsync-v1`rayon_core::registry::ThreadBuilder::run;cru-ds-fdsync-v1`rayon_core::registry::WorkerThread::wait_until_cold;cru-ds-fdsync-v1`<rayon_core::job::HeapJob<BODY> as rayon_core::job::Job>::execute;cru-ds-fdsync-v1`std::panicking::try;cru-ds-fdsync-v1`crucible_downstairs::extent::Extent::flush;cru-ds-fdsync-v1`<crucible_downstairs::extent_inner_raw::RawInner as crucible_downstairs::extent::ExtentInner>::flush;cru-ds-fdsync-v1`std::fs::File::sync_all;libc.so.1`__fdsync;unix`sys_syscall;genunix`fdsync;genunix`fop_fsync;zfs`zfs_fsync;zfs`zil_commit;zfs`zil_commit_impl;zfs`zil_commit_itx_assign;zfs`zil_itx_assign;zfs`dmu_objset_ds 1
libc.so.1`_lwp_start;libc.so.1`_thrp_setup;cru-ds-fdsync-v1`std::sys::unix::thread::Thread::new::thread_start;cru-ds-fdsync-v1`core::ops::function::FnOnce::call_once{{vtable.shim}};cru-ds-fdsync-v1`std::sys_common::backtrace::__rust_begin_short_backtrace;cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness;cru-ds-fdsync-v1`tokio::runtime::task::core::Core;cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::run;cru-ds-fdsync-v1`tokio::runtime::context::runtime::enter_runtime;cru-ds-fdsync-v1`tokio::runtime::context::scoped::Scoped;cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run;cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run_task;cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness;cru-ds-fdsync-v1`tokio::runtime::task::core::Core;cru-ds-fdsync-v1`crucible_downstairs::Downstairs::run::_{{closure}};cru-ds-fdsync-v1`crucible_downstairs::ActiveConnection::do_work_if_ready::{{closure}};cru-ds-fdsync-v1`crucible_downstairs::ActiveConnection::do_work::{{closure}};cru-ds-fdsync-v1`crucible_downstairs::region::Region::region_write;cru-ds-fdsync-v1`crucible_downstairs::extent::Extent::write;cru-ds-fdsync-v1`<crucible_downstairs::extent_inner_raw::RawInner as crucible_downstairs::extent::ExtentInner>::write;libc.so.1`__pwrite;unix`sys_syscall;genunix`pwrite;genunix`fop_write;zfs`zfs_write;zfs`dmu_tx_assign;zfs`dmu_tx_try_assign;zfs`dsl_dir_tempreserve_space;zfs`arc_memory_throttle 1
libc.so.1`_lwp_start;libc.so.1`_thrp_setup;cru-ds-fdsync-v1`std::sys::unix::thread::Thread::new::thread_start;cru-ds-fdsync-v1`core::ops::function::FnOnce::call_once{{vtable.shim}};cru-ds-fdsync-v1`std::sys_common::backtrace::__rust_begin_short_backtrace;cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness;cru-ds-fdsync-v1`tokio::runtime::task::core::Core;cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::run;cru-ds-fdsync-v1`tokio::runtime::context::runtime::enter_runtime;cru-ds-fdsync-v1`tokio::runtime::context::scoped::Scoped;cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run;cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run_task;cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness;cru-ds-fdsync-v1`tokio::runtime::task::core::Core;cru-ds-fdsync-v1`crucible_downstairs::recv_task::_{{closure}};cru-ds-fdsync-v1`<tokio::future::poll_fn::PollFn;cru-ds-fdsync-v1`<tokio_util::codec::framed_impl::FramedImpl 1
unix`thread_start;genunix`taskq_thread;zfs`zio_execute;zfs`metaslab_group_alloc_verify 1
87 changes: 87 additions & 0 deletions tests/data/collapse-dtrace/stack-ustack.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
CPU ID FUNCTION:NAME
30 76446 :tick-10ms



cru-ds-fdsync-v1`<tokio_util::codec::framed_impl::FramedImpl<T,U,R> as futures_core::stream::Stream>::poll_next::h375c4bf72398a9c9+0x451
cru-ds-fdsync-v1`<tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::hdb622d175ae42c67+0x376
cru-ds-fdsync-v1`crucible_downstairs::recv_task::_$u7b$$u7b$closure$u7d$$u7d$::h2313d0ca35c97b46 (.llvm.9599067906520872268)+0x1e8
cru-ds-fdsync-v1`tokio::runtime::task::core::Core<T,S>::poll::ha1b200ead37ecb81+0x3e
cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness<T,S>::poll::h6096748dfbf63e3f+0x47
cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run_task::hbc7adf21738f2cc8+0x146
cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run::h8894624b64f9ebd1+0xabe
cru-ds-fdsync-v1`tokio::runtime::context::scoped::Scoped<T>::set::h7f53e80a35be279f+0x2b
cru-ds-fdsync-v1`tokio::runtime::context::runtime::enter_runtime::ha36cde2fe36fc9dc+0x172
cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::run::heea3712ec5628e2e+0x4b
cru-ds-fdsync-v1`tokio::runtime::task::core::Core<T,S>::poll::h4fdbe1f8b2e046e9+0x43
cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness<T,S>::poll::hdaaa15b8bfc6c3b5+0x45
cru-ds-fdsync-v1`std::sys_common::backtrace::__rust_begin_short_backtrace::h07e5ebb552c48fa6+0x1b6
cru-ds-fdsync-v1`core::ops::function::FnOnce::call_once{{vtable.shim}}::hfb58463ecc052a89+0x75
cru-ds-fdsync-v1`std::sys::unix::thread::Thread::new::thread_start::h1783cbcbbf061711+0x29
libc.so.1`_thrp_setup+0x77
libc.so.1`_lwp_start
1

zfs`arc_memory_throttle+0x1
zfs`dsl_dir_tempreserve_space+0x9e
zfs`dmu_tx_try_assign+0x149
zfs`dmu_tx_assign+0x56
zfs`zfs_write+0x475
genunix`fop_write+0x5d
genunix`pwrite+0x172
unix`sys_syscall+0x17d

libc.so.1`__pwrite+0xa
cru-ds-fdsync-v1`<crucible_downstairs::extent_inner_raw::RawInner as crucible_downstairs::extent::ExtentInner>::write::hef63fa757835e3ff+0x1621
cru-ds-fdsync-v1`crucible_downstairs::extent::Extent::write::hfeced6743c01c23b+0x2fd
cru-ds-fdsync-v1`crucible_downstairs::region::Region::region_write::hfbbb7f74fb6b1568+0x654
cru-ds-fdsync-v1`crucible_downstairs::ActiveConnection::do_work::{{closure}}::h50e10780011359fc+0x1128
cru-ds-fdsync-v1`crucible_downstairs::ActiveConnection::do_work_if_ready::{{closure}}::h65a7bded82d12d6c+0x148
cru-ds-fdsync-v1`crucible_downstairs::Downstairs::run::_$u7b$$u7b$closure$u7d$$u7d$::h7a3087a6f836e6c7 (.llvm.14070482526595365531)+0x2012
cru-ds-fdsync-v1`tokio::runtime::task::core::Core<T,S>::poll::hf3cf7a78e14ca649+0x47
cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness<T,S>::poll::h2d72b7b7afc40df2+0x49
cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run_task::hbc7adf21738f2cc8+0x190
cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::Context::run::h8894624b64f9ebd1+0xabe
cru-ds-fdsync-v1`tokio::runtime::context::scoped::Scoped<T>::set::h7f53e80a35be279f+0x2b
cru-ds-fdsync-v1`tokio::runtime::context::runtime::enter_runtime::ha36cde2fe36fc9dc+0x172
cru-ds-fdsync-v1`tokio::runtime::scheduler::multi_thread::worker::run::heea3712ec5628e2e+0x4b
cru-ds-fdsync-v1`tokio::runtime::task::core::Core<T,S>::poll::h4fdbe1f8b2e046e9+0x43
cru-ds-fdsync-v1`tokio::runtime::task::harness::Harness<T,S>::poll::hdaaa15b8bfc6c3b5+0x45
cru-ds-fdsync-v1`std::sys_common::backtrace::__rust_begin_short_backtrace::h07e5ebb552c48fa6+0x1b6
cru-ds-fdsync-v1`core::ops::function::FnOnce::call_once{{vtable.shim}}::hfb58463ecc052a89+0x75
cru-ds-fdsync-v1`std::sys::unix::thread::Thread::new::thread_start::h1783cbcbbf061711+0x29
libc.so.1`_thrp_setup+0x77
libc.so.1`_lwp_start
1

zfs`metaslab_group_alloc_verify+0x1
zfs`zio_execute+0xa7
genunix`taskq_thread+0x2a6
unix`thread_start+0xb

1

zfs`dmu_objset_ds+0x1
zfs`zil_itx_assign+0x194
zfs`zil_commit_itx_assign+0x65
zfs`zil_commit_impl+0x26
zfs`zil_commit+0x4b
zfs`zfs_fsync+0xf6
genunix`fop_fsync+0x4a
genunix`fdsync+0xc4
unix`sys_syscall+0x17d

libc.so.1`__fdsync+0xa
cru-ds-fdsync-v1`std::fs::File::sync_all::hcd4d0768a77cbc2e+0x14
cru-ds-fdsync-v1`<crucible_downstairs::extent_inner_raw::RawInner as crucible_downstairs::extent::ExtentInner>::flush::h68fcf1774758d74e+0x9c
cru-ds-fdsync-v1`crucible_downstairs::extent::Extent::flush::h0eac5b95dfa4f5f0+0x472
cru-ds-fdsync-v1`std::panicking::try::h7ba6611983f64757+0x4c
cru-ds-fdsync-v1`_$LT$rayon_core..job..HeapJob$LT$BODY$GT$$u20$as$u20$rayon_core..job..Job$GT$::execute::h60b9d586fc4f8a0f (.llvm.8052073739315931670)+0x46
cru-ds-fdsync-v1`rayon_core::registry::WorkerThread::wait_until_cold::haa78671c0e7aa9b1+0x50f
cru-ds-fdsync-v1`rayon_core::registry::ThreadBuilder::run::hf28d413d115bded0+0x398
cru-ds-fdsync-v1`std::sys_common::backtrace::__rust_begin_short_backtrace::hfcd6324a3e87fc1e+0x48
cru-ds-fdsync-v1`core::ops::function::FnOnce::call_once{{vtable.shim}}::hbfa4fc2e086997af+0xb2
cru-ds-fdsync-v1`std::sys::unix::thread::Thread::new::thread_start::h1783cbcbbf061711+0x29
libc.so.1`_thrp_setup+0x77
libc.so.1`_lwp_start
1

0 comments on commit 0c0213b

Please sign in to comment.