Total duration Timing

This commit is contained in:
greg 2019-05-21 02:06:34 -07:00
parent 6da6f6312d
commit 2b407a4a83
4 changed files with 22 additions and 27 deletions

View File

@ -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" }

View File

@ -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<String, String> = 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![],
}
}

View File

@ -28,6 +28,12 @@ pub struct ComputationResponse {
pub debug_responses: Vec<DebugResponse>,
}
#[derive(Default, Debug)]
pub struct GlobalOutputStats {
pub total_duration: Option<time::Duration>,
pub stage_durations: Option<Vec<(String, time::Duration)>>
}
pub struct DebugRequest {
pub ask: DebugAsk,
}
@ -66,28 +72,3 @@ pub enum LangMetaResponse {
},
ImmediateDebug(DebugResponse),
}
#[derive(Default, Debug)]
pub struct GlobalOutputStats {
total_duration: Option<time::Duration>,
stage_durations: Option<Vec<(String, time::Duration)>>
}
/*
impl GlobalOutputStats {
fn get_timing(&self) -> Option<String> {
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
}
}
}
*/

View File

@ -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)