rustfmt
This commit is contained in:
@@ -5,12 +5,20 @@ use std::time::Duration;
|
||||
const CLOCK_MONOTONIC: i32 = 1;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn clock_nanosleep(clk_id: libc::clockid_t, flags: libc::c_int, rqtp: *const libc::timespec, rmtp: *mut libc::timespec) -> libc::c_int {
|
||||
fn clock_nanosleep(clk_id: libc::clockid_t,
|
||||
flags: libc::c_int,
|
||||
rqtp: *const libc::timespec,
|
||||
rmtp: *mut libc::timespec)
|
||||
-> libc::c_int {
|
||||
unsafe { libc::clock_nanosleep(clk_id, flags, rqtp as *const _, rmtp as *mut _) }
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn clock_nanosleep(_clk_id: libc::c_int, _flags: libc::c_int, rqtp: *const libc::timespec, rmtp: *mut libc::timespec) -> libc::c_int {
|
||||
fn clock_nanosleep(_clk_id: libc::c_int,
|
||||
_flags: libc::c_int,
|
||||
rqtp: *const libc::timespec,
|
||||
rmtp: *mut libc::timespec)
|
||||
-> libc::c_int {
|
||||
unsafe { libc::nanosleep(rqtp as *const _, rmtp as *mut _) }
|
||||
}
|
||||
|
||||
@@ -43,9 +51,7 @@ fn timespec_to_duration(timespec: libc::timespec) -> Duration {
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn set_scheduler(policy: i32, priority: i32) -> libc::c_int {
|
||||
let pid: libc::pid_t = 0;
|
||||
let param = libc::sched_param {
|
||||
sched_priority: priority
|
||||
};
|
||||
let param = libc::sched_param { sched_priority: priority };
|
||||
|
||||
unsafe { libc::sched_setscheduler(pid as libc::pid_t, policy as libc::c_int, ¶m) }
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ use sleep::{set_priority, sleep};
|
||||
use time::precise_time_ns;
|
||||
|
||||
fn duration_from_ns(duration_ns: u64) -> Duration {
|
||||
Duration::new(duration_ns / 1_000_000_000, (duration_ns % 1_000_000_000) as u32)
|
||||
Duration::new(duration_ns / 1_000_000_000,
|
||||
(duration_ns % 1_000_000_000) as u32)
|
||||
}
|
||||
fn duration_to_ns(duration: Duration) -> u64 {
|
||||
duration.as_secs() * 1_000_000_000u64 + duration.subsec_nanos() as u64
|
||||
@@ -86,26 +87,15 @@ fn main() {
|
||||
{
|
||||
let mut ap = ArgumentParser::new();
|
||||
ap.set_description(env!("CARGO_PKG_DESCRIPTION"));
|
||||
ap.refer(&mut min)
|
||||
.add_option(&["--min"], Store,
|
||||
"Sleep period start");
|
||||
ap.refer(&mut max)
|
||||
.add_option(&["--max"], Store,
|
||||
"Sleep period end");
|
||||
ap.refer(&mut step)
|
||||
.add_option(&["--step"], Store,
|
||||
"Sleep period step size");
|
||||
ap.refer(&mut count)
|
||||
.add_option(&["--loop"], Store,
|
||||
"Count of measurements per period");
|
||||
ap.refer(&mut realtime)
|
||||
.add_option(&["--rt"], StoreTrue,
|
||||
"Output file");
|
||||
ap.refer(&mut output)
|
||||
.add_option(&["-o", "--out"], Store,
|
||||
"Output file");
|
||||
ap.refer(&mut min).add_option(&["--min"], Store, "Sleep period start");
|
||||
ap.refer(&mut max).add_option(&["--max"], Store, "Sleep period end");
|
||||
ap.refer(&mut step).add_option(&["--step"], Store, "Sleep period step size");
|
||||
ap.refer(&mut count).add_option(&["--loop"], Store, "Count of measurements per period");
|
||||
ap.refer(&mut realtime).add_option(&["--rt"], StoreTrue, "Output file");
|
||||
ap.refer(&mut output).add_option(&["-o", "--out"], Store, "Output file");
|
||||
ap.add_option(&["-V", "--version"],
|
||||
Print(env!("CARGO_PKG_VERSION").to_string()), "Show version");
|
||||
Print(env!("CARGO_PKG_VERSION").to_string()),
|
||||
"Show version");
|
||||
ap.parse_args_or_exit();
|
||||
}
|
||||
|
||||
@@ -118,11 +108,12 @@ fn main() {
|
||||
}
|
||||
|
||||
if output != "" {
|
||||
file = Some(File::create(Path::new(output.as_str()))
|
||||
.expect(format!("Open file '{}' failed", output).as_str()));
|
||||
file = Some(File::create(Path::new(output.as_str())).expect(format!("Open file '{}' failed",
|
||||
output)
|
||||
.as_str()));
|
||||
}
|
||||
|
||||
for duration in (min..max+1).step_by(step) {
|
||||
for duration in (min..max + 1).step_by(step) {
|
||||
let data = measure_delay_loop(duration_from_ns(duration), count);
|
||||
let max_delay = data.iter().max().expect("Max delay not found");
|
||||
|
||||
@@ -134,8 +125,10 @@ fn main() {
|
||||
match file.as_ref() {
|
||||
Some(mut f) => {
|
||||
let value = format!("{: >9} {}\n", duration, duration_to_ns(max_delay.1));
|
||||
f.write_all(value.as_bytes())
|
||||
.expect(format!("Write value '{}' to '{}' file failed", value, output).as_str());
|
||||
f.write_all(value.as_bytes()).expect(format!("Write value '{}' to '{}' file failed",
|
||||
value,
|
||||
output)
|
||||
.as_str());
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user