Skip to main content

register_counter

Function register_counter 

Source
pub fn register_counter() -> Counter
Expand description

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.

Call this inside a tracing span that carries component_id, component_kind, and component_type labels so that those labels are automatically attached to the registered counter by the metrics recorder.

§Using the emitted counter

The counter is cumulative nanoseconds of CPU time. To derive the average number of CPU cores a component consumed over a window:

rate(component_cpu_usage_ns_total{component_id="my_remap"}[1m]) / 1e9

This value can exceed 1.0 when a transform genuinely uses multiple cores (concurrent execution path). Compare against utilization to separate CPU cost from pipeline back-pressure.