span-timing 0.1.1

A small, dependency-free crate for recording named scope durations in caller-owned counters
Documentation
  • Coverage
  • 84.62%
    11 out of 13 items documented2 out of 9 items with examples
  • Size
  • Source code size: 18.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 295.51 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • luketpeterson/span-timing
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • luketpeterson

span-timing

span-timing is a small, dependency-free crate for recording named scope durations in caller-owned counters.

It is useful for low-overhead instrumentation when a full profiling system is unnecessary or unavailable. timing_entries! associates a fixed set of named operations with an array of counters, and timed_span! measures a scope and delegates aggregation to each counter's TimingCounter implementation. The crate supplies Counter for count-and-total-tick measurements, while custom counter types can perform custom aggregation behavior.

Usage

use span_timing::{Counter, timed_span, timing_entries};

// Set up the entries to record results for the spans we want to measure
timing_entries! {
    pub enum Entry {
        Func1,
        Func2,
    }
    pub static COUNTERS: [Counter];
}

fn func1() {
    let _timed_span_guard = timed_span!(Entry::Func1, COUNTERS);
    // Code in the rest of this scope is timed.
}

no_std

Disable the default std feature to use span-timing in no_std applications. This is supported on x86, x86_64, and aarch64 targets; other targets need the default std feature for its Instant-based clock fallback.

The built-in Counter struct requires 64-bit atomics, but custom TimingCounter types can use target-appropriate primitives.

Acknowledgements

This work was initially created by Igor Malovitsa in the PathMap repository.

Alternatives

scopetime logs each scope's duration through the log facade. Prefer scopetime when individual measurements should flow through an application's existing logger and its configured output, filters, and sinks. Emitting a log record for every measured scope is much heavier-weight than updating in-memory atomic counters, so prefer span-timing when aggregate counts and elapsed ticks are sufficient.