From 2b407a4a83d7417510b53aaa8ce2ce183ee9c3ed Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 21 May 2019 02:06:34 -0700 Subject: [PATCH] Total duration Timing --- schala-lang/language/Cargo.toml | 2 +- schala-lang/language/src/lib.rs | 12 +++++++++++- schala-repl/src/language.rs | 31 ++++++------------------------- schala-repl/src/repl/mod.rs | 4 ++++ 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/schala-lang/language/Cargo.toml b/schala-lang/language/Cargo.toml index 733e168..33cc807 100644 --- a/schala-lang/language/Cargo.toml +++ b/schala-lang/language/Cargo.toml @@ -11,7 +11,7 @@ maplit = "*" lazy_static = "0.2.8" failure = "0.1.2" ena = "0.11.0" - +stopwatch = "0.0.7" schala-lang-codegen = { path = "../codegen" } schala-repl = { path = "../../schala-repl" } diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index badffef..70e191a 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -17,6 +17,8 @@ extern crate schala_repl; extern crate schala_lang_codegen; extern crate ena; +use stopwatch::Stopwatch; + use std::cell::RefCell; use std::rc::Rc; @@ -256,6 +258,8 @@ impl ProgrammingLanguageInterface for Schala { let eval_debug_artifact = None; self.source_reference.load_new_source(source); + let sw = Stopwatch::start_new(); + let main_output: Result = tokenizing(source, self, token_debug_artifact) .and_then(|tokens| parsing(tokens, self, parsing_debug_artifact)) .and_then(|ast| symbol_table(ast, self, symbol_debug_artifact)) @@ -263,9 +267,15 @@ impl ProgrammingLanguageInterface for Schala { .and_then(|ast| ast_reducing(ast, self, reducing_debug_artifact)) .and_then(|reduced_ast| eval(reduced_ast, self, eval_debug_artifact)); + let total_duration = Some(sw.elapsed()); + + let global_output_stats = GlobalOutputStats { + total_duration, stage_durations: None, + }; + ComputationResponse { main_output, - global_output_stats: GlobalOutputStats::default(), + global_output_stats, debug_responses: vec![], } } diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 6ee6d07..6aae266 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -28,6 +28,12 @@ pub struct ComputationResponse { pub debug_responses: Vec, } +#[derive(Default, Debug)] +pub struct GlobalOutputStats { + pub total_duration: Option, + pub stage_durations: Option> +} + pub struct DebugRequest { pub ask: DebugAsk, } @@ -66,28 +72,3 @@ pub enum LangMetaResponse { }, ImmediateDebug(DebugResponse), } - -#[derive(Default, Debug)] -pub struct GlobalOutputStats { - total_duration: Option, - stage_durations: Option> -} - - /* -impl GlobalOutputStats { - fn get_timing(&self) -> Option { - if self.durations.len() != 0 { - let mut buf = String::new(); - write!(&mut buf, "Timing: ").unwrap(); - for duration in self.durations.iter() { - let timing = (duration.as_secs() as f64) + (duration.subsec_nanos() as f64 * 1e-9); - write!(&mut buf, "{}s, ", timing).unwrap() - } - write!(&mut buf, "\n").unwrap(); - Some(buf) - } else { - None - } - } -} -*/ diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 442e58a..de5258c 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -197,6 +197,10 @@ impl Repl { fn handle_computation_response(&mut self, response: ComputationResponse) -> String { let mut buf = String::new(); + if let Some(total_duration) = response.global_output_stats.total_duration { + buf.push_str(&format!("Total duration: {:?}\n", total_duration)); + } + buf.push_str(&match response.main_output { Ok(s) => s, Err(e) => format!("{} {}", "Error".red(), e)