pub struct CowIter<'a> { /* private fields */ }
Expand description
COW (copy-on-write) record iterator.
This type allows you to access the raw bytes of record in the underlying ring-buffer directly without copy it to the outside.
Implementations§
Source§impl<'a> CowIter<'a>
impl<'a> CowIter<'a>
Sourcepub fn next<F, R>(&mut self, f: F) -> Option<R>
pub fn next<F, R>(&mut self, f: F) -> Option<R>
Advances the iterator and returns the next value.
If sampling is in happening, operations in the closure should be quick and cheap. Slow iteration of raw bytes may throttle kernel threads from outputting new data to the ring-buffer, and heavy operations may affect the performance of the target process.
§Examples
use perf_event_open::config::{Cpu, Opts, Proc, SampleOn, Size};
use perf_event_open::count::Counter;
use perf_event_open::event::sw::Software;
let event = Software::TaskClock;
let target = (Proc::ALL, Cpu(0));
let mut opts = Opts::default();
opts.sample_on = SampleOn::Count(50_000); // 50us
opts.sample_format.user_stack = Some(Size(8)); // Dump 8-bytes user stack in sample.
let counter = Counter::new(event, target, &opts).unwrap();
let sampler = counter.sampler(5).unwrap();
let mut iter = sampler.iter().into_cow();
counter.enable().unwrap();
let mut skipped = 0;
let it = loop {
let it = iter
.next(|cc, p| {
// ABI layout:
// u32 type
// u16 misc
// u16 size
// u64 len
// [u8; len] bytes
let ptr = cc.as_bytes().as_ptr();
let ty = ptr as *const u32;
// Only parse sample record with stack dumped.
if unsafe { *ty } == 9 {
let len = unsafe { ptr.offset(8) } as *const u64;
if unsafe { *len } > 0 {
return Some(p.parse(cc));
}
}
skipped += 1;
None
})
.flatten();
if let Some(it) = it {
break it;
}
};
println!("skipped: {}", skipped);
println!("{:-?}", it);
Sourcepub fn into_async(self) -> Result<AsyncCowIter<'a>>
pub fn into_async(self) -> Result<AsyncCowIter<'a>>
Creates an asynchronous iterator.
Auto Trait Implementations§
impl<'a> Freeze for CowIter<'a>
impl<'a> RefUnwindSafe for CowIter<'a>
impl<'a> Send for CowIter<'a>
impl<'a> Sync for CowIter<'a>
impl<'a> Unpin for CowIter<'a>
impl<'a> UnwindSafe for CowIter<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more