From bc23774bd41d2195be526790095a0b7adce3ec24 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 7 Apr 2023 17:48:35 -0700 Subject: refactor(timing): move timing interface to timing module --- src/main.rs | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index bd89baa..5ea93f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ mod macros; mod modules; mod route; +mod timing; mod xml; #[macro_use] @@ -65,28 +66,6 @@ static DATABASE: Lazy> = Lazy::new(|| { }) }); -fn time_mounts(context: &str, timer: &mut Instant, mut mounter: T) -where T: FnMut() { - mounter(); - - info!( - "{} mounts took {}ms", - context, - timer.elapsed().as_nanos() as f64 / 1_000_000.0 - ); - - *timer = Instant::now(); -} - -fn time_section(timer: &mut Instant, context: &str) { - info!( - "{} took {}ms", - context, - timer.elapsed().as_nanos() as f64 / 1_000_000.0 - ); - *timer = Instant::now(); -} - #[windmark::main] async fn main() -> Result<(), Box> { std::env::set_var("RUST_LOG", "windmark,locus=trace"); @@ -102,11 +81,10 @@ async fn main() -> Result<(), Box> { windmark::Response::not_found(ERROR_HANDLER_RESPONSE) }); router.set_fix_path(true); - - time_section(&mut time_mount, "creating router"); - - time_mounts("module", &mut time_mount, || stateless!(router, modules)); - + timing::time_section(&mut time_mount, "creating router"); + timing::time_mounts("module", &mut time_mount, || { + stateless!(router, modules); + }); std::thread::spawn(modules::search::index); router.run().await -- cgit v1.2.3