Skip to content

Commit

Permalink
Argument for terminating measurements after n seconds (#30)
Browse files Browse the repository at this point in the history
* add -t, --terminate-after arg

* add utility to kill ncurses and restore shell

* implement execute time check in interactive and live

* allow not passing run time limit

* update readme
  • Loading branch information
Badgie authored Oct 13, 2021
1 parent 37f9f29 commit 8aae1e8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ cs-21-pt-9-01
RAPL measurement tool
USAGE:
raplrs [OPTIONS] <SUBCOMMAND>
raplrs [OPTIONS] --terminate-after <run-time-limit> <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-d, --delay <delay> Delay between polls (ms) [default: 1000]
-d, --delay <delay> Delay between polls (ms) [default: 1000]
-t, --terminate-after <run-time-limit> Terminate after time limit (s)
SUBCOMMANDS:
benchmark Measure power consumption of a oneshot script
Expand Down
5 changes: 5 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ pub(crate) fn setup_ncurses() {
}
}

pub(crate) fn kill_ncurses() {
ncurses::endwin();
ncurses::reset_shell_mode();
}

pub(crate) fn calculate_power_metrics(zone: models::RAPLData, now: Instant,
start_time: Instant, prev_time: Instant) -> models::RAPLData {
let cur_power_j = read_power(zone.path.to_owned());
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ struct Cli {
/// Delay between polls (ms)
#[structopt(short = "d", long = "delay", default_value = "1000")]
delay: u64,
/// Terminate after time limit (s)
#[structopt(short = "t", long = "terminate-after")]
run_time_limit: Option<u64>,
/// Tool to use
#[structopt(subcommand)]
tool: Tool
Expand Down Expand Up @@ -71,7 +74,7 @@ fn main() {
match args_.tool {
Tool::Live { } => {
common::setup_ncurses();
tools::live_measurement(args_.delay, system_start_time);
tools::live_measurement(args_.delay, system_start_time, args_.run_time_limit);
},
Tool::Benchmark { runner, program, args, n } => {
tools::benchmark(args_.delay, runner, program, args, n, system_start_time);
Expand All @@ -80,7 +83,7 @@ fn main() {
if !background_log {
common::setup_ncurses();
}
tools::benchmark_interactive(runner, program, args_.delay, system_start_time, background_log);
tools::benchmark_interactive(runner, program, args_.delay, system_start_time, background_log, args_.run_time_limit);
},
Tool::Inline { metric} => {
tools::inline(metric, args_.delay);
Expand Down
23 changes: 21 additions & 2 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use std::process::{Command, Stdio};
use std::io;
use std::io::Write;

pub(crate) fn live_measurement(poll_delay: u64, system_start_time: SystemTime) {
pub(crate) fn live_measurement(poll_delay: u64, system_start_time: SystemTime, run_time_limit: Option<u64>) {
let tool_name = "live".to_string();
let sleep = Duration::from_millis(poll_delay);
let mut zones = common::setup_rapl_data();
let run_time_limit = run_time_limit.unwrap_or(0);

let start_time = Instant::now();
let mut prev_time: Instant = start_time;
Expand All @@ -36,6 +37,14 @@ pub(crate) fn live_measurement(poll_delay: u64, system_start_time: SystemTime) {
break;
}

if run_time_limit > 0 && now.duration_since(start_time).as_secs() >= run_time_limit {
common::kill_ncurses();
print_headers!();
print_result_line!(&zones);
println!();
break;
}

thread::sleep(sleep);
}
}
Expand Down Expand Up @@ -78,10 +87,12 @@ pub(crate) fn benchmark(poll_delay: u64, runner: Option<PathBuf>, program: PathB
}

pub(crate) fn benchmark_interactive(runner: Option<PathBuf>, program: PathBuf, poll_delay: u64,
system_start_time: SystemTime, background_log: bool) {
system_start_time: SystemTime, background_log: bool,
run_time_limit: Option<u64>) {
let tool_name = "benchmark-int".to_string();
let sleep = Duration::from_millis(poll_delay);
let mut zones = common::setup_rapl_data();
let run_time_limit = run_time_limit.unwrap_or(0);

let start_time = Instant::now();
let mut prev_time = start_time;
Expand Down Expand Up @@ -136,6 +147,14 @@ pub(crate) fn benchmark_interactive(runner: Option<PathBuf>, program: PathBuf, p

prev_time = now;

if run_time_limit > 0 && now.duration_since(start_time).as_secs() >= run_time_limit {
common::kill_ncurses();
print_headers!();
print_result_line!(&zones);
println!();
break;
}

if ncurses::getch() == common::KEY_CODE_EXIT {
ncurses::endwin();
break;
Expand Down

0 comments on commit 8aae1e8

Please sign in to comment.