use std::collections::VecDeque;
use vor::viz::{Metric, PanelConfig, PanelState};
#[derive(Clone, Copy)]
struct AppFrame {
visible: u32,
sh_degree: u8,
}
const METRICS: &[Metric<AppFrame>] = &[
Metric::new("visible", visible_of, "splats").as_integer(),
Metric::new("sh_degree", sh_degree_of, "").as_integer(),
];
const fn visible_of(r: &AppFrame) -> f64 {
r.visible as f64
}
const fn sh_degree_of(r: &AppFrame) -> f64 {
r.sh_degree as f64
}
#[vor::profile]
fn fake_work(i: u32) -> u32 {
let mut acc = i;
for k in 0..1_000u32 {
acc = acc.wrapping_mul(k).wrapping_add(1);
}
acc
}
struct Pipeline {
seed: u32,
}
#[vor::all_functions]
impl Pipeline {
fn sort(&self, n: u32) -> u32 {
let mut acc = self.seed ^ n;
for k in 0..2_000u32 {
acc = acc.wrapping_mul(k).wrapping_add(1);
}
acc
}
fn shade(&self, splats: u32) -> u32 {
let mut acc = splats;
for k in 0..1_000u32 {
acc = acc.rotate_left(1).wrapping_add(k);
}
acc
}
}
fn main() {
vor::enable();
let mut state = PanelState::new(PanelConfig::FRAME_MS);
let capacity = PanelConfig::FRAME_MS.history_capacity;
let mut history: VecDeque<AppFrame> = VecDeque::with_capacity(capacity);
let pipeline = Pipeline { seed: 7 };
for i in 0..3 {
let shaded = pipeline.shade(pipeline.sort(fake_work(i)));
vor::record_io(123_456, 1024);
state.tick();
if history.len() >= capacity {
history.pop_front();
}
history.push_back(AppFrame {
visible: 1_500_000 + shaded % 1000,
sh_degree: 3,
});
}
println!("workload metrics defined: {}", METRICS.len());
println!("workload history: {} frames", history.len());
println!("first frame.visible = {}", (METRICS[0].get)(&history[0]));
}