forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

timing.rs81 lines, 2.6 KiBHistoryRawDownload
1//! Stage timers for one encoder, read through [`Encoder::timings`]. They cost a
2//! clock read per stage per picture, which is noise next to a picture's coding.
3//!
4//! [`Encoder::timings`]: super::Encoder::timings
5
6/// Wall-clock seconds spent in each stage of `encode`, summed over every
7/// picture the encoder has coded.
8#[derive(Debug, Clone, Copy, Default, PartialEq)]
9pub struct EncodeTimings {
10 /// Pictures counted.
11 pub pictures: u64,
12 /// Copying and padding the source planes.
13 pub pad: f64,
14 /// The parallel band coding, wall clock.
15 pub bands_wall: f64,
16 /// Sum of every band's own coding time (the work the threads share).
17 pub bands_busy: f64,
18 /// Sum over pictures of the slowest band (the critical path).
19 pub bands_slowest: f64,
20 /// Stitching the bands into one picture.
21 pub stitch: f64,
22 /// The in-loop deblocking filter, which runs on one thread.
23 pub deblock: f64,
24 /// Border extension, the reference swap and assembling the access unit.
25 pub output: f64,
26}
27
28/// Per-stage nanosecond counters for the macroblock coder, behind the
29/// `enc-profile` feature so a normal build pays nothing. Shared atomics: the
30/// bands add to them concurrently, which is fine for a profile.
31#[cfg(feature = "enc-profile")]
32pub mod mb_stages {
33 use std::sync::atomic::{AtomicU64, Ordering};
34
35 /// Stage names, in index order.
36 pub const NAMES: [&str; 16] = [
37 "choose_inter",
38 "intra_pre_cost",
39 "inter_rd_candidates",
40 "intra_rd_total",
41 "state_save_load",
42 "entropy_clone",
43 "intra4x4_rd",
44 "intra8x8_rd",
45 "intra_bits_and_ssd",
46 "(unused)",
47 "chroma_mode_rd",
48 "intra16_rd",
49 "me_seeds",
50 "me_int",
51 "me_sub",
52 "me_chroma_skip",
53 ];
54 pub(crate) static NANOS: [AtomicU64; 16] = [const { AtomicU64::new(0) }; 16];
55
56 /// Nanoseconds spent in each stage so far, in [`NAMES`] order.
57 pub fn snapshot() -> [u64; 16] {
58 std::array::from_fn(|i| NANOS[i].load(Ordering::Relaxed))
59 }
60}
61
62/// Time `$body` into stage `$idx` of [`mb_stages`] when profiling, else just run it.
63#[cfg(feature = "enc-profile")]
64macro_rules! mb_timed {
65 ($idx:expr, $body:expr) => {{
66 let t = std::time::Instant::now();
67 let r = $body;
68 $crate::enc::timing::mb_stages::NANOS[$idx].fetch_add(
69 t.elapsed().as_nanos() as u64,
70 std::sync::atomic::Ordering::Relaxed,
71 );
72 r
73 }};
74}
75#[cfg(not(feature = "enc-profile"))]
76macro_rules! mb_timed {
77 ($idx:expr, $body:expr) => {
78 $body
79 };
80}
81pub(crate) use mb_timed;