pub struct Delay(/* private fields */);
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.
Delay::from(duration)
Delay::from_tcp_socket(addr)
Delay::from_udp_request(addr, request)
Delay::from_path(path)
§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
impl Delay
sourcepub fn from_path<T>(path: T) -> Self
pub fn from_path<T>(path: T) -> Self
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"));
sourcepub fn from_tcp_socket<T>(addr: T) -> Selfwhere
T: Into<SocketAddr>,
pub fn from_tcp_socket<T>(addr: T) -> Selfwhere
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(),
));
sourcepub fn from_udp_request<T, U>(addr: T, req: U) -> Self
pub fn from_udp_request<T, U>(addr: T, req: U) -> Self
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],
));
sourcepub fn poll<T: Into<Duration>>(self, duration: T) -> Self
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)),
);
sourcepub fn timeout<T: Into<Duration>>(self, duration: T) -> Self
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
impl AsRef<Delay> for Delay
source§fn as_ref(&self) -> &InternalDelay
fn as_ref(&self) -> &InternalDelay
source§impl From<&Delay> for InternalDelay
impl From<&Delay> for InternalDelay
source§impl From<&mut Delay> for InternalDelay
impl From<&mut Delay> for InternalDelay
source§impl From<Delay> for InternalDelay
impl From<Delay> for InternalDelay
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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)