|
|
@ -1,8 +1,5 @@
|
|
|
|
use bytes::BytesMut;
|
|
|
|
use bytes::BytesMut;
|
|
|
|
use std::{
|
|
|
|
use std::borrow::Borrow;
|
|
|
|
borrow::Borrow,
|
|
|
|
|
|
|
|
os::fd::{AsRawFd as _, RawFd},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// See https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features.
|
|
|
|
// See https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features.
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -103,16 +100,11 @@ impl<T: Borrow<MapData>> AsyncPerfEventArray<T> {
|
|
|
|
) -> Result<AsyncPerfEventArrayBuffer<T>, PerfBufferError> {
|
|
|
|
) -> Result<AsyncPerfEventArrayBuffer<T>, PerfBufferError> {
|
|
|
|
let Self { perf_map } = self;
|
|
|
|
let Self { perf_map } = self;
|
|
|
|
let buf = perf_map.open(index, page_count)?;
|
|
|
|
let buf = perf_map.open(index, page_count)?;
|
|
|
|
let fd = buf.as_raw_fd();
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
Ok(AsyncPerfEventArrayBuffer {
|
|
|
|
let buf = AsyncFd::new(buf)?;
|
|
|
|
buf,
|
|
|
|
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
|
|
|
|
|
|
|
|
let buf = Async::new(buf)?;
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
Ok(AsyncPerfEventArrayBuffer { buf })
|
|
|
|
async_tokio_fd: AsyncFd::new(fd)?,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
|
|
|
|
|
|
|
|
async_std_fd: Async::new(fd)?,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -131,14 +123,15 @@ impl<T: Borrow<MapData>> AsyncPerfEventArray<T> {
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// See the [`AsyncPerfEventArray` documentation](AsyncPerfEventArray) for an overview of how to
|
|
|
|
/// See the [`AsyncPerfEventArray` documentation](AsyncPerfEventArray) for an overview of how to
|
|
|
|
/// use perf buffers.
|
|
|
|
/// use perf buffers.
|
|
|
|
pub struct AsyncPerfEventArrayBuffer<T> {
|
|
|
|
pub struct AsyncPerfEventArrayBuffer<T: Borrow<MapData>> {
|
|
|
|
|
|
|
|
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))]
|
|
|
|
buf: PerfEventArrayBuffer<T>,
|
|
|
|
buf: PerfEventArrayBuffer<T>,
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
async_tokio_fd: AsyncFd<RawFd>,
|
|
|
|
buf: AsyncFd<PerfEventArrayBuffer<T>>,
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
|
|
|
|
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
|
|
|
|
async_std_fd: Async<RawFd>,
|
|
|
|
buf: Async<PerfEventArrayBuffer<T>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<T: Borrow<MapData>> AsyncPerfEventArrayBuffer<T> {
|
|
|
|
impl<T: Borrow<MapData>> AsyncPerfEventArrayBuffer<T> {
|
|
|
@ -155,21 +148,20 @@ impl<T: Borrow<MapData>> AsyncPerfEventArrayBuffer<T> {
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
buffers: &mut [BytesMut],
|
|
|
|
buffers: &mut [BytesMut],
|
|
|
|
) -> Result<Events, PerfBufferError> {
|
|
|
|
) -> Result<Events, PerfBufferError> {
|
|
|
|
let Self {
|
|
|
|
let Self { buf } = self;
|
|
|
|
buf,
|
|
|
|
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
|
|
|
|
async_tokio_fd,
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
|
|
|
|
|
|
|
|
async_std_fd,
|
|
|
|
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
let mut guard = async_tokio_fd.readable_mut().await?;
|
|
|
|
let mut guard = buf.readable_mut().await?;
|
|
|
|
|
|
|
|
#[cfg(feature = "async_tokio")]
|
|
|
|
|
|
|
|
let buf = guard.get_inner_mut();
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
|
|
|
|
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
|
|
|
|
if !buf.readable() {
|
|
|
|
let buf = {
|
|
|
|
async_std_fd.readable().await?;
|
|
|
|
if !buf.get_ref().readable() {
|
|
|
|
}
|
|
|
|
buf.readable().await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.get_mut()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let events = buf.read_events(buffers)?;
|
|
|
|
let events = buf.read_events(buffers)?;
|
|
|
|
const EMPTY: Events = Events { read: 0, lost: 0 };
|
|
|
|
const EMPTY: Events = Events { read: 0, lost: 0 };
|
|
|
|