From fe7ba339b5f0295e426213661297666b891ee799 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 25 May 2019 20:09:11 -0700 Subject: [PATCH] Per-stage timing output --- schala-lang/language/src/lib.rs | 51 ++++++++++++++++++++++++++------- schala-repl/src/language.rs | 2 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 6b3ecb7..e6c17f7 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -242,12 +242,24 @@ impl PassDebugArtifact { } } +fn stage_names() -> Vec<&'static str> { + vec![ + "tokenizing", + "parsing", + "symbol-table", + "typechecking", + "ast-reduction", + "ast-walking-evaluation" + ] +} + impl ProgrammingLanguageInterface for Schala { fn get_language_name(&self) -> String { format!("Schala") } fn get_source_file_suffix(&self) -> String { format!("schala") } fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse { let ComputationRequest { source, debug_requests } = request; + let stage_names = stage_names(); self.source_reference.load_new_source(source); let token_debug_artifact = None; @@ -258,17 +270,37 @@ impl ProgrammingLanguageInterface for Schala { let eval_debug_artifact = None; let sw = Stopwatch::start_new(); + let mut stage_durations = Vec::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)) - .and_then(|ast| typechecking(ast, self, typechecking_debug_artifact)) - .and_then(|ast| ast_reducing(ast, self, reducing_debug_artifact)) - .and_then(|reduced_ast| eval(reduced_ast, self, eval_debug_artifact)); + let main_output: Result = { + let output = tokenizing(source, self, token_debug_artifact); + stage_durations.push((stage_names[0].to_string(), sw.elapsed())); + output + }.and_then(|tokens| { + let output = parsing(tokens, self, parsing_debug_artifact); + stage_durations.push((stage_names[1].to_string(), sw.elapsed())); + output + }).and_then(|ast| { + let output = symbol_table(ast, self, symbol_debug_artifact); + stage_durations.push((stage_names[2].to_string(), sw.elapsed())); + output + }).and_then(|ast| { + let output = typechecking(ast, self, typechecking_debug_artifact); + stage_durations.push((stage_names[3].to_string(), sw.elapsed())); + output + }).and_then(|ast| { + let output = ast_reducing(ast, self, reducing_debug_artifact); + stage_durations.push((stage_names[4].to_string(), sw.elapsed())); + output + }).and_then(|reduced_ast| { + let output = eval(reduced_ast, self, eval_debug_artifact); + stage_durations.push((stage_names[5].to_string(), sw.elapsed())); + output + }); let total_duration = sw.elapsed(); let global_output_stats = GlobalOutputStats { - total_duration, stage_durations: None, + total_duration, stage_durations }; ComputationResponse { @@ -280,10 +312,7 @@ impl ProgrammingLanguageInterface for Schala { fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse { match request { - LangMetaRequest::StageNames => LangMetaResponse::StageNames( - vec!["tokenizing".into(), "parsing".into(), "typechecking".into(), "symbol-table".into(), - "ast-reduction".into(), "ast-walking-evaluation".into()] - ), + LangMetaRequest::StageNames => LangMetaResponse::StageNames(stage_names().iter().map(|s| s.to_string()).collect()), LangMetaRequest::Docs { source } => self.handle_docs(source), LangMetaRequest::ImmediateDebug(debug_request) => LangMetaResponse::ImmediateDebug(self.handle_debug_immediate(debug_request)), diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 6126707..abf8bb6 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -31,7 +31,7 @@ pub struct ComputationResponse { #[derive(Default, Debug)] pub struct GlobalOutputStats { pub total_duration: time::Duration, - pub stage_durations: Option> + pub stage_durations: Vec<(String, time::Duration)> } #[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize, Serialize)]