Print human friendly rays / second.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Bill Thiede 2019-10-12 17:47:19 -07:00
parent c440c518d2
commit 2b1112d39e
6 changed files with 26 additions and 10 deletions

7
rtiow/Cargo.lock generated
View File

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

View File

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

View File

@ -36,8 +36,7 @@ lazy_static! {
#[cfg(not(feature = "prom"))]
fn push_metrics(_push_gateway_addr: &str, _instance: String, start_time: &DateTime<Utc>) {
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(),

View File

@ -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.
//!

View File

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

View File

@ -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<EnvMap>,
) -> 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;
}
});