From 435cb6e4699fc68231a5a9f0f3140284172c888f 2022-02-08 15:11:11 From: mh Date: 2022-02-08 15:11:11 Subject: [PATCH] Add (defaultly disabled) flag for debug logging --- diff --git a/bin-compiler/src/main.rs b/bin-compiler/src/main.rs index 83a996cde240e028973856bac8e09c1fbe0a1713..f9d1b46c4bb3f139e60139fc4f4394361433a731 100644 --- a/bin-compiler/src/main.rs +++ b/bin-compiler/src/main.rs @@ -25,6 +25,12 @@ fn main() { .help("number of runtime threads") .default_value("1") .takes_value(true) + ) + .arg( + Arg::new("debug") + .long("debug") + .short('d') + .help("enable debug logging") ); // Retrieve arguments and convert @@ -51,6 +57,8 @@ fn main() { } }; + let debug_enabled = app.is_present("debug"); + // Add input files to file buffer let input_files = input_files.unwrap(); assert!(input_files.len() > 0); // because arg is required @@ -95,7 +103,7 @@ fn main() { // Make sure there is a nameless module with a main component print!("Creating main component ... "); - let runtime = rw::runtime2::Runtime::new(num_threads, protocol_description); + let runtime = rw::runtime2::Runtime::new(num_threads, debug_enabled, protocol_description); if let Err(err) = runtime.create_component(b"", b"main") { use rw::ComponentCreationError as CCE; let reason = match err { diff --git a/src/runtime2/component/component_pdl.rs b/src/runtime2/component/component_pdl.rs index fb391058dfb1bdfad2b058ca73c5eaec63cfe33e..8fdb556af27fe536f23f6d19a592551b097e4450 100644 --- a/src/runtime2/component/component_pdl.rs +++ b/src/runtime2/component/component_pdl.rs @@ -672,7 +672,6 @@ impl CompPDL { }, None => { // Peer port remains with creator component. - println!("DEBUG: Setting peer for port {:?} of component {:?} to {:?}", created_port_info.self_id, reservation.id(), creator_ctx.id); created_port_info.peer_comp_id = creator_ctx.id; created_ctx.add_peer(pair.created_handle, sched_ctx, creator_ctx.id, None); } diff --git a/src/runtime2/runtime.rs b/src/runtime2/runtime.rs index d8ea8d5960331c5e15062ebc667a7840f6991bfe..f3c46ebbe11ba125623ae42974df250a3e758ddc 100644 --- a/src/runtime2/runtime.rs +++ b/src/runtime2/runtime.rs @@ -158,7 +158,8 @@ pub struct Runtime { } impl Runtime { - pub fn new(num_threads: u32, protocol_description: ProtocolDescription) -> Runtime { + // TODO: debug_logging should be removed at some point + pub fn new(num_threads: u32, debug_logging: bool, protocol_description: ProtocolDescription) -> Runtime { assert!(num_threads > 0, "need a thread to perform work"); let runtime_inner = Arc::new(RuntimeInner { protocol: protocol_description, @@ -173,7 +174,7 @@ impl Runtime { }; for thread_index in 0..num_threads { - let mut scheduler = Scheduler::new(runtime.inner.clone(), thread_index); + let mut scheduler = Scheduler::new(runtime.inner.clone(), thread_index, debug_logging); let thread_handle = std::thread::spawn(move || { scheduler.run(); }); diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index 1e02cfa0db92610c63a8e2ac8800acd22fcd9ae3..b27cf5d06aa3b7636674263fd866508504b4317a 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -8,42 +8,49 @@ use super::runtime::*; pub(crate) struct Scheduler { runtime: Arc, scheduler_id: u32, + debug_logging: bool, } pub(crate) struct SchedulerCtx<'a> { pub runtime: &'a RuntimeInner, pub id: u32, pub comp: u32, + pub logging_enabled: bool, } impl<'a> SchedulerCtx<'a> { - pub fn new(runtime: &'a RuntimeInner, id: u32) -> Self { + pub fn new(runtime: &'a RuntimeInner, id: u32, logging_enabled: bool) -> Self { return Self { runtime, id, comp: 0, + logging_enabled, } } pub(crate) fn log(&self, text: &str) { - println!("[s:{:02}, c:{:03}] {}", self.id, self.comp, text); + if self.logging_enabled { + println!("[s:{:02}, c:{:03}] {}", self.id, self.comp, text); + } } // TODO: Obviously remove, but useful for testing pub(crate) fn log_special(&self, text: &str) { - println!("[s:{:02}, c:{:03}] *** *** {}", self.id, self.comp, text); + if self.logging_enabled { + println!("[s:{:02}, c:{:03}] *** *** {}", self.id, self.comp, text); + } } } impl Scheduler { // public interface to thread - pub fn new(runtime: Arc, scheduler_id: u32) -> Self { - return Scheduler{ runtime, scheduler_id } + pub fn new(runtime: Arc, scheduler_id: u32, debug_logging: bool) -> Self { + return Scheduler{ runtime, scheduler_id, debug_logging } } pub fn run(&mut self) { - let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, self.scheduler_id); + let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, self.scheduler_id, self.debug_logging); 'run_loop: loop { // Wait until we have something to do (or need to quit) diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index 7bdc1ce2771d8f70da978ac0ad6a834e5a414e6b..ce820c8a0167bf00581b238e07141be8c6703995 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -23,7 +23,7 @@ fn test_component_creation() { auto b = 5 + a; } ").expect("compilation"); - let rt = Runtime::new(1, pd); + let rt = Runtime::new(1, true, pd); for i in 0..20 { create_component(&rt, "", "nothing_at_all", no_args()); @@ -80,6 +80,6 @@ fn test_component_communication() { new sender(o_mrmm, 5, 5); new receiver(i_mrmm, 5, 5); }").expect("compilation"); - let rt = Runtime::new(3, pd); + let rt = Runtime::new(3, true, pd); create_component(&rt, "", "constructor", no_args()); } \ No newline at end of file diff --git a/testdata/basic-modules/producer.pdl b/testdata/basic-modules/producer.pdl index d6ddac2d2c79cb98ca95a9768ceb67f1fd551450..dc4747d7687a4ed6bb25a62b97d769223a01b657 100644 --- a/testdata/basic-modules/producer.pdl +++ b/testdata/basic-modules/producer.pdl @@ -1,7 +1,6 @@ #module producer primitive producer(out output) { - print("P: Going to send a value"); sync { print("P: Going to send a value!"); put(output, 1337); diff --git a/testdata/basic/testing.pdl b/testdata/basic/testing.pdl index 9f450bf50e752fe2872a5b109c804e8fd84472b2..af02505f5fbca31617368760f4b7727e70ec8e49 100644 --- a/testdata/basic/testing.pdl +++ b/testdata/basic/testing.pdl @@ -8,7 +8,6 @@ primitive consumer(in input) { } primitive producer(out output) { - print("P: Going to send a value"); sync { print("P: Going to send a value!"); put(output, 1337);