iai_callgrind

Struct Delay

source
pub struct Delay(/* private fields */);
Available on crate feature default only.
Expand description

Provide the crate::Delay to specify the event for crate::Command execution start.

The default configuration is created with Delay::new providing a crate::DelayKind to specify the event type and parameters for the Delay.

Additionally, the Delay can be created using from*() methods.

§Examples

Suppose your command needs to start 60 seconds after the benchmark started:

use std::time::Duration;

use iai_callgrind::{Command, Delay, DelayKind};

let command = Command::new(env!("CARGO_BIN_EXE_my-echo")).delay(Delay::new(
    DelayKind::DurationElapse(Duration::from_secs(60)),
));

let command_from =
    Command::new(env!("CARGO_BIN_EXE_my-echo")).delay(Delay::from(Duration::from_secs(60)));

let command_duration =
    Command::new(env!("CARGO_BIN_EXE_my-echo")).delay(Duration::from_secs(60));

However, an iai-callgrind Delay is not limited to a duration, it can be any path creation event, a successful TCP connect or as well a received UDP response.

use iai_callgrind::{Command, Delay, DelayKind};

let command = Command::new("echo").delay(Delay::new(DelayKind::PathExists(
    "/your/path/to/wait/for".into(),
)));

let command_from = Command::new("echo").delay(Delay::from_path("/your/path/to/wait/for"));
use std::net::SocketAddr;
use std::time::Duration;

use iai_callgrind::{Command, Delay, DelayKind};

let command = Command::new("echo").delay(
    Delay::new(DelayKind::TcpConnect(
        "127.0.0.1:31000".parse::<SocketAddr>().unwrap(),
    ))
    .timeout(Duration::from_secs(3))
    .poll(Duration::from_millis(50)),
);

let command_from = Command::new("echo").delay(
    Delay::from_tcp_socket("127.0.0.1:31000".parse::<SocketAddr>().unwrap())
        .timeout(Duration::from_secs(3))
        .poll(Duration::from_millis(50)),
);
use std::net::SocketAddr;
use std::time::Duration;

use iai_callgrind::{Command, Delay, DelayKind};

let command = Command::new("echo").delay(
    Delay::new(DelayKind::UdpResponse(
        "127.0.0.1:34000".parse::<SocketAddr>().unwrap(),
        vec![1],
    ))
    .timeout(Duration::from_secs(3))
    .poll(Duration::from_millis(50)),
);

let command_from = Command::new("echo").delay(
    Delay::from_udp_request("127.0.0.1:34000".parse::<SocketAddr>().unwrap(), vec![1])
        .timeout(Duration::from_secs(3))
        .poll(Duration::from_millis(50)),
);

Implementations§

source§

impl Delay

source

pub fn from_path<T>(path: T) -> Self
where T: Into<PathBuf>,

Instantiate a Delay which will wait until a path exists (Path::exists).


use iai_callgrind::{Command, Delay};

let command = Command::new("echo").delay(Delay::from_path("/your/path/to/wait/for"));
source

pub fn from_tcp_socket<T>(addr: T) -> Self
where T: Into<SocketAddr>,

Instantiate a Delay which will wait until successful TCP connect (std::net::TcpStream::connect).


use std::net::SocketAddr;

use iai_callgrind::{Command, Delay};

let command = Command::new("echo").delay(Delay::from_tcp_socket(
    "127.0.0.1:31000".parse::<SocketAddr>().unwrap(),
));
source

pub fn from_udp_request<T, U>(addr: T, req: U) -> Self
where T: Into<SocketAddr>, U: Into<Vec<u8>>,

Instantiate a Delay which will wait until a UDP response is received after sending the UDP request. The poll duration is also used as the reconnect and request resend interval. (std::net::UdpSocket::bind, std::net::UdpSocket::connect, std::net::UdpSocket::recv).


use std::net::SocketAddr;

use iai_callgrind::{Command, Delay};

let command = Command::new("echo").delay(Delay::from_udp_request(
    "127.0.0.1:34000".parse::<SocketAddr>().unwrap(),
    vec![1],
));
source

pub fn new(kind: DelayKind) -> Self

Instantiate a Delay waiting until an event has happened.

The possible events are defined in DelayKind.


use std::time::Duration;

use iai_callgrind::{Command, Delay, DelayKind};

let command = Command::new("echo").delay(Delay::new(DelayKind::DurationElapse(
    Duration::from_secs(15),
)));
source

pub fn poll<T: Into<Duration>>(self, duration: T) -> Self

Update the Delay poll interval.

The poll interval should be considered together with the Delay::timeout, and ideally should have a value of n * timeout duration.

In case the poll interval is set to a value >= timeout duration it is attempted to set the poll interval to a value of timeout duration - 5ms.


use std::net::SocketAddr;
use std::time::Duration;

use iai_callgrind::{Command, Delay};

let command = Command::new("echo").delay(
    Delay::from_udp_request("127.0.0.1:34000".parse::<SocketAddr>().unwrap(), vec![1])
        .poll(Duration::from_millis(150)),
);
source

pub fn timeout<T: Into<Duration>>(self, duration: T) -> Self

Update the Delay timeout interval.

The timeout duration should be considered together with the poll interval. For further details please refer to Delay::poll. The minimum timeout duration is 10ms.


use std::net::SocketAddr;
use std::time::Duration;

use iai_callgrind::{Command, Delay};
let command = Command::new("echo").delay(
    Delay::from_tcp_socket("127.0.0.1:31000".parse::<SocketAddr>().unwrap())
        .timeout(Duration::from_secs(5)),
);

Trait Implementations§

source§

impl AsRef<Delay> for Delay

source§

fn as_ref(&self) -> &InternalDelay

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Delay

source§

fn clone(&self) -> Delay

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Delay

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Delay

source§

fn default() -> Delay

Returns the “default value” for a type. Read more
source§

impl From<&Delay> for InternalDelay

source§

fn from(value: &Delay) -> Self

Converts to this type from the input type.
source§

impl From<&mut Delay> for InternalDelay

source§

fn from(value: &mut Delay) -> Self

Converts to this type from the input type.
source§

impl From<Delay> for InternalDelay

source§

fn from(value: Delay) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Delay
where T: Into<Duration>,

source§

fn from(duration: T) -> Self

Instantiate a Delay which will wait until the duration has elapsed.


use std::time::Duration;

use iai_callgrind::{Command, Delay};

let command = Command::new("echo").delay(Delay::from(Duration::from_secs(10)));
source§

impl PartialEq for Delay

source§

fn eq(&self, other: &Delay) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Delay

Auto Trait Implementations§

§

impl Freeze for Delay

§

impl RefUnwindSafe for Delay

§

impl Send for Delay

§

impl Sync for Delay

§

impl Unpin for Delay

§

impl UnwindSafe for Delay

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.