Skip to content

Commit

Permalink
Merge pull request aya-rs#243 from alessandrod/perf-reserve
Browse files Browse the repository at this point in the history
aya: perf_buffer: call BytesMut::reserve() internally
  • Loading branch information
alessandrod committed Apr 10, 2022
2 parents f75d968 + ad1636d commit a1d4499
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
15 changes: 5 additions & 10 deletions aya/src/maps/perf/perf_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub enum PerfBufferError {

/// `read_events()` was called with a buffer that is not large enough to
/// contain the next event in the perf buffer.
#[deprecated(
since = "0.10.8",
note = "read_events() now calls BytesMut::reserve() internally, so this error is never returned"
)]
#[error("the buffer needs to be of at least {size} bytes")]
MoreSpaceNeeded {
/// expected size
Expand Down Expand Up @@ -192,10 +196,7 @@ impl PerfBuffer {
match event_type {
x if x == PERF_RECORD_SAMPLE as u32 => {
buf.clear();
if sample_size > buf.capacity() {
return Err(PerfBufferError::MoreSpaceNeeded { size: sample_size });
}

buf.reserve(sample_size);
unsafe { buf.set_len(sample_size) };

fill_buf(sample_start, base, self.size, buf);
Expand Down Expand Up @@ -239,12 +240,6 @@ impl PerfBuffer {
events.lost += lost;
}
Ok(None) => { /* skip unknown event type */ }
Err(PerfBufferError::MoreSpaceNeeded { .. }) if events.read > 0 => {
// we have processed some events so we're going to return those. In the
// next read_events() we'll return an error unless the caller increases the
// buffer size
break;
}
Err(e) => {
// we got an error and we didn't process any events, propagate the error
// and give the caller a chance to increase buffers
Expand Down
3 changes: 0 additions & 3 deletions aya/src/maps/perf/perf_event_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ impl<T: DerefMut<Target = Map>> PerfEventArrayBuffer<T> {
/// # Errors
///
/// [`PerfBufferError::NoBuffers`] is returned when `out_bufs` is empty.
///
/// [`PerfBufferError::MoreSpaceNeeded { size }`](PerfBufferError) is returned when the size of the events is
/// bigger than the size of the out_bufs provided.
pub fn read_events(&mut self, out_bufs: &mut [BytesMut]) -> Result<Events, PerfBufferError> {
self.buf.read_events(out_bufs)
}
Expand Down

0 comments on commit a1d4499

Please sign in to comment.