Skip to main content

Module cpu_time

Module cpu_time 

Source
Expand description

Per-component CPU-time measurement primitives.

This module provides the building blocks for attributing CPU time to individual Vector components at runtime:

  • ThreadTime — a lightweight snapshot of thread CPU time, backed by CLOCK_THREAD_CPUTIME_ID on Linux/macOS, GetThreadTimes on Windows, and a zero no-op on other platforms.
  • CpuTimedFuture / CpuTimedExt — a Future adapter that brackets every poll call with a ThreadTime sample and accumulates the delta into a [metrics::Counter].
  • spawn_timed — convenience wrapper that spawns a future on the current tokio runtime with optional CPU-time accounting attached.
  • register_counter — registers the component_cpu_usage_ns_total metrics counter for a component (available on Linux, macOS, and Windows only).

Structs§

CpuTimedFuture
A Future adapter that accumulates thread CPU time across every poll.
ThreadTime
An opaque snapshot of thread CPU time.

Traits§

CpuTimedExt
Extension trait that wraps a future in CpuTimedFuture via a chained call:

Functions§

register_counter
Registers the component_cpu_usage_ns_total counter for the calling component on platforms where thread CPU time is available (Linux, macOS, Windows). On other platforms it returns [Counter::noop()] — the metric is not emitted at all, rather than reporting wall-clock or zero values that would be misleading to compare against supported platforms.
spawn_timed
Spawns future on the current tokio runtime, attaching CPU-time accounting when counter is Some. When None, the future is spawned as-is with no per-poll overhead.