Commit 274b86a9 authored by Simon Wörner's avatar Simon Wörner

added measure pause

parent e786513f
......@@ -223,16 +223,23 @@ impl AsyncPort {
.or(Err(Error::new(ErrorKind::Other, "open failed")))
}
pub fn poll(&mut self, timeout: Option<Duration>, measure: Option<&mut Measure>) -> std::io::Result<Option<Value>> {
let poll = nix::poll::poll(&mut self.fds, match timeout { None => -1, Some(t) => duration_to_ms(t) as i32})
.or(Err(Error::new(ErrorKind::Other, "poll failed")))?;
pub fn poll(&mut self, timeout: Option<Duration>, mut measure: Option<&mut Measure>) -> std::io::Result<Option<Value>> {
let timeout = match timeout { None => -1, Some(t) => duration_to_ms(t) as i32};
// pause measure
if let Some(ref mut m) = measure {
m.pause();
}
let poll = nix::poll::poll(&mut self.fds, timeout);
// start measure
match measure {
Some(m) => m.start(),
None => { }
if let Some(ref mut m) = measure {
m.start();
}
let poll = poll.or(Err(Error::new(ErrorKind::Other, "poll failed")))?;
if poll == 0 {
return Ok(None);
}
......
......@@ -7,6 +7,7 @@ pub struct Measure {
pub min: u64,
pub max: u64,
time: u64,
last: u64,
pub name: String
}
......@@ -15,18 +16,30 @@ impl Measure {
Measure {
min: u64::max_value(),
max: 0u64,
time: 064,
time: 0u64,
last: 0u64,
name: name
}
}
pub fn start(&mut self) {
if self.time != 0 {
if self.last == 0 {
#[cfg(debug_assertions)]
println!("WARNING: Measure('{:?}') start called without stop!", self);
}
self.time = precise_time_ns();
self.last = precise_time_ns();
}
pub fn pause(&mut self) {
if self.last == 0 {
#[cfg(debug_assertions)]
println!("WARNING: Measure('{:?}') pause called without start!", self);
return;
}
self.time += self.time_diff();
}
pub fn stop(&mut self) {
......@@ -37,17 +50,22 @@ impl Measure {
return;
}
let time_diff = precise_time_ns() - self.time;
self.time += self.time_diff();
if time_diff < self.min {
self.min = time_diff;
if self.time < self.min {
self.min = self.time;
}
if time_diff > self.max {
self.max = time_diff;
if self.time > self.max {
self.max = self.time;
}
self.time = 0u64;
self.last = 0u64;
}
fn time_diff(&self) -> u64 {
precise_time_ns() - self.time
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment