diff --git a/rtiow/Cargo.lock b/rtiow/Cargo.lock index 9df414c..c98028e 100644 --- a/rtiow/Cargo.lock +++ b/rtiow/Cargo.lock @@ -795,6 +795,11 @@ name = "httparse" version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "human_format" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "hyper" version = "0.12.24" @@ -1606,6 +1611,7 @@ dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "cpuprofiler 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "human_format 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2503,6 +2509,7 @@ dependencies = [ "checksum hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "21ceb46a83a85e824ef93669c8b390009623863b5c195d1ba747292c0c72f94e" "checksum http 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fe67e3678f2827030e89cc4b9e7ecd16d52f132c0b940ab5005f88e821500f6a" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" +"checksum human_format 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3d5497bfab9681858cded590626cf58844034b453668f7d3700bac5ade28042d" "checksum hyper 0.12.24 (registry+https://github.com/rust-lang/crates.io-index)" = "fdfa9b401ef6c4229745bb6e9b2529192d07b920eed624cdee2a82348cd550af" "checksum hyper-tls 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "32cd73f14ad370d3b4d4b7dce08f69b81536c82e39fcc89731930fe5788cd661" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" diff --git a/rtiow/Cargo.toml b/rtiow/Cargo.toml index 1a8c06c..e307114 100644 --- a/rtiow/Cargo.toml +++ b/rtiow/Cargo.toml @@ -14,6 +14,7 @@ askama = "0.7.1" chrono = "*" cpuprofiler = { version = "0.0.3", optional = true } image = "0.19.0" +human_format = "1.0.1" lazy_static = "1.1.0" log = "0.4.5" num_cpus = "1.8.0" diff --git a/rtiow/src/bin/tracer.rs b/rtiow/src/bin/tracer.rs index 7af52f6..06a8045 100644 --- a/rtiow/src/bin/tracer.rs +++ b/rtiow/src/bin/tracer.rs @@ -36,8 +36,7 @@ lazy_static! { #[cfg(not(feature = "prom"))] fn push_metrics(_push_gateway_addr: &str, _instance: String, start_time: &DateTime) { - let runtime = *start_time - Utc::now(); - let runtime = runtime.to_std().unwrap(); + let runtime = (Utc::now() - *start_time).to_std().unwrap(); info!( "Render time {}.{} seconds", runtime.as_secs(), diff --git a/rtiow/src/human.rs b/rtiow/src/human.rs index 4f2787d..bfe6fe8 100644 --- a/rtiow/src/human.rs +++ b/rtiow/src/human.rs @@ -1,6 +1,6 @@ -/// From https://raw.githubusercontent.com/BobGneu/human-format-rs/master/src/lib.rs #![doc(html_root_url = "https://docs.rs/human_format")] +//! From https://raw.githubusercontent.com/BobGneu/human-format-rs/master/src/lib.rs //! `human_format` provides facilitates creating a formatted string, converting between numbers that are beyond typical //! needs for humans into a simpler string that conveys the gist of the meaning of the number. //! diff --git a/rtiow/src/lib.rs b/rtiow/src/lib.rs index 028e30c..5274097 100644 --- a/rtiow/src/lib.rs +++ b/rtiow/src/lib.rs @@ -6,6 +6,7 @@ pub mod cuboid; pub mod flip_normals; pub mod hitable; pub mod hitable_list; +mod human; pub mod kdtree; pub mod material; pub mod moving_sphere; diff --git a/rtiow/src/renderer.rs b/rtiow/src/renderer.rs index 05f8c3e..9e9188e 100644 --- a/rtiow/src/renderer.rs +++ b/rtiow/src/renderer.rs @@ -23,6 +23,7 @@ use rand::Rng; use crate::camera::Camera; use crate::hitable::Hit; +use crate::human; use crate::ray::Ray; use crate::scenes; use crate::texture::EnvMap; @@ -42,6 +43,7 @@ impl MockPrometheus { fn inc(&self) {} } +static RAY_COUNT: AtomicUsize = AtomicUsize::new(0); #[cfg(not(feature = "prom"))] static RAY_COUNTER: MockPrometheus = MockPrometheus {}; @@ -194,6 +196,7 @@ fn color( global_illumination: bool, env_map: &Option, ) -> Vec3 { + RAY_COUNT.fetch_add(1, Ordering::SeqCst); RAY_COUNTER.with_label_values(&[&depth.to_string()]).inc(); if let Some(rec) = world.hit(r, 0.001, std::f32::MAX) { let (u, v) = rec.uv; @@ -284,7 +287,7 @@ fn render_worker( let job = { input_chan.lock().unwrap().recv() }; match job { Err(err) => { - info!("Shutting down render_worker {}: {}", tid, err); + trace!("Shutting down render_worker {}: {}", tid, err); return; } Ok(req) => match req { @@ -301,7 +304,6 @@ fn render_worker( }, } } - trace!(target: "renderer", "Shutting down worker {}", tid); } pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::io::Error> { @@ -344,22 +346,28 @@ pub fn render(scene: Scene, output_dir: &Path) -> std::result::Result<(), std::i thread::spawn(move || { let mut last_time = time::Instant::now(); let mut last_pixel_count = PIXEL_COUNT.load(Ordering::SeqCst); + let mut last_ray_count = RAY_COUNT.load(Ordering::SeqCst); + let human = human::Formatter::new(); loop { let sleep_time = time::Duration::from_secs(1); thread::sleep(sleep_time); let now = time::Instant::now(); - let mut pixel_count = PIXEL_COUNT.load(Ordering::SeqCst); + let pixel_count = PIXEL_COUNT.load(Ordering::SeqCst); + let ray_count = RAY_COUNT.load(Ordering::SeqCst); let time_diff = now - last_time; let pixel_diff = pixel_count - last_pixel_count; + let ray_diff = ray_count - last_ray_count; info!( - "{} / {} ({}%) pixels rendered {} p/s", - pixel_count, - pixel_total, + "{} / {} ({}%) pixels {} pixels/s {} rays/s", + human.format(pixel_count as f64), + human.format(pixel_total as f64), 100 * pixel_count / pixel_total, - pixel_diff as u64 / time_diff.as_secs() + human.format(pixel_diff as f64 / time_diff.as_secs_f64()), + human.format(ray_diff as f64 / time_diff.as_secs_f64()) ); last_time = now; last_pixel_count = pixel_count; + last_ray_count = ray_count; } });