Skip to content
Snippets Groups Projects
Commit 73d4b319 authored by Edvin Åkerfeldt's avatar Edvin Åkerfeldt
Browse files

Started implementation of the cli stuff

parent ef19c8cd
No related branches found
No related tags found
No related merge requests found
...@@ -7,3 +7,9 @@ edition = "2018" ...@@ -7,3 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = { version = "0.3", features = [ "paw" ] }
paw = "1.0"
\ No newline at end of file
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use serde::{Serialize, Deserialize};
// common data structures // common data structures
#[derive(Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Task { pub struct Task {
pub id: String, pub id: String,
pub prio: u8, pub prio: u8,
...@@ -18,7 +19,7 @@ impl Task { ...@@ -18,7 +19,7 @@ impl Task {
} }
//#[derive(Debug, Clone)] //#[derive(Debug, Clone)]
#[derive(Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Trace { pub struct Trace {
pub id: String, pub id: String,
pub start: u32, pub start: u32,
......
mod common; pub mod common;
pub mod aux;
use std::path::PathBuf;
use structopt::StructOpt;
use common::*; use common::*;
use aux::*;
/// A basic example
#[derive(StructOpt, Debug)]
#[structopt(name = "srp_analysis", about ="asdasdasdasd")]
struct Opt {
// A flag, true if used in the command line. Note doc comment will
// be used for the help message of the flag. The name of the
// argument will be, by default, based on the name of the field.
/// Use approximation
#[structopt(name = "approximate", long)]
approx_bp: bool,
/// Generate an example file
#[structopt(long)] //
generate: bool,
/// Output file for generated example
#[structopt(short, long, parse(from_os_str))]
output: Option<PathBuf>,
/// Output file for generated example
#[structopt(short, long, parse(from_os_str), required_unless = "generate")]
input: Option<PathBuf>,
}
// The number of occurrences of the `v/verbose` flag
/// Verbose mode (-v, -vv, -vvv, etc.)
//#[structopt(short, long, parse(from_occurrences))]
//verbose: u8,
/// Set speed
//#[structopt(short, long, default_value = "42")]
//speed: f64,
// the long option will be translated by default to kebab case,
// i.e. `--nb-cars`.
/// Number of cars
//#[structopt(short = "c", long)]
//nb_cars: Option<i32>,
/// admin_level to consider
//#[structopt(short, long)]
//level: Vec<String>,
/// Files to process
//#[structopt(name = "FILE", parse(from_os_str))]
//files: Vec<PathBuf>,
fn main() { fn main() {
let t1 = Task { let t1 = Task {
...@@ -67,10 +126,72 @@ fn main() { ...@@ -67,10 +126,72 @@ fn main() {
// builds a vector of tasks t1, t2, t3 // builds a vector of tasks t1, t2, t3
let tasks: Tasks = vec![t1, t2, t3]; let tasks: Tasks = vec![t1, t2, t3];
// Example for running
// cargo run -- --generate_example -o hej.json
// cargo run -- -i hej.json --approximate
// cargo run -- --help
let opt = Opt::from_args();
//println!("{:?}", opt);
if opt.generate {
// Convert the Point to a JSON string.
let serialized = serde_json::to_string(&tasks).unwrap();
// Prints serialized = {"x":1,"y":2}
if let Some(output_file) = opt.output {
println!("Saving example file to: {:?}", output_file);
} else {
println!("{}", serialized);
}
// Convert the JSON string back to a Point.
//let deserialized: [Task; 3] = serde_json::from_str(&serialized).unwrap();
// Prints deserialized = Point { x: 1, y: 2 }
//println!("deserialized = {:?}", deserialized);
return;
}
//let input_file = opt.input.unwrap(); // Let it panic, if it has reached this stage we've fucked up our StructOpt config
println!("tasks {:?}", &tasks); println!("tasks {:?}", &tasks);
// println!("tot_util {}", tot_util(&tasks)); // println!("tot_util {}", tot_util(&tasks));
let (ip, tr) = pre_analysis(&tasks); let (ip, tr) = pre_analysis(&tasks);
println!("ip: {:?}", ip); println!("ip: {:?}", ip);
println!("tr: {:?}", tr); println!("tr: {:?}", tr);
let _approximate_bp = false;
println!("=== Running analysis ===");
for t in tasks.iter() {
println!("-> {:?}", &t.id);
println!(":: Response time (safe approx) = {:?}", response_time(&t, &tasks, true).unwrap());
println!(":: Preemption time (safe approx) = {:?}", preemption_time(&t, &tasks, true).unwrap());
match response_time(&t, &tasks, false) {
Ok(re) => println!(":: Response time (realistic) = {:?}", re),
Err(_) => println!(":: Response time (realistic) = INCONC")
}
match preemption_time(&t, &tasks, false) {
Ok(re) => println!(":: Preemption time (realistic) = {:?}", re),
Err(_) => println!(":: Preemption time (realistic) = INCONC")
}
println!(":: Blocking time = {:?}", blocking_time(&t, &tasks));
println!(":: WCET = {:?}", t.get_wcet());
println!("");
}
println!("{:?}", times_as_vec(&tasks, false));
let l = total_cpu_load(&tasks);
if l <= 1.0 {
println!("Loadfactor: {:?} - OK", l)
} else {
println!("Loadfactor: {:?} - FAILED", l)
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment