From 3fa02f63473e621bbf419f87e2995d613a18079e Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 11 Nov 2026 02:13:55 -0800 Subject: [PATCH] :mute: Write each kind of warning once, and count the rest A warn or error line says a fallback, a refusal or a failure, and the library wrote one at every event that met its cause: a refused pipeline at each create, a broken ring at each post, a swapchain's failure at each frame, a CUDA call's at each frame's drop. Each degradation is to be said once per boot and then counted. The library's logger now writes the first line of each kind at its level and each later one at debug, counting it. A kind is the call site and, where the site reports more than one cause, the class of the cause it names as a `kind` key-value (`kind:% = error`): its text up to its first digit, quote or `;`, so a refusal's id, a raise's selector, a Vulkan result or a CUDA error tells kinds apart and a size or an address does not. A site with one cause names none. An info line that names a kind is said once per kind too. The first 256 kinds are told apart, the rest counted together. `write_repeats` writes the count at info: "lines repeated since the last count: more of :[ []] (: ); ...". The `log` crate's `kv` feature carries the key-value. The display sink's own first-refusal flag goes: the logger keeps one per kind of refusal. msi-boot.sh counts ICB_SLOTS refusals from the first lines and the logger's counts, as the later ones are debug lines now. --- Cargo.toml | 5 +- crates/reims-vgpu-graphics/src/device.rs | 8 +- crates/reims-vgpu-video/Cargo.toml | 2 +- .../reims-vgpu-video/src/core/device_wait.rs | 1 + crates/reims-vgpu-video/src/nvidia/cuda.rs | 8 +- .../reims-vgpu-video/src/nvidia/external.rs | 4 +- .../src/nvidia/nvdec/decoder.rs | 9 +- crates/reims-vgpu-video/src/nvidia/nvenc.rs | 23 +- .../src/nvidia/nvenc/encoder.rs | 4 +- .../reims-vgpu-video/src/nvidia/zero_copy.rs | 2 +- .../reims-vgpu-video/src/vaapi/va/surface.rs | 1 + crates/reims-vgpu-vulkan/src/awake.rs | 2 +- crates/reims-vgpu-vulkan/src/core/logging.rs | 491 +++++++++++++++++- .../src/core/platform/command.rs | 4 +- .../src/core/raise/refusals.rs | 2 +- crates/reims-vgpu-vulkan/src/gpu/command.rs | 4 +- crates/reims-vgpu-vulkan/src/gpu/device.rs | 2 +- .../src/os/linux/host_ram.rs | 7 +- .../reims-vgpu-vulkan/src/os/linux/import.rs | 3 +- .../reims-vgpu-vulkan/src/os/linux/surface.rs | 2 +- crates/reims-vgpu-vulkan/src/os/linux/vm.rs | 4 +- crates/reims-vgpu-vulkan/src/records.rs | 2 +- crates/reims-vgpu-vulkan/src/swapchain.rs | 35 +- crates/reims-vgpu-window/src/sdl/shell.rs | 2 +- crates/reims-vgpu/src/graphics.rs | 29 +- crates/reims-vgpu/src/graphics/decode/icb.rs | 4 +- crates/reims-vgpu/src/graphics/decode/mod.rs | 40 +- .../reims-vgpu/src/graphics/decode/shares.rs | 2 +- .../src/graphics/decode/surface_cache.rs | 20 +- .../src/graphics/decode/surface_order.rs | 4 +- .../src/graphics/decode/surface_pages.rs | 2 +- crates/reims-vgpu/src/graphics/nvidia.rs | 5 +- crates/reims-vgpu/src/graphics/present.rs | 2 +- crates/reims-vgpu/src/graphics/sink.rs | 21 +- crates/reims-vgpu/src/graphics/video_host.rs | 10 +- .../src/graphics/video_host/encode.rs | 10 +- crates/reims-vgpu/src/graphics/vulkan.rs | 2 +- scripts/internal/lane-gate/msi-boot.sh | 12 +- 38 files changed, 654 insertions(+), 136 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3c6d7a86e..c2147d5e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,8 +55,9 @@ lzma-rs = "0.3.0" # core (architecture 2.2) parking_lot = "0.12.5" zerocopy = { version = "0.8.27", features = ["derive"] } -# every crate's lines, and the default stderr logger (core::logging) -log = "0.4.34" +# every crate's lines, and the default stderr logger (core::logging); `kv` for a line's `kind`, +# which tells the logger's kinds apart at one call site +log = { version = "0.4.34", features = ["kv"] } # The macOS sides of the crates. objc2 `exception` is always on; `catch-all` is never enabled # (architecture 2.3). objc2's checks (a message to nil, a missing method, the encodings) are # debug assertions: on in dev, off in `checked` (the objc2 profile override below). diff --git a/crates/reims-vgpu-graphics/src/device.rs b/crates/reims-vgpu-graphics/src/device.rs index 12122fe9c..6d266a4ea 100644 --- a/crates/reims-vgpu-graphics/src/device.rs +++ b/crates/reims-vgpu-graphics/src/device.rs @@ -1573,7 +1573,7 @@ impl Shared { } Err(broken) => { log::error!( - target: "reims_vgpu_graphics", + target: "reims_vgpu_graphics", kind:% = broken; "the control submission ring is broken ({broken}): it takes nothing \ more until the device is reset" ); @@ -1702,7 +1702,7 @@ impl Shared { Posted::NoRoom => return Post::NoRoom, Posted::Broken(broken) => { log::warn!( - target: "reims_vgpu_graphics", + target: "reims_vgpu_graphics", kind:% = broken; "the control completion ring is broken ({broken}): an event is dropped" ); return Post::Dropped; @@ -2349,7 +2349,7 @@ impl Shared { } if let Err(broken) = &next { log::error!( - target: "reims_vgpu_graphics", + target: "reims_vgpu_graphics", kind:% = broken; "queue {:#x}'s submission ring is broken ({broken}): it takes nothing \ more until the device is reset", queue.obj_id ); @@ -2602,7 +2602,7 @@ impl Shared { Posted::NoRoom => return Post::NoRoom, Posted::Broken(broken) => { log::warn!( - target: "reims_vgpu_graphics", + target: "reims_vgpu_graphics", kind:% = broken; "queue {:#x}'s completion ring is broken ({broken}): an event is dropped", queue.obj_id ); diff --git a/crates/reims-vgpu-video/Cargo.toml b/crates/reims-vgpu-video/Cargo.toml index e2b60ecbb..314a345be 100644 --- a/crates/reims-vgpu-video/Cargo.toml +++ b/crates/reims-vgpu-video/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] thiserror = "2" -log = "0.4" +log = { version = "0.4", features = ["kv"] } # The locks the video code takes, the Vulkan crate's core's (`core::sync`). parking_lot.workspace = true # The Annex B start-code scan (`codec::h264::nal`), a vectorized substring search. diff --git a/crates/reims-vgpu-video/src/core/device_wait.rs b/crates/reims-vgpu-video/src/core/device_wait.rs index 4cf611f60..4b9cab91e 100644 --- a/crates/reims-vgpu-video/src/core/device_wait.rs +++ b/crates/reims-vgpu-video/src/core/device_wait.rs @@ -174,6 +174,7 @@ impl Lingering { let mut state = self.shared.lock(); state.ever_kept += 1; log::error!( + kind:% = what; "{what}: the device did not finish it in {:.1} s; it is kept, with what the \ device may still write, until the device is done ({} kept now, {} ever)", DEVICE_WAIT.as_secs_f64(), diff --git a/crates/reims-vgpu-video/src/nvidia/cuda.rs b/crates/reims-vgpu-video/src/nvidia/cuda.rs index 5c450fedd..d5669a855 100644 --- a/crates/reims-vgpu-video/src/nvidia/cuda.rs +++ b/crates/reims-vgpu-video/src/nvidia/cuda.rs @@ -355,7 +355,7 @@ impl Drop for Gpu { // the Gpu, since everything that uses it holds it. let result = unsafe { (self.cuda.f.cuDevicePrimaryCtxRelease)(self.device) }; if let Err(e) = self.cuda.check("cuDevicePrimaryCtxRelease", result) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } } @@ -424,7 +424,7 @@ impl Drop for Stream { // wait for it. let result = unsafe { (cuda.f.cuStreamDestroy_v2)(self.handle) }; if let Err(e) = cuda.check("cuStreamDestroy", result) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } } @@ -491,7 +491,7 @@ impl Drop for Pinned { // SAFETY: allocated by cuMemHostAlloc, freed once. let result = unsafe { (cuda.f.cuMemFreeHost)(self.at.cast::()) }; if let Err(e) = cuda.check("cuMemFreeHost", result) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } } @@ -513,7 +513,7 @@ impl Drop for Current<'_> { // ours; the pointer is to a live CUcontext. let result = unsafe { (self.gpu.cuda.f.cuCtxPopCurrent_v2)(&raw mut popped) }; match self.gpu.cuda.check("cuCtxPopCurrent", result) { - Err(e) => log::warn!("{e}"), + Err(e) => log::warn!(kind:% = e; "{e}"), Ok(()) if popped != self.gpu.context => { log::warn!("cuCtxPopCurrent popped another context than the GPU's"); } diff --git a/crates/reims-vgpu-video/src/nvidia/external.rs b/crates/reims-vgpu-video/src/nvidia/external.rs index bc51c3a16..e3f99b496 100644 --- a/crates/reims-vgpu-video/src/nvidia/external.rs +++ b/crates/reims-vgpu-video/src/nvidia/external.rs @@ -150,12 +150,12 @@ impl Drop for ImportedBuffer { // reference says a mapped buffer is. let freed = unsafe { (cuda.f.cuMemFree_v2)(self.address) }; if let Err(error) = cuda.check("cuMemFree", freed) { - log::warn!("{error}"); + log::warn!(kind:% = error; "{error}"); } // SAFETY: imported by `import`, destroyed once, its mapping freed above. let destroyed = unsafe { (external.cuDestroyExternalMemory)(self.memory) }; if let Err(error) = cuda.check("cuDestroyExternalMemory", destroyed) { - log::warn!("{error}"); + log::warn!(kind:% = error; "{error}"); } } } diff --git a/crates/reims-vgpu-video/src/nvidia/nvdec/decoder.rs b/crates/reims-vgpu-video/src/nvidia/nvdec/decoder.rs index 5abf27b53..5028a10dc 100644 --- a/crates/reims-vgpu-video/src/nvidia/nvdec/decoder.rs +++ b/crates/reims-vgpu-video/src/nvidia/nvdec/decoder.rs @@ -304,7 +304,7 @@ impl Made { let _current = match self.gpu.push() { Ok(current) => current, Err(e) => { - log::warn!("an NVDEC decoder is left undestroyed: {e}"); + log::warn!(kind:% = e; "an NVDEC decoder is left undestroyed: {e}"); return; } }; @@ -312,7 +312,7 @@ impl Made { // destroyed once, when no picture holds it and no decoder took it. let result = unsafe { (self.nvdec.f.cuvidDestroyDecoder)(self.handle) }; if let Err(e) = self.gpu.cuda().check("cuvidDestroyDecoder", result) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } drop(self.stream); @@ -797,6 +797,7 @@ impl Staging { Ok(pinned) => Staging::Pinned(pinned), Err(error) => { log::warn!( + kind:% = error; "no page-locked staging memory of {needed} bytes, so this decoder's \ pictures are copied through pageable memory: {error}" ); @@ -1293,7 +1294,7 @@ impl Drop for UnfinishedPicture { // `calls` with the context pushed, once the copies from it are done. let result = unsafe { (inner.nvdec.f.cuvidUnmapVideoFrame64)(inner.handle(), address) }; if let Err(e) = inner.gpu.cuda().check("cuvidUnmapVideoFrame64", result) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } } @@ -1375,7 +1376,7 @@ impl<'a> MappedFrame<'a> { impl Drop for MappedFrame<'_> { fn drop(&mut self) { if let Err(e) = self.release() { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } } diff --git a/crates/reims-vgpu-video/src/nvidia/nvenc.rs b/crates/reims-vgpu-video/src/nvidia/nvenc.rs index 8ce0456c6..57145fcc2 100644 --- a/crates/reims-vgpu-video/src/nvidia/nvenc.rs +++ b/crates/reims-vgpu-video/src/nvidia/nvenc.rs @@ -549,14 +549,14 @@ impl Session { }; let current = match self.gpu.push() { Ok(current) => current, - Err(e) => return log::warn!("{e}"), + Err(e) => return log::warn!(kind:% = e; "{e}"), }; // SAFETY: a live session and one of its buffers, which it locked, // unlocked once. let status = unsafe { unlock(self.encoder, output) }; drop(current); if let Err(e) = self.check("nvEncUnlockBitstream", status) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } @@ -575,7 +575,7 @@ impl Session { .any(|kept| kept.handle == output && kept.kind == BufferKind::Bitstream) }); if frames && let Err(e) = self.encode_picture(Submission::End) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } for output in submitted { match locks::lock_now(call, self.encoder, &self.gpu, output) { @@ -584,10 +584,10 @@ impl Session { } Ok(Lock { status, .. }) => { if let Err(e) = self.check("nvEncLockBitstream", status) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } - Err(e) => log::warn!("{e}"), + Err(e) => log::warn!(kind:% = e; "{e}"), } } } @@ -824,7 +824,10 @@ impl Drop for Session { return; } drop(locks); - let current = self.gpu.push().inspect_err(|e| log::warn!("{e}")); + let current = self + .gpu + .push() + .inspect_err(|e| log::warn!(kind:% = e; "{e}")); let api = &self.nvenc.api; // Its buffers first, as the header asks; none is locked, since each // lock is undone before the call that made it returns. @@ -838,7 +841,7 @@ impl Drop for Session { // point destroys, destroyed once, as the session goes. let status = unsafe { destroy(self.encoder, kept.handle) }; if let Err(e) = self.check("destroying an NVENC buffer", status) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } let Some(destroy) = api.nvEncDestroyEncoder else { @@ -850,7 +853,7 @@ impl Drop for Session { let status = unsafe { destroy(self.encoder) }; drop(current); if let Err(e) = check_status("nvEncDestroyEncoder", status, None) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } } @@ -877,7 +880,7 @@ impl Session { stuck: RefCell::new(None), }; let Some(locks) = locks else { - log::error!("{what}: no thread finishes it, and it is leaked"); + log::error!(kind:% = what; "{what}: no thread finishes it, and it is leaked"); std::mem::forget(session); return; }; @@ -989,7 +992,7 @@ impl<'a> Locked<'a> { impl Drop for Locked<'_> { fn drop(&mut self) { if let Err(e) = self.release() { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } } diff --git a/crates/reims-vgpu-video/src/nvidia/nvenc/encoder.rs b/crates/reims-vgpu-video/src/nvidia/nvenc/encoder.rs index f665be873..4cdba317a 100644 --- a/crates/reims-vgpu-video/src/nvidia/nvenc/encoder.rs +++ b/crates/reims-vgpu-video/src/nvidia/nvenc/encoder.rs @@ -535,10 +535,10 @@ impl Drop for NvencEncoder { match self.flush() { Ok(bitstreams) => { for e in bitstreams.into_iter().filter_map(Result::err) { - log::warn!("{e}"); + log::warn!(kind:% = e; "{e}"); } } - Err(e) => log::warn!("{e}"), + Err(e) => log::warn!(kind:% = e; "{e}"), } } // The session destroys its buffers, then itself, as its field diff --git a/crates/reims-vgpu-video/src/nvidia/zero_copy.rs b/crates/reims-vgpu-video/src/nvidia/zero_copy.rs index 41847370f..9bafeb095 100644 --- a/crates/reims-vgpu-video/src/nvidia/zero_copy.rs +++ b/crates/reims-vgpu-video/src/nvidia/zero_copy.rs @@ -115,7 +115,7 @@ impl Drop for Registration { (registration.cuMemHostUnregister)(self.view.first.as_ptr().cast::()) }; if let Err(error) = cuda.check("cuMemHostUnregister", result) { - log::warn!("{error}"); + log::warn!(kind:% = error; "{error}"); } } } diff --git a/crates/reims-vgpu-video/src/vaapi/va/surface.rs b/crates/reims-vgpu-video/src/vaapi/va/surface.rs index be87fd8a5..d482e423d 100644 --- a/crates/reims-vgpu-video/src/vaapi/va/surface.rs +++ b/crates/reims-vgpu-video/src/vaapi/va/surface.rs @@ -643,6 +643,7 @@ impl Surface { Ok(read) => read, Err(Fallback::Staged(error)) => { log::warn!( + kind:% = error; "the staged copy back failed, so this pool's frames come back through \ vaGetImage from now on: {error}" ); diff --git a/crates/reims-vgpu-vulkan/src/awake.rs b/crates/reims-vgpu-vulkan/src/awake.rs index 4ddc82a3c..d7492a4b1 100644 --- a/crates/reims-vgpu-vulkan/src/awake.rs +++ b/crates/reims-vgpu-vulkan/src/awake.rs @@ -237,7 +237,7 @@ fn keep(device: &rt::Device, shared: &Shared, look: Duration) { None => Toucher::new(device).and_then(|made| toucher.insert(made).touch()), }; if let Err(e) = touched { - log::warn!(target: TARGET, "the GPU is no longer kept awake: {e}"); + log::warn!(target: TARGET, kind:% = e; "the GPU is no longer kept awake: {e}"); drop(toucher.take()); drop(held); return; diff --git a/crates/reims-vgpu-vulkan/src/core/logging.rs b/crates/reims-vgpu-vulkan/src/core/logging.rs index d4de66cdc..b8f94463b 100644 --- a/crates/reims-vgpu-vulkan/src/core/logging.rs +++ b/crates/reims-vgpu-vulkan/src/core/logging.rs @@ -20,6 +20,21 @@ //! evaluates its arguments only when a logger takes it, so no argument has an effect. A value a //! line shows that has one (a read of guest memory, a question to Metal) is read before the line, //! whether or not it is written. +//! +//! **A warn or error line is written once per kind.** Such a line says a fallback, a refusal or a +//! failure, whose cause may come again at every event that meets it (a guest's message, a frame, +//! an object's release). This logger writes the first line of each kind at its level, and each +//! later one at debug, where the filter takes debug for its target, counting it ([`Kinds`]). A +//! kind is the line's call site (its file and line) and, where the line names one, the class of +//! its [`KIND`] key-value, which tells apart the causes one site reports: the cause itself, +//! `log::warn!(target: "…", kind:% = error; "… was refused: {error}")`, whose text up to its +//! first digit, quote or `;` is its class ([`class`]), so a size, an address or a name in it +//! makes no kind of its own. An info line that names a [`KIND`] is written once per kind too: a +//! fallback each session or object may take, said once per process. [`write_repeats`] writes how +//! many lines of each kind came after its first since its last line, at a device's reset and at +//! the process's exit (`crate::answer::write_counts`). Other info lines, and debug and trace +//! lines, are written as they come: a line at info is never on a path every event takes +//! (docs/conventions.md). use std::fmt::Write as _; use std::io::Write as _; @@ -133,6 +148,158 @@ pub fn stderr_line(level: Level, target: &str, message: &str) -> String { format!("reims-vgpu {level} {target}: {message}\n") } +/// The key-value a warn or error line names its cause by, where its call site reports more than +/// one (the module docs): the [`class`] of its value's `Display` text, with the call site, is the +/// line's kind. +pub const KIND: &str = "kind"; + +/// How many kinds of warn and error lines the logger tells apart; a line of a kind past them is +/// written at debug, and counted with the others past them ([`Kinds::past`]). +const KINDS_KEPT: usize = 256; + +/// The class of a cause's text, which a line's [`KIND`] names: its text up to its first ASCII +/// digit, `"`, `` ` `` or `;`, less the spaces and opening punctuation it then ends with. What +/// varies between causes of one class (a size, an address, an index, a quoted name, a clause of +/// detail) comes after it: `too small: 16 x 16` is of the class `too small`, +/// `NoFunction("main0")` of `NoFunction`. +pub fn class(text: &str) -> &str { + let end = text + .find(|c: char| c.is_ascii_digit() || matches!(c, '"' | '`' | ';')) + .unwrap_or(text.len()); + text[..end].trim_end_matches(|c: char| c.is_whitespace() || "([{<:,=#".contains(c)) +} + +/// The target of [`write_repeats`]'s line. +const REPEATS_TARGET: &str = "reims_vgpu_vulkan::core::logging"; + +/// How many characters of a kind's first line [`write_repeats`]'s line shows. +const FIRST_SHOWN: usize = 120; + +/// A line's kind: its call site, and the [`class`] of the [`KIND`] it names ("" for none). +#[derive(Debug, Clone, PartialEq, Eq)] +struct Site { + file: &'static str, + line: u32, + kind: String, +} + +impl Site { + /// `record`'s, where it is written once per kind (the module docs): a warn or error line, or + /// an info line that names a [`KIND`], whose call site is known, as it is for every line of + /// `log`'s macros. + fn of(record: &Record<'_>) -> Option { + let kind = (record.key_values().get(log::kv::Key::from_str(KIND))) + .map(|kind| class(&kind.to_string()).to_owned()); + if record.level() > Level::Warn && (record.level() > Level::Info || kind.is_none()) { + return None; + } + Some(Site { + file: record.file_static()?, + line: record.line()?, + kind: kind.unwrap_or_default(), + }) + } +} + +/// The lines of one kind the logger wrote or counted. +struct Kind { + site: Site, + /// The first line's target and message, cut to [`FIRST_SHOWN`] characters. + first: String, + /// How many lines of the kind came after the first. + after: u64, + /// Of them, how many [`write_repeats`] has counted. + counted: u64, +} + +/// The kinds of warn and error lines the logger took, in the order of their first lines (the +/// module docs). A process meets a few dozen at most, so a list serves. +struct Kinds { + kept: Vec, + /// Lines of kinds past the first [`KINDS_KEPT`], each written at debug. + past: u64, + /// Of them, how many [`write_repeats`] has counted. + past_counted: u64, +} + +impl Kinds { + /// An empty list, for a `static`'s initializer. + const fn new() -> Kinds { + Kinds { + kept: Vec::new(), + past: 0, + past_counted: 0, + } + } + + /// Notes a line of `site`: whether it is its kind's first, which is written at its level. + fn note(&mut self, site: &Site) -> bool { + if let Some(kind) = self.kept.iter_mut().find(|kind| kind.site == *site) { + kind.after += 1; + return false; + } + if self.kept.len() == KINDS_KEPT { + self.past += 1; + return false; + } + self.kept.push(Kind { + site: site.clone(), + first: String::new(), + after: 0, + counted: 0, + }); + true + } + + /// Keeps the first line of `site`'s kind, of `target` and `message`, for [`Self::repeats`]. + fn describe(&mut self, site: &Site, target: &str, message: &str) { + if let Some(kind) = self.kept.iter_mut().find(|kind| kind.site == *site) { + let mut first = format!("{target}: {message}"); + if let Some((cut, _)) = first.char_indices().nth(FIRST_SHOWN) { + first.truncate(cut); + first.push('…'); + } + kind.first = first; + } + } + + /// The line counting each kind that had lines after its first since the last count, in the + /// order of their first lines, then the lines of kinds past the first [`KINDS_KEPT`]; `None` + /// where there were none. + fn repeats(&mut self) -> Option { + let mut line = String::new(); + for kind in &mut self.kept { + let more = kind.after - kind.counted; + if more == 0 { + continue; + } + kind.counted = kind.after; + if !line.is_empty() { + line.push_str("; "); + } + let Site { + file, + line: at, + kind: named, + } = &kind.site; + let _ = write!(line, "{more} more of {file}:{at}"); + if !named.is_empty() { + let _ = write!(line, " [{named}]"); + } + let _ = write!(line, " ({})", kind.first); + } + let past = self.past - self.past_counted; + if past > 0 { + self.past_counted = self.past; + if !line.is_empty() { + line.push_str("; "); + } + let _ = write!(line, "{past} of kinds past the first {KINDS_KEPT}"); + } + (!line.is_empty()).then(|| format!("lines repeated since the last count: {line}")) + } +} + /// The logger: the environment's filter, the host's hook, and stderr. struct Logger { /// `REIMS_VGPU_LOG`'s filter, read on first use; `None` if it is not set. @@ -143,6 +310,8 @@ struct Logger { /// the lock for a line that is not written. Every encoder call of the Vulkan platform asks /// whether its debug line is on, from as many walk threads as run at once. hook_level: AtomicUsize, + /// The kinds of warn and error lines taken (the module docs). + kinds: Mutex, } /// A hook's level as [`Logger::hook_level`] keeps it: 0 for no hook, else the level's place in @@ -164,6 +333,7 @@ impl Logger { env: OnceLock::new(), hook: Mutex::new(None), hook_level: AtomicUsize::new(0), + kinds: Mutex::new(Kinds::new()), } } @@ -219,25 +389,71 @@ impl Log for Logger { } // The hook is called without the lock: it may write lines of its own, or be replaced. let hook = self.hook.lock().clone(); - if record.level() > self.level(record.target(), hook.as_ref().map(|(level, _)| *level)) { + let up_to = self.level(record.target(), hook.as_ref().map(|(level, _)| *level)); + if record.level() > up_to { + return; + } + // A warn or error line after its kind's first is a debug line, counted (the module + // docs). + let site = Site::of(record); + let first = (site.as_ref()).is_none_or(|site| self.kinds.lock().note(site)); + let level = if first { record.level() } else { Level::Debug }; + if level > up_to { return; } let mut message = String::new(); // A `Display` impl that fails leaves what it wrote. let _ = write!(message, "{}", record.args()); - match hook { - Some((_, hook)) => hook(record.level(), record.target(), &message), - None => { - let line = stderr_line(record.level(), record.target(), &message); - // One write per line, so lines from different threads do not interleave. - let _ = std::io::stderr().write_all(line.as_bytes()); - } + if let (true, Some(site)) = (first, &site) { + self.kinds.lock().describe(site, record.target(), &message); } + write_to(hook, level, record.target(), &message); } fn flush(&self) {} } +/// Writes `message`, a line of `level` and `target` the filter passed, to `hook`, or to stderr +/// without one. +fn write_to(hook: Option, level: Level, target: &str, message: &str) { + match hook { + Some((_, hook)) => hook(level, target, message), + None => { + let line = stderr_line(level, target, message); + // One write per line, so lines from different threads do not interleave. + let _ = std::io::stderr().write_all(line.as_bytes()); + } + } +} + +impl Logger { + /// Writes the line counting the lines that came after their kind's first since the last + /// such line, where any did ([`Kinds::repeats`]): a summary, at info, under + /// [`REPEATS_TARGET`], where the filter takes it. + fn write_repeats(&self) { + let hook = self.hook.lock().clone(); + if Level::Info > self.level(REPEATS_TARGET, hook.as_ref().map(|(level, _)| *level)) { + return; + } + let Some(line) = self.kinds.lock().repeats() else { + return; + }; + write_to(hook, Level::Info, REPEATS_TARGET, &line); + } +} + +/// Writes how many lines of each kind came after its first since the last count, one line at +/// info (the module docs), where any did and the process's logger is this module's: +/// `reims-vgpu INFO reims_vgpu_vulkan::core::logging: lines repeated since the last count: +/// more of :[ []] (: ); …[; of kinds +/// past the first 256]`, the first line cut at 120 characters. A device's reset and the process's +/// exit write it (`crate::answer::write_counts`). +pub fn write_repeats() { + if OURS.get() == Some(&true) { + LOGGER.write_repeats(); + } +} + static LOGGER: Logger = Logger::new(); /// Whether this module's logger is the process's: `Some(true)` once installed, `Some(false)` if @@ -314,9 +530,268 @@ mod tests { env: OnceLock::from(env.map(Filter::parse)), hook: Mutex::new(None), hook_level: AtomicUsize::new(0), + kinds: Mutex::new(Kinds::new()), } } + /// `l` with a hook that keeps every line its filter passes. + fn hooked(l: &Logger) -> Seen { + let (seen, hook) = recording_hook(); + l.keep( + &mut l.hook.lock(), + Some((LevelFilter::Trace, Arc::from(hook))), + ); + seen + } + + /// Writes `text` at `level` from the call site `x.rs:line`, naming `kind` where given, as + /// `log`'s macros do. + fn write_from(l: &Logger, level: Level, line: u32, kind: Option<&str>, text: &str) { + let kinds = kind.map(|kind| [(KIND, kind)]); + let none: [(&str, &str); 0] = []; + l.log( + &Record::builder() + .args(format_args!("{text}")) + .level(level) + .target("reims_vgpu::graphics") + .file_static(Some("x.rs")) + .line(Some(line)) + .key_values(match &kinds { + Some(kinds) => kinds as &dyn log::kv::Source, + None => &none, + }) + .build(), + ); + } + + /// The levels and messages `seen` kept, taken. + fn taken(seen: &Seen) -> Vec<(Level, String)> { + (seen.lock().drain(..)) + .map(|(level, _, message)| (level, message)) + .collect() + } + + /// A warn or error line of a kind already written is a debug line, and counted: the count + /// names its call site and its first line, once + #[test] + fn a_kinds_later_lines_are_debug_lines_and_counted() { + let l = logger(Some("debug")); + let seen = hooked(&l); + write_from(&l, Level::Warn, 7, None, "refused 1"); + write_from(&l, Level::Warn, 7, None, "refused 2"); + write_from(&l, Level::Error, 9, None, "broken"); + write_from(&l, Level::Warn, 7, None, "refused 3"); + assert_eq!( + taken(&seen), + [ + (Level::Warn, "refused 1".to_owned()), + (Level::Debug, "refused 2".to_owned()), + (Level::Error, "broken".to_owned()), + (Level::Debug, "refused 3".to_owned()), + ] + ); + l.write_repeats(); + assert_eq!( + taken(&seen), + [( + Level::Info, + "lines repeated since the last count: 2 more of x.rs:7 (reims_vgpu::graphics: \ + refused 1)" + .to_owned() + )] + ); + l.write_repeats(); + assert_eq!(taken(&seen), [], "nothing repeated since"); + write_from(&l, Level::Error, 9, None, "broken again"); + l.write_repeats(); + assert_eq!( + taken(&seen), + [ + (Level::Debug, "broken again".to_owned()), + ( + Level::Info, + "lines repeated since the last count: 1 more of x.rs:9 \ + (reims_vgpu::graphics: broken)" + .to_owned() + ), + ] + ); + } + + /// A line naming a new kind at a site written before is written at its level; a line of a + /// kind written before, at debug + #[test] + fn a_new_kind_at_a_site_is_written_at_its_level() { + let l = logger(Some("debug")); + let seen = hooked(&l); + write_from(&l, Level::Warn, 7, Some("Abi"), "refused: abi"); + write_from(&l, Level::Warn, 7, Some("Driver"), "refused: driver"); + write_from(&l, Level::Warn, 7, Some("Abi"), "refused: abi again"); + write_from(&l, Level::Warn, 7, None, "refused"); + assert_eq!( + taken(&seen), + [ + (Level::Warn, "refused: abi".to_owned()), + (Level::Warn, "refused: driver".to_owned()), + (Level::Debug, "refused: abi again".to_owned()), + (Level::Warn, "refused".to_owned()), + ] + ); + l.write_repeats(); + assert_eq!( + taken(&seen), + [( + Level::Info, + "lines repeated since the last count: 1 more of x.rs:7 [Abi] \ + (reims_vgpu::graphics: refused: abi)" + .to_owned() + )] + ); + } + + /// Under a filter that takes no debug line, a kind's later lines are not written, but still + /// counted; info lines, and lines with no call site, are written at every occurrence + #[test] + fn a_kinds_later_lines_are_counted_where_debug_is_off() { + let l = logger(Some("info")); + let seen = hooked(&l); + for n in 0..3 { + write_from(&l, Level::Warn, 7, None, &format!("refused {n}")); + write_from(&l, Level::Info, 8, None, &format!("shown {n}")); + } + write(&l, Level::Warn, "reims_vgpu::graphics", "no site"); + write(&l, Level::Warn, "reims_vgpu::graphics", "no site"); + assert_eq!( + taken(&seen), + [ + (Level::Warn, "refused 0".to_owned()), + (Level::Info, "shown 0".to_owned()), + (Level::Info, "shown 1".to_owned()), + (Level::Info, "shown 2".to_owned()), + (Level::Warn, "no site".to_owned()), + (Level::Warn, "no site".to_owned()), + ] + ); + l.write_repeats(); + assert_eq!( + taken(&seen), + [( + Level::Info, + "lines repeated since the last count: 2 more of x.rs:7 (reims_vgpu::graphics: \ + refused 0)" + .to_owned() + )] + ); + } + + /// An info line that names a kind is written once per kind, its later lines at debug and + /// counted, as a warn line's + #[test] + fn an_info_line_naming_a_kind_is_written_once_per_kind() { + let l = logger(Some("debug")); + let seen = hooked(&l); + write_from(&l, Level::Info, 8, Some("in place"), "landed in place"); + write_from(&l, Level::Info, 8, Some("copied"), "landed copied"); + write_from(&l, Level::Info, 8, Some("in place"), "landed in place"); + assert_eq!( + taken(&seen), + [ + (Level::Info, "landed in place".to_owned()), + (Level::Info, "landed copied".to_owned()), + (Level::Debug, "landed in place".to_owned()), + ] + ); + l.write_repeats(); + assert_eq!( + taken(&seen), + [( + Level::Info, + "lines repeated since the last count: 1 more of x.rs:8 [in place] \ + (reims_vgpu::graphics: landed in place)" + .to_owned() + )] + ); + } + + /// A kind's class is its text up to its first digit or quote: the causes one site reports + /// differ by it, and not by a size, an address or a name past it + #[test] + fn a_kinds_class_is_its_text_before_any_digit_or_quote() { + assert_eq!(class("Abi"), "Abi"); + assert_eq!(class("too small: 16 x 16"), "too small"); + assert_eq!(class("NoFunction(\"main0\")"), "NoFunction"); + assert_eq!(class("ERROR_DEVICE_LOST"), "ERROR_DEVICE_LOST"); + assert_eq!( + class("the library's function `f` is missing"), + "the library's function" + ); + assert_eq!(class("0x1000"), ""); + assert_eq!(class("nil; its functions: vertex"), "nil"); + + let l = logger(Some("debug")); + let seen = hooked(&l); + write_from(&l, Level::Warn, 7, Some("too small: 16 x 16"), "a"); + write_from(&l, Level::Warn, 7, Some("too small: 8 x 8"), "b"); + write_from(&l, Level::Warn, 7, Some("too large: 8 x 8"), "c"); + assert_eq!( + taken(&seen), + [ + (Level::Warn, "a".to_owned()), + (Level::Debug, "b".to_owned()), + (Level::Warn, "c".to_owned()), + ] + ); + } + + /// Past the first 256 kinds, a line of a new kind is written at debug and counted with the + /// others past them + #[test] + fn kinds_past_the_first_256_are_counted_together() { + let l = logger(Some("info")); + let seen = hooked(&l); + for line in 0..KINDS_KEPT as u32 + 2 { + write_from(&l, Level::Warn, line, None, "refused"); + } + assert_eq!(taken(&seen).len(), KINDS_KEPT); + l.write_repeats(); + assert_eq!( + taken(&seen), + [( + Level::Info, + "lines repeated since the last count: 2 of kinds past the first 256".to_owned() + )] + ); + } + + /// The count of a kind cuts its first line at 120 characters; under a filter that drops + /// info lines for its target, no count is written + #[test] + fn the_count_cuts_long_first_lines_and_follows_the_filter() { + let l = logger(Some("debug")); + let seen = hooked(&l); + let long = "x".repeat(200); + write_from(&l, Level::Warn, 7, None, &long); + write_from(&l, Level::Warn, 7, None, &long); + let _ = taken(&seen); + l.write_repeats(); + let shown = format!("reims_vgpu::graphics: {long}"); + let cut: String = shown.chars().take(FIRST_SHOWN).collect(); + assert_eq!( + taken(&seen), + [( + Level::Info, + format!("lines repeated since the last count: 1 more of x.rs:7 ({cut}…)") + )] + ); + + let l = logger(Some("debug,reims_vgpu_vulkan::core::logging=error")); + let seen = hooked(&l); + write_from(&l, Level::Warn, 7, None, "refused"); + write_from(&l, Level::Warn, 7, None, "refused"); + l.write_repeats(); + assert_eq!(taken(&seen).len(), 2, "the two lines, and no count"); + } + fn write(l: &Logger, level: Level, target: &str, text: &str) { l.log( &Record::builder() diff --git a/crates/reims-vgpu-vulkan/src/core/platform/command.rs b/crates/reims-vgpu-vulkan/src/core/platform/command.rs index cb8958d54..d3d0388c4 100644 --- a/crates/reims-vgpu-vulkan/src/core/platform/command.rs +++ b/crates/reims-vgpu-vulkan/src/core/platform/command.rs @@ -111,14 +111,14 @@ pub fn run_completed( ) { let info = carried.run(read).unwrap_or_else(|refusal| { log::warn!( - target: "reims_vgpu::refused", + target: "reims_vgpu::refused", kind:% = refusal; "a command buffer's completion was refused, and the command buffer failed: {refusal}" ); CompletedInfo::refused(&refusal) }); if let Err(refusal) = carried.run(|| block(info)) { log::warn!( - target: "reims_vgpu::refused", + target: "reims_vgpu::refused", kind:% = refusal; "a command buffer's completed handler was refused: {refusal}" ); } diff --git a/crates/reims-vgpu-vulkan/src/core/raise/refusals.rs b/crates/reims-vgpu-vulkan/src/core/raise/refusals.rs index d619ef9ec..67a7436c0 100644 --- a/crates/reims-vgpu-vulkan/src/core/raise/refusals.rs +++ b/crates/reims-vgpu-vulkan/src/core/raise/refusals.rs @@ -108,7 +108,7 @@ pub fn refusing(f: impl FnOnce() -> T) -> Result { Err(other) => match panic_message(&*other) { Some(message) if panics_refused() => { log::error!( - target: "reims_vgpu::refused", + target: "reims_vgpu::refused", kind:% = message; "a panic in a refusal scope, a bug, refused the op it met: {message}" ); Err(Refusal { diff --git a/crates/reims-vgpu-vulkan/src/gpu/command.rs b/crates/reims-vgpu-vulkan/src/gpu/command.rs index fad250f90..1fce661ac 100644 --- a/crates/reims-vgpu-vulkan/src/gpu/command.rs +++ b/crates/reims-vgpu-vulkan/src/gpu/command.rs @@ -725,7 +725,7 @@ impl Progress { }; let refused = |what: &str, refusal: refusals::Refusal| { log::warn!( - target: "reims_vgpu::refused", + target: "reims_vgpu::refused", kind:% = refusal; "a command buffer's {what} as it ended was refused: {refusal}" ); }; @@ -794,7 +794,7 @@ impl Ending { && let Err(refusal) = carried.run(|| refused(sel)) { log::warn!( - target: "reims_vgpu::refused", + target: "reims_vgpu::refused", kind:% = refusal; "a refused command buffer's execution of an indirect command buffer: {refusal}" ); } diff --git a/crates/reims-vgpu-vulkan/src/gpu/device.rs b/crates/reims-vgpu-vulkan/src/gpu/device.rs index f0575e5d8..2a311d7f6 100644 --- a/crates/reims-vgpu-vulkan/src/gpu/device.rs +++ b/crates/reims-vgpu-vulkan/src/gpu/device.rs @@ -478,7 +478,7 @@ fn create_buffer( /// Logs that `sel` answered nil, its buffer refused for `why`. fn no_buffer(sel: &'static str, why: &dyn std::fmt::Display) { - log::warn!(target: "reims_vgpu_vulkan::gpu", "{sel} answered nil: {why}"); + log::warn!(target: "reims_vgpu_vulkan::gpu", kind:% = why; "{sel} answered nil: {why}"); } /// What Metal answers where the runtime refuses a buffer or heap made at `placing`'s address: diff --git a/crates/reims-vgpu-vulkan/src/os/linux/host_ram.rs b/crates/reims-vgpu-vulkan/src/os/linux/host_ram.rs index e4efefcd8..7bb7e207b 100644 --- a/crates/reims-vgpu-vulkan/src/os/linux/host_ram.rs +++ b/crates/reims-vgpu-vulkan/src/os/linux/host_ram.rs @@ -147,7 +147,7 @@ fn runtime_ram(ranges: &[(u64, u64)]) -> Option { Ok(ram) => ram, Err(refusal) => { log::warn!( - target: "reims_vgpu_vulkan::os", + target: "reims_vgpu_vulkan::os", kind:% = refusal; "the guest's RAM is not handed to devices whole ({refusal}): buffers over its \ pages keep imports of their own" ); @@ -309,7 +309,10 @@ pub(crate) fn copy_from_host_ram( /// A refusal of a copy by runs, logged. fn refused(error: rt::Error) -> RunsCopyRefused { - log::warn!(target: "reims_vgpu::vulkan", "the runtime refused a copy by runs: {error}"); + log::warn!( + target: "reims_vgpu::vulkan", kind:% = error; + "the runtime refused a copy by runs: {error}" + ); RunsCopyRefused } diff --git a/crates/reims-vgpu-vulkan/src/os/linux/import.rs b/crates/reims-vgpu-vulkan/src/os/linux/import.rs index 32662b53b..f6e9f2183 100644 --- a/crates/reims-vgpu-vulkan/src/os/linux/import.rs +++ b/crates/reims-vgpu-vulkan/src/os/linux/import.rs @@ -246,7 +246,8 @@ pub(crate) fn views_through_dma_bufs() -> bool { /// Imports refused at the views' budget, of one kind: how many and their bytes, each written to /// the trace (its first byte, its length and the mappings it would have taken) and the count -/// logged at the first and at each power of two. +/// logged at the first and at each power of two, at debug after the first (`core::logging`'s once +/// per kind). struct Refused { /// The trace record's name. record: &'static str, diff --git a/crates/reims-vgpu-vulkan/src/os/linux/surface.rs b/crates/reims-vgpu-vulkan/src/os/linux/surface.rs index e3877a94f..108bb2904 100644 --- a/crates/reims-vgpu-vulkan/src/os/linux/surface.rs +++ b/crates/reims-vgpu-vulkan/src/os/linux/surface.rs @@ -464,7 +464,7 @@ fn view(runs: &[std::ops::Range], length: u64, zeros: u64, read_only: bool) .ok()?; let refused = |what: &str| { log::warn!( - target: "reims_vgpu_vulkan::os", + target: "reims_vgpu_vulkan::os", kind:% = what; "IOSurface over the guest's pages: {what}; refused" ); let _ = vm.deallocate(at, whole); diff --git a/crates/reims-vgpu-vulkan/src/os/linux/vm.rs b/crates/reims-vgpu-vulkan/src/os/linux/vm.rs index ee313204d..076aed052 100644 --- a/crates/reims-vgpu-vulkan/src/os/linux/vm.rs +++ b/crates/reims-vgpu-vulkan/src/os/linux/vm.rs @@ -403,7 +403,7 @@ fn no_space(what: &str) -> KernReturn { let at_limit = at_the_limit(&mappings, &limit); if at_limit && AT_LIMIT.with(|a| a.replace(a.get().map(|_| true)).is_some()) { log::warn!( - target: "reims_vgpu_vulkan::os", + target: "reims_vgpu_vulkan::os", kind:% = what; "{what}: the kernel refused the map at the process's limit of mappings, {mappings} of \ vm.max_map_count {limit} held, {} of them the library's views of memory: folding the \ views no import holds, to try again", @@ -424,7 +424,7 @@ fn no_space(what: &str) -> KernReturn { return NO_SPACE; } log::error!( - target: "reims_vgpu_vulkan::os", + target: "reims_vgpu_vulkan::os", kind:% = what; "{what}: the kernel refused the map (ENOMEM): the process has {mappings} mappings, \ vm.max_map_count is {limit}" ); diff --git a/crates/reims-vgpu-vulkan/src/records.rs b/crates/reims-vgpu-vulkan/src/records.rs index 272d66c56..7e8684e46 100644 --- a/crates/reims-vgpu-vulkan/src/records.rs +++ b/crates/reims-vgpu-vulkan/src/records.rs @@ -161,7 +161,7 @@ impl Keeper { Ok(()) => self.bytes += framed.len() as u64, Err(e) => { log::warn!( - target: "reims_vgpu_vulkan::records", + target: "reims_vgpu_vulkan::records", kind:% = e; "a pipeline record was not appended to {}: {e}; no more are kept", self.path.display() ); diff --git a/crates/reims-vgpu-vulkan/src/swapchain.rs b/crates/reims-vgpu-vulkan/src/swapchain.rs index 18c83f81a..59c2f5410 100644 --- a/crates/reims-vgpu-vulkan/src/swapchain.rs +++ b/crates/reims-vgpu-vulkan/src/swapchain.rs @@ -392,7 +392,10 @@ impl Fences { match unsafe { vk.create_fence(&vk::FenceCreateInfo::default(), None) } { Ok(fence) => Some(fence), Err(e) => { - log::warn!(target: "reims_vgpu_vulkan::swapchain", "vkCreateFence: {e}"); + log::warn!( + target: "reims_vgpu_vulkan::swapchain", kind:? = e; + "vkCreateFence: {e}" + ); None } } @@ -796,7 +799,7 @@ impl Swapchain { Ok(()) => self.refusing = false, Err(e) if self.lost => { log::warn!( - target: "reims_vgpu_vulkan::swapchain", + target: "reims_vgpu_vulkan::swapchain", kind:? = e; "no swapchain ({e}): the surface is lost" ); return Acquired::Failed; @@ -804,7 +807,7 @@ impl Swapchain { Err(e) => { if !self.refusing { log::warn!( - target: "reims_vgpu_vulkan::swapchain", + target: "reims_vgpu_vulkan::swapchain", kind:? = e; "no swapchain yet ({e}): tried again at the next draw" ); } @@ -859,7 +862,7 @@ impl Swapchain { } Err(e) => { log::warn!( - target: "reims_vgpu_vulkan::swapchain", + target: "reims_vgpu_vulkan::swapchain", kind:? = e; "vkAcquireNextImageKHR: {e}: the window stops presenting" ); Acquired::Failed @@ -874,7 +877,10 @@ impl Swapchain { Ok(()) => { // SAFETY: the fence has signalled, and nothing else waits on it. if let Err(e) = unsafe { self.vk.reset_fences(&[self.fence]) } { - log::warn!(target: "reims_vgpu_vulkan::swapchain", "vkResetFences: {e}"); + log::warn!( + target: "reims_vgpu_vulkan::swapchain", kind:? = e; + "vkResetFences: {e}" + ); return Acquired::Failed; } self.pending = None; @@ -888,7 +894,10 @@ impl Swapchain { Acquired::Retry } Err(e) => { - log::warn!(target: "reims_vgpu_vulkan::swapchain", "vkWaitForFences: {e}"); + log::warn!( + target: "reims_vgpu_vulkan::swapchain", kind:? = e; + "vkWaitForFences: {e}" + ); Acquired::Failed } } @@ -961,7 +970,7 @@ impl Swapchain { // The image stays taken, its semaphore perhaps never signalled: the swapchain is // made again, which gives every image back. log::warn!( - target: "reims_vgpu_vulkan::swapchain", + target: "reims_vgpu_vulkan::swapchain", kind:? = e; "a window frame was not scheduled ({e:?}): the swapchain is made again" ); self.stale = true; @@ -1021,7 +1030,10 @@ impl Swapchain { Ok(suboptimal) => self.stale |= suboptimal, Err(vk::Result::ERROR_OUT_OF_DATE_KHR) => self.stale = true, Err(e) => { - log::warn!(target: "reims_vgpu_vulkan::swapchain", "vkQueuePresentKHR: {e}"); + log::warn!( + target: "reims_vgpu_vulkan::swapchain", kind:? = e; + "vkQueuePresentKHR: {e}" + ); self.stale = true; } } @@ -1130,7 +1142,7 @@ impl Swapchain { // `None`: a recovery moved the queue, after it waited for the old one to idle (the // module doc, "Across the device's recoveries"). if let Some(Err(e)) = idle { - log::warn!(target: "reims_vgpu_vulkan::swapchain", "vkQueueWaitIdle: {e}"); + log::warn!(target: "reims_vgpu_vulkan::swapchain", kind:? = e; "vkQueueWaitIdle: {e}"); } self.presents.idle(); // Every enqueued present's fence has signalled. @@ -1149,7 +1161,10 @@ impl Swapchain { Ok(true) => {} Ok(false) => break, Err(e) => { - log::warn!(target: "reims_vgpu_vulkan::swapchain", "vkGetFenceStatus: {e}"); + log::warn!( + target: "reims_vgpu_vulkan::swapchain", kind:? = e; + "vkGetFenceStatus: {e}" + ); break; } } diff --git a/crates/reims-vgpu-window/src/sdl/shell.rs b/crates/reims-vgpu-window/src/sdl/shell.rs index e5aee08aa..8e67b8456 100644 --- a/crates/reims-vgpu-window/src/sdl/shell.rs +++ b/crates/reims-vgpu-window/src/sdl/shell.rs @@ -553,7 +553,7 @@ fn mouse_rect(image: Rect) -> SDL_Rect { /// Logs that SDL refused `what` for the window titled `title`. pub(crate) fn refused(what: &str, title: &str) { log::warn!( - target: "reims_vgpu_window", + target: "reims_vgpu_window", kind:% = what; "window {title:?}: {what}: {}", sdl_error() ); diff --git a/crates/reims-vgpu/src/graphics.rs b/crates/reims-vgpu/src/graphics.rs index 43345da7d..83797e79d 100644 --- a/crates/reims-vgpu/src/graphics.rs +++ b/crates/reims-vgpu/src/graphics.rs @@ -892,7 +892,7 @@ impl Presented

{ reims_vgpu_vulkan::core::raise::refusals::refusing(move || drop(shown)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the texture of IOSurface {previous} was let go of, and its release was refused: \ {refusal}" ); @@ -925,7 +925,7 @@ impl Presented

{ reims_vgpu_vulkan::core::raise::refusals::refusing(move || drop(shown)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the texture of IOSurface {previous} was let go of at the device's reset, and its \ release was refused: {refusal}" ); @@ -1156,7 +1156,7 @@ impl GraphicsControl

{ Box::new(move || drop(held)), Box::new(move |raise| { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the block at {offset:#x}: the platform raised at its device cache's \ write back ({raise:?})" ); @@ -1474,7 +1474,7 @@ impl GraphicsControl

{ Ok(Err(e)) => { let (ty, seqno, obj_id) = message_identity(message); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:? = e; "a message (type {ty:#x}, seqno {seqno}, object {obj_id:#x}) was not \ carried out: {e:?}" ); @@ -1485,7 +1485,7 @@ impl GraphicsControl

{ Err(raise) => { let (ty, seqno, obj_id) = message_identity(message); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "a message (type {ty:#x}, seqno {seqno}, object {obj_id:#x}) faulted: \ {raise}" ); @@ -1699,7 +1699,7 @@ impl GraphicsControl

{ Err(e) => { let (ty, seqno, obj_id) = message_identity(message); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:? = e; "a pipeline create (type {ty:#x}, seqno {seqno}, object {obj_id:#x}) was not \ carried out: {e:?}" ); @@ -1731,7 +1731,7 @@ impl GraphicsControl

{ let compiled = compile_refusing::

(&self.device, job); if let Some(reason) = compiled.refusal() { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = reason; "a pipeline create (seqno {seqno}, object {obj_id:#x}) was refused: {reason}" ); } @@ -1837,7 +1837,7 @@ impl GraphicsControl

{ let answer = entry::run(|_| refusing(|| decoder.sampler_state(&self.device, message))); let answer = answer.unwrap_or_else(|raise| { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "a sampler create (type {ty:#x}, seqno {seqno}, object {obj_id:#x}) faulted: \ {raise}" ); @@ -1974,7 +1974,7 @@ impl GraphicsControl

{ let answer = entry::run(|_| refusing(|| decoder.icb_state(&self.device, message))); let answer = answer.unwrap_or_else(|raise| { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "an indirect command buffer create (type {ty:#x}, seqno {seqno}, object \ {obj_id:#x}) faulted: {raise}" ); @@ -2008,7 +2008,7 @@ impl GraphicsControl

{ let (seqno, status) = answer.unwrap_or((Some(seqno), RGFX_STATUS_REFUSED)); if status != RGFX_STATUS_OK { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = status; "an argument layout (type {ty:#x}, object {obj_id:#x}) was answered status \ {status}" ); @@ -2034,7 +2034,7 @@ impl GraphicsControl

{ LibraryStart::Refused { error, answer } => { let (ty, seqno, obj_id) = message_identity(message); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:? = error; "a library create (type {ty:#x}, seqno {seqno}, object {obj_id:#x}) was not \ carried out: {error:?}" ); @@ -2073,7 +2073,7 @@ impl GraphicsControl

{ if status != RGFX_STATUS_OK { let reason = reason.as_deref().unwrap_or("it was cancelled"); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = reason; "a library create (seqno {seqno}, object {obj_id:#x}) was refused: {reason}" ); } @@ -2101,7 +2101,7 @@ impl GraphicsControl

{ entry::run(|_| decoder.fill_presented(&self.device, iosurface_id, generation)); filled.unwrap_or_else(|raise| { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "IOSurface {iosurface_id}: the platform raised at its device cache's fill for \ a present ({raise:?})" ); @@ -2144,7 +2144,7 @@ impl GraphicsControl

{ fn display_color(&self, color: &RgfxDisplayColor, entries: &[RgfxColorEntry]) { if let Err(dropped) = self.color.lock().part(color, entries) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:? = dropped; "a display colour part of transaction {} (stage {}, entries {} on of {}, {} \ carried) was dropped ({dropped:?}): the stage keeps its table", color.transaction_id, @@ -2648,6 +2648,7 @@ fn reserve_guest_texture_ids(platform: &P, device: &P::Device) { let ids: Vec = guest_texture_ids().collect(); if let Err(raise) = refusing(|| device.reserve_resource_indices(0, &ids)) { log::error!( + kind:% = raise; "the guest's texture resource ids are not reserved ({raise}): its textures may \ share ids with the host's" ); diff --git a/crates/reims-vgpu/src/graphics/decode/icb.rs b/crates/reims-vgpu/src/graphics/decode/icb.rs index 905f04cae..2eb540153 100644 --- a/crates/reims-vgpu/src/graphics/decode/icb.rs +++ b/crates/reims-vgpu/src/graphics/decode/icb.rs @@ -349,7 +349,7 @@ impl GraphicsDecoder

{ } if let Some((op, index, why)) = first { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = why; "indirect command buffer {:#x}: {refused} of {records} records not carried out; \ the first, op {op:#04x} at command {index}: {why}", m.obj_id @@ -383,7 +383,7 @@ impl GraphicsDecoder

{ } if let Some((icb, index, why)) = &tally.first { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = why; "ICB_SLOTS of {} runs (the first on buffer {:#x}): {} of {} runs and fields not \ carried out; the first, buffer {icb:#x} at command {index}: {why}", m.run_count, diff --git a/crates/reims-vgpu/src/graphics/decode/mod.rs b/crates/reims-vgpu/src/graphics/decode/mod.rs index 8cab68a4f..aacfdd431 100644 --- a/crates/reims-vgpu/src/graphics/decode/mod.rs +++ b/crates/reims-vgpu/src/graphics/decode/mod.rs @@ -1417,7 +1417,7 @@ impl GraphicsDecoder

{ Ok(Some(Err(why))) => { self.uncache_surface(device, pages.block_offset); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:? = why; "the IOSurface block of {:#x} bytes at {:#x}: no view of its {:#x} bytes in \ {} runs ({why:?}); the surface takes a copy block", pages.block_size, pages.block_offset, pages.length, runs.len() @@ -1427,7 +1427,7 @@ impl GraphicsDecoder

{ Err(raise) => { self.uncache_surface(device, pages.block_offset); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block of {:#x} bytes at {:#x}: the platform raised at the \ buffer over its view ({raise:?}); the surface takes a copy block", pages.block_size, pages.block_offset @@ -1587,7 +1587,7 @@ impl GraphicsDecoder

{ Ok(false) => RGFX_STATUS_REFUSED, Err(raise) => { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block at {block:#x}: the platform raised at its \ deferred device cache ({raise:?}); its pages are named instead" ); @@ -1663,7 +1663,7 @@ impl GraphicsDecoder

{ match taken { Some(Some(true)) => { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = why; "the IOSurface block at {block:#x}: its deferred device cache took its {} \ runs copied, the host's CPU moving its bytes: {why}", runs.len() @@ -1675,7 +1675,7 @@ impl GraphicsDecoder

{ } } log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = why; "the IOSurface block at {block:#x}: its deferred device cache took none of its {} \ runs: {why}; the cache keeps its bytes, its pages not named", runs.len() @@ -1804,7 +1804,7 @@ impl GraphicsDecoder

{ {length:#x} bytes; its buffers lie over its pages" ), Err(raise) => log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block at {block:#x}: the platform raised at its device cache \ ({raise:?}); its buffers lie over its pages" ), @@ -1865,12 +1865,12 @@ impl GraphicsDecoder

{ self.shared.surface_worker.drop_later(block, block, import); } Ok(Err(why)) => log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:? = why; "the IOSurface block at {block:#x}: no device cache, and no view of its pages \ ({why:?}); its buffers are refused" ), Err(raise) => log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block at {block:#x}: no device cache, and the platform raised at \ the buffer over its view ({raise:?}); its buffers are refused" ), @@ -1885,7 +1885,7 @@ impl GraphicsDecoder

{ } if let Err(raise) = self.surface_caches.released(device, block, Box::new(|| {})) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block at {block:#x}: the platform raised at the copy of its device \ cache into its pages ({raise:?})" ); @@ -1962,7 +1962,7 @@ impl GraphicsDecoder

{ slow.fetch_add(1, Ordering::Relaxed); let ran = MonoTime::from_nanos(ran_at.load(Ordering::Relaxed)); log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = what; "the IOSurface block at {block:#x}: a {what} answered {} ms after it was \ asked: {} ms for its SURFACE_PAGES, {} ms behind the command buffers that \ may write its device cache, then {} ms for its copy into the pages", @@ -2116,7 +2116,7 @@ impl GraphicsDecoder

{ && let Err(raise) = refusing(|| release.signal(queue, &self.shared.commit_cancel)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "queue {queue_obj_id:#x}'s surface timeline was ended, and its last signal \ faulted: {raise}" ); @@ -2583,7 +2583,7 @@ impl GraphicsDecoder

{ ObjHandle::SharedEvent(event) => { if let Err(raise) = refusing(|| event.set_signaled_value(u64::MAX)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "context {context}'s shared event {id:#x} was not set past every value at \ its close: {raise}" ); @@ -2624,7 +2624,7 @@ impl GraphicsDecoder

{ close: the platform made no command buffer" ), Err(raise) => log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "context {context}'s {plain} events were not signalled past every value at its \ close: {raise}" ), @@ -2680,7 +2680,7 @@ impl GraphicsDecoder

{ let states = std::mem::take(&mut *shared.contexts.lock()); if let Err(refusal) = refusals::refusing(move || drop(states)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the contexts' tables were let go of at the device's reset, and a release was \ refused: {refusal}" ); @@ -2689,7 +2689,7 @@ impl GraphicsDecoder

{ let cache = shared.libraries.lock().take_cache(); if let Err(refusal) = refusals::refusing(move || drop(cache)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the library cache was let go of at the device's reset, and a release was \ refused: {refusal}" ); @@ -2791,7 +2791,7 @@ impl GraphicsDecoder

{ Ok(sa) => answer(RGFX_STATUS_OK, sa.size, sa.align), Err(raise) => { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "heap texture size of format {}, type {}, {}x{}x{} not answered: {raise}", m.desc.pixel_format, m.desc.texture_type, @@ -2889,7 +2889,7 @@ impl GraphicsDecoder

{ && let Err(raise) = refusing(|| event.set_signaled_value(u64::MAX)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "shared event {:#x}, the last holder of a closed context's, was not set \ past every value at its destroy: {raise}", m.obj_id @@ -3549,7 +3549,7 @@ impl GraphicsDecoder

{ let run = move || { if let Err(raise) = refusing(op) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "{what} of object {obj_id:#x} was not carried out: the platform raised \ ({raise:?})" ); @@ -5180,7 +5180,7 @@ impl Closed

{ && let Err(refusal) = refusals::refusing(move || drop(views)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "context {context}'s pages blocks' views were let go of at its close, and a \ release was refused: {refusal}" ); @@ -5201,7 +5201,7 @@ pub(crate) fn drop_refused(id: u64, value: T) { /// Logs the refused release of object `id` ([`drop_refused`]). fn refused_release(id: u64, refusal: &refusals::Refusal) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "object {id:#x} was let go of, and its release was refused: {refusal}" ); } diff --git a/crates/reims-vgpu/src/graphics/decode/shares.rs b/crates/reims-vgpu/src/graphics/decode/shares.rs index 08a8a37fb..db765ac7c 100644 --- a/crates/reims-vgpu/src/graphics/decode/shares.rs +++ b/crates/reims-vgpu/src/graphics/decode/shares.rs @@ -429,7 +429,7 @@ impl GraphicsDecoder

{ && let Err(raise) = super::refusing(|| event.set_signaled_value(u64::MAX)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "shared event named {:#x} was not set past every value at its last hold's going: \ {raise}", m.name diff --git a/crates/reims-vgpu/src/graphics/decode/surface_cache.rs b/crates/reims-vgpu/src/graphics/decode/surface_cache.rs index 2970e6082..a75d8ed16 100644 --- a/crates/reims-vgpu/src/graphics/decode/surface_cache.rs +++ b/crates/reims-vgpu/src/graphics/decode/surface_cache.rs @@ -1826,7 +1826,7 @@ impl SurfaceCaches

{ } if let Err(raise) = event.set_signaled_value(cache.made) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block at {block:#x}: the platform raised at the set of its device \ cache's new event ({raise:?}); its deferred copies are waited for on the CPU" ); @@ -2014,7 +2014,7 @@ impl SurfaceCaches

{ Ok(made) => made, Err(raise) => { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block at {block:#x}: the platform raised at a fill of \ its device cache made behind the command buffers it waited for \ ({raise:?}); it is not made" @@ -2094,7 +2094,7 @@ impl SurfaceCaches

{ ); if let Err(raise) = event.set_signaled_value(number) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "the IOSurface block at {block:#x}: the platform raised at the set of its \ device cache's event ({raise:?})" ); @@ -2629,7 +2629,7 @@ impl SurfaceCaches

{ } self.counts.behind += 1; log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = message; "the IOSurface block at {block:#x}: a {message} of its device cache, of CPU \ generation {held}, copies nothing: the CPU's generation moved to {cpu} under a lock \ that did not wait for the copy" @@ -2816,7 +2816,7 @@ impl SurfaceCaches

{ } if let Err(refusal) = refusals::refusing(move || drop((caches, ends, deferred))) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the IOSurface device caches were let go of at the device's reset, and a release \ was refused: {refusal}" ); @@ -3178,7 +3178,7 @@ impl Caches

{ refusals::refusing(move || drop((end, made, read_back_end, swept))) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "queue {queue:#x}'s spare end event or transfer queue, or a gone queue's end \ event, was let go of, and its release was refused: {refusal}" ); @@ -3196,7 +3196,7 @@ impl Caches

{ } if let Err(refusal) = refusals::refusing(move || drop(ends)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "queue {queue:#x}'s end event, or another gone queue's, was let go of, and its \ release was refused: {refusal}" ); @@ -3461,7 +3461,7 @@ impl Caches

{ && let Err(refusal) = refusals::refusing(move || drop(spare)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "a device cache's spare event was let go of, and its release was refused: \ {refusal}" ); @@ -3558,7 +3558,7 @@ impl Caches

{ && let Err(raise) = refusing(|| state.early_copies(queue, on, &uses.blocks)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = raise; "queue {queue:#x}: the platform raised at an early copy of a device cache into \ its pages ({raise:?}); the lock that follows downloads it" ); @@ -4241,7 +4241,7 @@ fn copy( cache.pages = Some(CachePages::View(import)); } Err(why) => log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:? = why; "the IOSurface block at {block:#x}: the platform refused a copy by its pages' \ runs, and no view of them was made ({why:?}); the copy is not made" ), diff --git a/crates/reims-vgpu/src/graphics/decode/surface_order.rs b/crates/reims-vgpu/src/graphics/decode/surface_order.rs index 69b078700..971f1fbea 100644 --- a/crates/reims-vgpu/src/graphics/decode/surface_order.rs +++ b/crates/reims-vgpu/src/graphics/decode/surface_order.rs @@ -616,7 +616,7 @@ impl SurfaceOrder

{ && let Err(refusal) = refusals::refusing(move || drop(q.event)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "queue {id:#x}'s surface timeline was let go of, and its release was \ refused: {refusal}" ); @@ -631,7 +631,7 @@ impl SurfaceOrder

{ let queues = std::mem::take(&mut self.queues); if let Err(refusal) = refusals::refusing(move || drop(queues)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the surface timelines were let go of at the device's reset, and a release was \ refused: {refusal}" ); diff --git a/crates/reims-vgpu/src/graphics/decode/surface_pages.rs b/crates/reims-vgpu/src/graphics/decode/surface_pages.rs index ec5a00157..989a073de 100644 --- a/crates/reims-vgpu/src/graphics/decode/surface_pages.rs +++ b/crates/reims-vgpu/src/graphics/decode/surface_pages.rs @@ -1425,7 +1425,7 @@ impl SurfaceViews

{ self.laid_out.clear(); if let Err(refusal) = refusals::refusing(move || drop((views, private, cache))) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the IOSurface views were let go of at the device's reset, and a release was \ refused: {refusal}" ); diff --git a/crates/reims-vgpu/src/graphics/nvidia.rs b/crates/reims-vgpu/src/graphics/nvidia.rs index 7bbfcb24e..457004ea8 100644 --- a/crates/reims-vgpu/src/graphics/nvidia.rs +++ b/crates/reims-vgpu/src/graphics/nvidia.rs @@ -344,7 +344,10 @@ fn supported(gpu: &Gpu, codec: NvdecCodec, bit_depth: u32) -> Option Some(caps), Ok(_) => None, Err(error) => { - log::warn!("hardware video: {NAME}'s caps of {codec:?} at {bit_depth} bits: {error}"); + log::warn!( + kind:% = error; + "hardware video: {NAME}'s caps of {codec:?} at {bit_depth} bits: {error}" + ); None } } diff --git a/crates/reims-vgpu/src/graphics/present.rs b/crates/reims-vgpu/src/graphics/present.rs index 84a811624..2c1244d22 100644 --- a/crates/reims-vgpu/src/graphics/present.rs +++ b/crates/reims-vgpu/src/graphics/present.rs @@ -342,7 +342,7 @@ impl PresentQueue

{ reims_vgpu_vulkan::core::raise::refusals::refusing(move || drop(waiting)) { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refusal; "the presents waiting were dropped at the device's reset, and a texture's release \ was refused: {refusal}" ); diff --git a/crates/reims-vgpu/src/graphics/sink.rs b/crates/reims-vgpu/src/graphics/sink.rs index e2e6903c3..2f5b445ca 100644 --- a/crates/reims-vgpu/src/graphics/sink.rs +++ b/crates/reims-vgpu/src/graphics/sink.rs @@ -166,8 +166,6 @@ pub(crate) struct ScanoutDraw { color_pipelines: Mutex>, /// The colour's buffers, made for the colour of that count of changes. color_buffers: Mutex)>>, - /// Whether a draw was refused yet: the first refusal is logged at WARN ([`Self::scoped`]). - refused: AtomicBool, /// The colour's table last drawn (the module doc). color_table: Mutex>>, /// The ramps the tables of surfaces are drawn from, by pixel format, made at their first use. @@ -458,7 +456,6 @@ impl ScanoutDraw

{ color_functions: std::sync::OnceLock::new(), color_pipelines: Mutex::default(), color_buffers: Mutex::default(), - refused: AtomicBool::new(false), color_table: Mutex::new(None), ramps: Mutex::default(), scanout_ramp: std::sync::OnceLock::new(), @@ -479,18 +476,12 @@ impl ScanoutDraw

{ match refusals::refusing(draw) { Ok(drawn) => drawn, Err(refusal) => { - if self.refused.swap(true, Ordering::AcqRel) { - log::debug!( - target: "reims_vgpu::graphics", - "a draw of the display was refused: {refusal}" - ); - } else { - log::warn!( - target: "reims_vgpu::graphics", - "a draw of the display was refused, and the window keeps the frame it \ - shows: {refusal} (later refusals are logged at debug)" - ); - } + // Once per kind of refusal; later ones at debug, counted (`core::logging`). + log::warn!( + target: "reims_vgpu::graphics", kind:% = refusal; + "a draw of the display was refused, and the window keeps the frame it shows: \ + {refusal}" + ); None } } diff --git a/crates/reims-vgpu/src/graphics/video_host.rs b/crates/reims-vgpu/src/graphics/video_host.rs index 67a9324af..a536c619f 100644 --- a/crates/reims-vgpu/src/graphics/video_host.rs +++ b/crates/reims-vgpu/src/graphics/video_host.rs @@ -858,14 +858,20 @@ fn land_pictures( let mut counts = counts.lock(); counts.failed += 1; if counts.failed <= FAILURES_LOGGED { - log::error!("hardware video: {name}: a picture did not land: {error}"); + log::error!( + kind:% = error; + "hardware video: {name}: a picture did not land: {error}" + ); } } } // The output's holds go, and its bracket ends, before the guest may read it. drop((output, _bitstream)); if let Err(raise) = event.set_signaled_value(value) { - log::error!("hardware video: {name}: the session's signal of {value}: {raise}"); + log::error!( + kind:% = raise; + "hardware video: {name}: the session's signal of {value}: {raise}" + ); } } } diff --git a/crates/reims-vgpu/src/graphics/video_host/encode.rs b/crates/reims-vgpu/src/graphics/video_host/encode.rs index 7876960c0..769e8a17d 100644 --- a/crates/reims-vgpu/src/graphics/video_host/encode.rs +++ b/crates/reims-vgpu/src/graphics/video_host/encode.rs @@ -516,7 +516,10 @@ fn finish_frames( Err(error) => { let failed = counts.lock().frames[2]; if failed < FAILURES_LOGGED { - log::error!("hardware video: {name}: a frame was not encoded: {error}"); + log::error!( + kind:% = error; + "hardware video: {name}: a frame was not encoded: {error}" + ); } let result = RgfxVideoEncodeResult { status: RGFX_VIDEO_ENCODE_FAILED, @@ -550,7 +553,10 @@ fn finish_frames( // The holds go, and the brackets end, before the guest may read them. drop((source, out)); if let Err(raise) = event.set_signaled_value(value) { - log::error!("hardware video: {name}: the session's signal of {value}: {raise}"); + log::error!( + kind:% = raise; + "hardware video: {name}: the session's signal of {value}: {raise}" + ); } } } diff --git a/crates/reims-vgpu/src/graphics/vulkan.rs b/crates/reims-vgpu/src/graphics/vulkan.rs index c2302909f..8d252b784 100644 --- a/crates/reims-vgpu/src/graphics/vulkan.rs +++ b/crates/reims-vgpu/src/graphics/vulkan.rs @@ -53,7 +53,7 @@ impl FrameSink for VulkanScanoutSink { })), Err(refused) => { log::warn!( - target: "reims_vgpu::graphics", + target: "reims_vgpu::graphics", kind:% = refused; "no swapchain for the graphics display's window ({refused}): it stays empty" ); None diff --git a/scripts/internal/lane-gate/msi-boot.sh b/scripts/internal/lane-gate/msi-boot.sh index e500f136e..d85ab9eb7 100755 --- a/scripts/internal/lane-gate/msi-boot.sh +++ b/scripts/internal/lane-gate/msi-boot.sh @@ -74,6 +74,16 @@ START=$(date +%s) T0=$START log() { echo "$(date +%T) $*" | tee -a "$R/boot.log"; } kv() { echo "$1 $2" >> "$R/host.txt"; } +# How many lines of the warning whose message starts with $1 (an ERE) the library wrote into log +# $2: the library writes the first of each kind at warn and the later ones at debug, counting them +# in its line of repeats at each reset and at the exit (docs/conventions.md), " more of +# :[ []] (: )". +warned() { + local first more + first=$(grep -cE " WARN [^ ]+: $1" "$2") + more=$(grep -oE "[0-9]+ more of [^ ]+( \[[^]]*\])? \([^ ]+: $1" "$2" | awk '{ s += $1 } END { print s + 0 }') + echo $((first + more)) +} # The host CPU's heat now: "PKG_C PKG_COUNT PKG_MS CORE_COUNT CORE_MS" (thermal.txt's fields, the # counters the largest over the CPUs), read with the shell's own read, as a sampler does it once a # second over 30-odd CPUs. @@ -218,7 +228,7 @@ finish() { # whose runs were not all carried out. kv queues_unshared "$(grep -c 'made unshared' "$B/launch.log")" kv submit_room_posted "$(grep -c 'SUBMIT_ROOM posted' "$B/launch.log")" - kv icb_slots_refused "$(grep -c 'ICB_SLOTS of .* not carried out' "$B/launch.log")" + kv icb_slots_refused "$(warned 'ICB_SLOTS of' "$B/launch.log")" # The boot's hold of host quiet: HOST_QUIET where no build ran beside QEMU, HOST_NOT_QUIET where # the wait for running builds ran out (msi-launch.sh). case $(grep -m1 -o -E 'HOST_(NOT_)?QUIET' "$B/launch.log") in