diff --git a/src/perf_event/counting/group/tests/mod.rs b/src/perf_event/counting/group/tests/mod.rs index 24a41d9..c6af0e2 100644 --- a/src/perf_event/counting/group/tests/mod.rs +++ b/src/perf_event/counting/group/tests/mod.rs @@ -1,8 +1,9 @@ mod hardware; mod software; +use crate::config::{Cpu, Process}; use crate::counting::{Config, CounterGroup}; -use crate::{Builder, Event, EventScope}; +use crate::{Event, EventScope}; /// rate = ev_1 / ev_2 pub fn test_group(ev_1: &Event, ev_2: &Event, workload: &mut F) @@ -16,13 +17,12 @@ where } fn gen_group() -> CounterGroup { - let builder = Builder::new().calling_process().any_cpu(); - builder.build_counting_group().unwrap() + CounterGroup::new(&Process::Calling, &Cpu::Any).unwrap() } fn gen_cfg(ev: &Event) -> Config { let scopes = [EventScope::User, EventScope::Host]; - Config::new(ev, &scopes, &Default::default()) + Config::new(ev, &scopes) } fn test_stat(ev_1: &Event, ev_2: &Event, workload: &mut F) diff --git a/src/perf_event/counting/single/tests/mod.rs b/src/perf_event/counting/single/tests/mod.rs index 34d33af..daba75e 100644 --- a/src/perf_event/counting/single/tests/mod.rs +++ b/src/perf_event/counting/single/tests/mod.rs @@ -1,8 +1,9 @@ mod hardware; mod software; +use crate::config::{Cpu, Process}; use crate::counting::{Config, Counter}; -use crate::{Builder, Event, EventScope}; +use crate::{Event, EventScope}; pub fn test_single(ev: &Event, workload: &mut F) where @@ -13,20 +14,18 @@ where test_reset_count(ev, workload); } -fn gen_counting(ev: &Event) -> Counter { - let builder = Builder::new().calling_process().any_cpu(); - +fn gen_counter(ev: &Event) -> Counter { let scopes = [EventScope::User, EventScope::Host]; - let cfg = Config::new(ev, &scopes, &Default::default()); + let cfg = Config::new(ev, &scopes); - builder.build_counting(&cfg).unwrap() + Counter::new(&Process::Calling, &Cpu::Any, &cfg).unwrap() } fn test_stat(ev: &Event, workload: &mut F) where F: FnMut(), { - let mut counter = gen_counting(ev); + let mut counter = gen_counter(ev); let before = counter.stat().unwrap().event_count; dbg!(before); @@ -45,7 +44,7 @@ fn test_enable_disable(ev: &Event, workload: &mut F) where F: FnMut(), { - let mut counter = gen_counting(ev); + let mut counter = gen_counter(ev); counter.enable().unwrap(); workload(); @@ -63,7 +62,7 @@ fn test_reset_count(ev: &Event, workload: &mut F) where F: FnMut(), { - let mut counter = gen_counting(ev); + let mut counter = gen_counter(ev); counter.enable().unwrap(); workload(); diff --git a/src/perf_event/sampling/group/tests/mod.rs b/src/perf_event/sampling/group/tests/mod.rs index 8487be8..66da780 100644 --- a/src/perf_event/sampling/group/tests/mod.rs +++ b/src/perf_event/sampling/group/tests/mod.rs @@ -1,9 +1,10 @@ mod hardware; mod software; +use crate::config::{Cpu, Process}; use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, FixedSamplerGroup, OverflowBy, SamplerGuard}; -use crate::{Builder, Event, EventScope}; +use crate::sampling::{Config, FixedSamplerGroup, OverflowBy, SamplerGroup, SamplerGuard}; +use crate::{Event, EventScope}; pub fn test_group(ev_1: &Event, ev_2: &Event, workload: &mut F) where @@ -17,26 +18,22 @@ where test_guard_stat(ev_1, ev_2, workload); } -fn gen_builder() -> Builder { - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(1 + 512) +fn gen_group() -> SamplerGroup { + let mmap_pages = 1 + 512; + SamplerGroup::new(&Process::Calling, &Cpu::Any, mmap_pages).unwrap() } fn gen_cfg(ev: &Event) -> Config { let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - let extra_config = ExtraConfig::default(); - Config::new(&ev, &scopes, &overflow_by, &extra_config) + Config::new(&ev, &scopes, &overflow_by) } fn test_next_record(ev_1: &Event, ev_2: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(); - let mut group = builder.build_sampling_group().unwrap(); + let mut group = gen_group(); let ev_1_guard = group.add_member(&gen_cfg(ev_1)).unwrap(); let ev_2_guard = group.add_member(&gen_cfg(ev_2)).unwrap(); @@ -72,8 +69,7 @@ fn test_enable_disable(ev_1: &Event, ev_2: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(); - let mut group = builder.build_sampling_group().unwrap(); + let mut group = gen_group(); let ev_1_guard = group.add_member(&gen_cfg(ev_1)).unwrap(); let ev_2_guard = group.add_member(&gen_cfg(ev_2)).unwrap(); @@ -109,8 +105,7 @@ fn test_guard_basic(ev_1: &Event, ev_2: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(); - let mut group = builder.build_sampling_group().unwrap(); + let mut group = gen_group(); let mut ev_1_guard = group.add_member(&gen_cfg(ev_1)).unwrap(); let mut ev_2_guard = group.add_member(&gen_cfg(ev_2)).unwrap(); @@ -142,8 +137,7 @@ fn test_guard_enable_disable(ev_1: &Event, ev_2: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(); - let mut group = builder.build_sampling_group().unwrap(); + let mut group = gen_group(); let mut ev_1_guard = group.add_member(&gen_cfg(ev_1)).unwrap(); let mut ev_2_guard = group.add_member(&gen_cfg(ev_2)).unwrap(); @@ -179,8 +173,7 @@ fn test_stat(ev_1: &Event, ev_2: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(); - let mut group = builder.build_sampling_group().unwrap(); + let mut group = gen_group(); let ev_1_guard = group.add_member(&gen_cfg(ev_1)).unwrap(); let ev_2_guard = group.add_member(&gen_cfg(ev_2)).unwrap(); @@ -209,8 +202,7 @@ fn test_guard_stat(ev_1: &Event, ev_2: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(); - let mut group = builder.build_sampling_group().unwrap(); + let mut group = gen_group(); let mut ev_1_guard = group.add_member(&gen_cfg(ev_1)).unwrap(); let mut ev_2_guard = group.add_member(&gen_cfg(ev_2)).unwrap(); diff --git a/src/perf_event/sampling/single/tests/mod.rs b/src/perf_event/sampling/single/tests/mod.rs index 7d6e753..9d3b378 100644 --- a/src/perf_event/sampling/single/tests/mod.rs +++ b/src/perf_event/sampling/single/tests/mod.rs @@ -3,8 +3,9 @@ mod sample_record_fields; mod software; use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy}; -use crate::{Builder, Event, EventScope}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; +use crate::{Event, EventScope}; +use crate::config::{Cpu, Process}; pub fn test_single(ev: &Event, workload: &mut F) where @@ -19,11 +20,9 @@ where test_stat(ev, workload); } -fn gen_builder(mmap_pages: usize) -> Builder { - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) +fn gen_sampler(cfg: &Config) -> Sampler { + let mmap_pages = 1 + 512; + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(ev: &Event) -> Config { @@ -31,15 +30,14 @@ fn gen_cfg(ev: &Event) -> Config { let overflow_by = OverflowBy::Period(1000); let mut extra_config = ExtraConfig::default(); extra_config.sample_record_fields.time = true; - Config::new(&ev, &scopes, &overflow_by, &extra_config) + Config::extra_new(&ev, &scopes, &overflow_by, &extra_config) } fn test_next_record(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + (1 << 16)); - let mut sampler = builder.build_sampling(&gen_cfg(ev)).unwrap(); + let mut sampler = gen_sampler(&gen_cfg(ev)); sampler.enable().unwrap(); workload(); @@ -61,8 +59,7 @@ fn test_all_records(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + (1 << 16)); - let mut sampler = builder.build_sampling(&gen_cfg(ev)).unwrap(); + let mut sampler = gen_sampler(&gen_cfg(ev)); sampler.enable().unwrap(); workload(); @@ -84,8 +81,7 @@ fn test_enable_disable(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + (1 << 16)); - let mut sampler = builder.build_sampling(&gen_cfg(ev)).unwrap(); + let mut sampler = gen_sampler(&gen_cfg(ev)); assert!(sampler.next_record().is_none()); sampler.enable().unwrap(); @@ -113,8 +109,7 @@ fn test_pause_resume(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + (1 << 16)); - let mut sampler = builder.build_sampling(&gen_cfg(ev)).unwrap(); + let mut sampler = gen_sampler(&gen_cfg(ev)); assert!(sampler.next_record().is_none()); sampler.enable().unwrap(); @@ -141,8 +136,7 @@ fn test_ring_buffer(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + 512); - let mut sampler = builder.build_sampling(&gen_cfg(ev)).unwrap(); + let mut sampler = gen_sampler(&gen_cfg(ev)); sampler.enable().unwrap(); workload(); @@ -161,8 +155,7 @@ fn test_stat(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + 512); - let mut sampler = builder.build_sampling(&gen_cfg(ev)).unwrap(); + let mut sampler = gen_sampler(&gen_cfg(ev)); sampler.enable().unwrap(); workload(); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs index 5b33987..c6b3e7a 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_intr.rs @@ -1,14 +1,12 @@ +use crate::config::{Cpu, Process}; use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; use crate::test::cpu_workload; -use crate::{Builder, Event, EventScope, HardwareEvent}; +use crate::{Event, EventScope, HardwareEvent}; -fn gen_builder() -> Builder { +fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(sample_regs_intr: u64) -> Config { @@ -18,15 +16,14 @@ fn gen_cfg(sample_regs_intr: u64) -> Config { let event = HardwareEvent::CpuCycles; let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - Config::new(&Event::from(event), &scopes, &overflow_by, &extra_config) + Config::extra_new(&Event::from(event), &scopes, &overflow_by, &extra_config) } #[test] fn test() { - let builder = gen_builder(); for i in 1..7 { let cfg = gen_cfg(i); - let mut sampler = builder.build_sampling(&cfg).unwrap(); + let mut sampler = gen_sampler(&cfg); sampler.enable().unwrap(); cpu_workload(); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs index 115d175..d4d9d8a 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/abi_and_regs_user.rs @@ -1,14 +1,12 @@ use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; use crate::test::cpu_workload; -use crate::{Builder, Event, EventScope, HardwareEvent}; +use crate::{Event, EventScope, HardwareEvent}; +use crate::config::{Cpu, Process}; -fn gen_builder() -> Builder { +fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(sample_regs_user: u64) -> Config { @@ -18,15 +16,14 @@ fn gen_cfg(sample_regs_user: u64) -> Config { let event = HardwareEvent::CpuCycles; let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - Config::new(&Event::from(event), &scopes, &overflow_by, &extra_config) + Config::extra_new(&Event::from(event), &scopes, &overflow_by, &extra_config) } #[test] fn test() { - let builder = gen_builder(); for i in 1..7 { let cfg = gen_cfg(i); - let mut sampler = builder.build_sampling(&cfg).unwrap(); + let mut sampler = gen_sampler(&cfg); sampler.enable().unwrap(); cpu_workload(); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/all.rs b/src/perf_event/sampling/single/tests/sample_record_fields/all.rs index 5187307..30216de 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/all.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/all.rs @@ -1,22 +1,20 @@ use crate::sampling::record::sample::WeightRepr; use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy, SampleRecordFields}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler, SampleRecordFields}; use crate::test::cpu_workload; -use crate::{Builder, Event, EventScope, HardwareEvent}; +use crate::{Event, EventScope, HardwareEvent}; +use crate::config::{Cpu, Process}; -fn gen_builder() -> Builder { +fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(extra_config: ExtraConfig) -> Config { let event = HardwareEvent::CpuCycles; let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - Config::new(&Event::from(event), &scopes, &overflow_by, &extra_config) + Config::extra_new(&Event::from(event), &scopes, &overflow_by, &extra_config) } #[test] @@ -53,10 +51,9 @@ fn test() { #[cfg(feature = "linux-5.11")] code_page_size: true, }; - let builder = gen_builder(); let cfg = gen_cfg(extra_config); + let mut sampler = gen_sampler(&cfg); - let mut sampler = builder.build_sampling(&cfg).unwrap(); sampler.enable().unwrap(); cpu_workload(); sampler.disable().unwrap(); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs b/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs index 26bdfdc..05abd9e 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/data_stack_user.rs @@ -1,14 +1,12 @@ use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; use crate::test::cpu_workload; -use crate::{Builder, Event, EventScope, HardwareEvent}; +use crate::{Event, EventScope, HardwareEvent}; +use crate::config::{Cpu, Process}; -fn gen_builder() -> Builder { +fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(sample_stack_user: u16) -> Config { @@ -18,15 +16,14 @@ fn gen_cfg(sample_stack_user: u16) -> Config { let event = HardwareEvent::CpuCycles; let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - Config::new(&Event::from(event), &scopes, &overflow_by, &extra_config) + Config::extra_new(&Event::from(event), &scopes, &overflow_by, &extra_config) } #[test] fn test() { - let builder = gen_builder(); for i in 3..8 { let cfg = gen_cfg(2_u16.pow(i)); - let mut sampler = builder.build_sampling(&cfg).unwrap(); + let mut sampler = gen_sampler(&cfg); sampler.enable().unwrap(); cpu_workload(); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs b/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs index d2aefa8..48419a1 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/ips.rs @@ -1,14 +1,12 @@ use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; use crate::test::cpu_workload; -use crate::{Builder, Event, EventScope, HardwareEvent}; +use crate::{Event, EventScope, HardwareEvent}; +use crate::config::{Cpu, Process}; -fn gen_builder() -> Builder { +fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(sample_max_stack: u16) -> Config { @@ -18,15 +16,14 @@ fn gen_cfg(sample_max_stack: u16) -> Config { let event = HardwareEvent::CpuCycles; let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - Config::new(&Event::from(event), &scopes, &overflow_by, &extra_config) + Config::extra_new(&Event::from(event), &scopes, &overflow_by, &extra_config) } #[test] fn test() { - let builder = gen_builder(); for i in 1..7 { let cfg = gen_cfg(i); - let mut sampler = builder.build_sampling(&cfg).unwrap(); + let mut sampler = gen_sampler(&cfg); sampler.enable().unwrap(); cpu_workload(); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs b/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs index c1bd195..ffead67 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/mod.rs @@ -7,23 +7,21 @@ mod ips; mod weight; use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; use crate::test::cpu_workload; -use crate::{Builder, Event, EventScope, HardwareEvent}; +use crate::{Event, EventScope, HardwareEvent}; +use crate::config::{Cpu, Process}; -fn gen_builder() -> Builder { +fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(extra_config: ExtraConfig) -> Config { let event = HardwareEvent::CpuCycles; let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - Config::new(&Event::from(event), &scopes, &overflow_by, &extra_config) + Config::extra_new(&Event::from(event), &scopes, &overflow_by, &extra_config) } macro_rules! gen_test { @@ -33,10 +31,9 @@ macro_rules! gen_test { let mut extra_config = ExtraConfig::default(); extra_config.sample_record_fields.$field = true; - let builder = gen_builder(); let cfg = gen_cfg(extra_config); + let mut sampler = gen_sampler(&cfg); - let mut sampler = builder.build_sampling(&cfg).unwrap(); sampler.enable().unwrap(); cpu_workload(); sampler.disable().unwrap(); @@ -62,10 +59,9 @@ fn pid_and_tid() { let mut extra_config = ExtraConfig::default(); extra_config.sample_record_fields.pid_and_tid = true; - let builder = gen_builder(); let cfg = gen_cfg(extra_config); + let mut sampler = gen_sampler(&cfg); - let mut sampler = builder.build_sampling(&cfg).unwrap(); sampler.enable().unwrap(); cpu_workload(); sampler.disable().unwrap(); diff --git a/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs b/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs index 8ce735e..8d6b15a 100644 --- a/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs +++ b/src/perf_event/sampling/single/tests/sample_record_fields/weight.rs @@ -1,15 +1,13 @@ use crate::sampling::record::sample::{Weight, WeightRepr}; use crate::sampling::record::{Record, RecordBody}; -use crate::sampling::{Config, ExtraConfig, OverflowBy}; +use crate::sampling::{Config, ExtraConfig, OverflowBy, Sampler}; use crate::test::cpu_workload; -use crate::{Builder, Event, EventScope, HardwareEvent}; +use crate::{Event, EventScope, HardwareEvent}; +use crate::config::{Cpu, Process}; -fn gen_builder() -> Builder { +fn gen_sampler(cfg: &Config) -> Sampler { let mmap_pages = 1 + 512; - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) + Sampler::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } fn gen_cfg(repr: WeightRepr) -> Config { @@ -19,14 +17,13 @@ fn gen_cfg(repr: WeightRepr) -> Config { let event = HardwareEvent::CpuCycles; let scopes = [EventScope::User, EventScope::Host]; let overflow_by = OverflowBy::Period(1000); - Config::new(&Event::from(event), &scopes, &overflow_by, &extra_config) + Config::extra_new(&Event::from(event), &scopes, &overflow_by, &extra_config) } #[test] fn test_full() { - let builder = gen_builder(); let cfg = gen_cfg(WeightRepr::Full); - let mut sampler = builder.build_sampling(&cfg).unwrap(); + let mut sampler = gen_sampler(&cfg); sampler.enable().unwrap(); cpu_workload(); @@ -45,9 +42,8 @@ fn test_full() { #[cfg(feature = "linux-5.12")] #[test] fn test_vars() { - let builder = gen_builder(); let cfg = gen_cfg(WeightRepr::Vars); - let mut sampler = builder.build_sampling(&cfg).unwrap(); + let mut sampler = gen_sampler(&cfg); sampler.enable().unwrap(); cpu_workload(); diff --git a/src/perf_event/tracing/tests/breakpoint.rs b/src/perf_event/tracing/tests/breakpoint.rs index abab0ba..0fc2dd1 100644 --- a/src/perf_event/tracing/tests/breakpoint.rs +++ b/src/perf_event/tracing/tests/breakpoint.rs @@ -1,5 +1,5 @@ use crate::sampling::record::{Record, RecordBody}; -use crate::tracing::tests::{gen_builder, gen_cfg}; +use crate::tracing::tests::{gen_cfg, gen_tracer}; use crate::{BreakpointEvent, BreakpointLen, BreakpointType, Event}; fn test(ev: &Event, workload: &mut F, addr: u64) @@ -14,8 +14,7 @@ fn test_next_record(ev: &Event, workload: &mut F, addr: u64) where F: FnMut(), { - let builder = gen_builder(1 + 512); - let mut tracer = builder.build_tracing(&gen_cfg(ev)).unwrap(); + let mut tracer = gen_tracer(&gen_cfg(ev)); tracer.enable().unwrap(); workload(); @@ -35,8 +34,7 @@ fn test_stat(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + 512); - let mut tracer = builder.build_tracing(&gen_cfg(ev)).unwrap(); + let mut tracer = gen_tracer(&gen_cfg(ev)); tracer.enable().unwrap(); workload(); diff --git a/src/perf_event/tracing/tests/mod.rs b/src/perf_event/tracing/tests/mod.rs index a9c4124..f35a3fa 100644 --- a/src/perf_event/tracing/tests/mod.rs +++ b/src/perf_event/tracing/tests/mod.rs @@ -1,19 +1,18 @@ mod breakpoint; mod tracepoint; -use crate::tracing::{Config, ExtraConfig}; -use crate::{Builder, Event, EventScope}; +use crate::tracing::{Config, ExtraConfig, Tracer}; +use crate::{Event, EventScope}; +use crate::config::{Cpu, Process}; -pub fn gen_builder(mmap_pages: usize) -> Builder { - Builder::new() - .calling_process() - .any_cpu() - .ring_buffer_pages(mmap_pages) +fn gen_tracer(cfg: &Config) -> Tracer { + let mmap_pages = 1 + 512; + Tracer::new(&Process::Calling, &Cpu::Any, mmap_pages, cfg).unwrap() } pub fn gen_cfg(ev: &Event) -> Config { let mut extra_config = ExtraConfig::default(); extra_config.sample_record_fields.addr = true; let scopes = EventScope::all(); - Config::new(ev, &scopes, &extra_config) + Config::extra_new(ev, &scopes, &extra_config) } diff --git a/src/perf_event/tracing/tests/tracepoint.rs b/src/perf_event/tracing/tests/tracepoint.rs index 88b7335..f6cd062 100644 --- a/src/perf_event/tracing/tests/tracepoint.rs +++ b/src/perf_event/tracing/tests/tracepoint.rs @@ -1,6 +1,6 @@ use crate::sampling::record::{Record, RecordBody}; use crate::test::{cpu_workload, read_file}; -use crate::tracing::tests::{gen_builder, gen_cfg}; +use crate::tracing::tests::{gen_cfg, gen_tracer}; use crate::{Event, TracepointEvent}; use std::str::FromStr; @@ -16,8 +16,7 @@ fn test_next_record(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + 512); - let mut tracer = builder.build_tracing(&gen_cfg(ev)).unwrap(); + let mut tracer = gen_tracer(&gen_cfg(ev)); tracer.enable().unwrap(); workload(); @@ -37,8 +36,7 @@ fn test_stat(ev: &Event, workload: &mut F) where F: FnMut(), { - let builder = gen_builder(1 + 512); - let mut tracer = builder.build_tracing(&gen_cfg(ev)).unwrap(); + let mut tracer = gen_tracer(&gen_cfg(ev)); tracer.enable().unwrap(); workload();