Skip to main content

PlatformSampler

Trait PlatformSampler 

Source
pub trait PlatformSampler: Default {
    // Required methods
    fn sample(&mut self) -> (SystemSnapshot, Vec<Row>);
    fn cache_len(&self) -> usize;
    fn backend_name() -> &'static str;

    // Provided methods
    fn set_scan_options(&mut self, _opts: ScanOptions) { ... }
    fn supports_threads() -> bool { ... }
}
Expand description

A unified sampler interface so the front end does not name a backend.

docs/DESIGN.md §5: selection happens at compile time, so this trait exists for genericity in tests and for documentation, not for runtime dispatch in the hot loop.

Required Methods§

Source

fn sample(&mut self) -> (SystemSnapshot, Vec<Row>)

Take one sample: host counters plus one row per process.

Source

fn cache_len(&self) -> usize

Number of cached per-process identity records, for tests and diagnostics.

Source

fn backend_name() -> &'static str

A user-facing name for the backend.

Provided Methods§

Source

fn set_scan_options(&mut self, _opts: ScanOptions)

Tell the sampler what the front end currently needs.

Call this before every sample(). The default implementation ignores it, which is the right behaviour for a backend with no expensive reads.

Source

fn supports_threads() -> bool

Whether this backend can actually enumerate threads.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl PlatformSampler for Sampler

The unified sampler interface.

This was only implemented for the Darwin backend, so on Linux the trait was declared but never satisfied: gander_core::PlatformSampler described an interface that did not exist on the platform where it mattered most, and every use gander_core::PlatformSampler in a Linux-only test was dead (the inherent sample shadowed it). sample and cache_len now exist only on the trait, on both platforms, so a caller cannot accidentally depend on a method that one backend happens to have and the other does not.