Crates.io | micrometer |
lib.rs | micrometer |
version | 0.2.7 |
source | src |
created_at | 2023-02-27 09:16:05.13705 |
updated_at | 2023-10-24 13:21:31.050439 |
description | Profiling for fast, high frequency events in multithreaded applications with low overhead |
homepage | |
repository | https://github.com/imDema/micrometer-rs |
max_upload_size | |
id | 795807 |
size | 46,742 |
Profiling for fast, high frequency events in multithreaded applications with low overhead
By default every measure is a no-op, to measure and consume measures, enable the enable
feature. This is done to allow libs to instrument their code without runitme costs if
no one is using the measures.
micrometer
is intended for multithreaded environments, each
location may be relevant for multiple threads, the location in the context of a specific
thread is referred to as thread locationSpan
: a span is a guard object that measures the time between when it was created
and when it was dropped (unless it was disarmed). Each span will produce one measurementTrack
: a track is the struct responsible of handling all measurements originating
from a thread location. It is used to create spans or manually record the duration of an
event.TrackPoint
: while a track maps to the concept of thread location (as a single track
can only be owned by one thread), a track point maps to the concept of location. The
track point struct is a lazily allocated, thread local handle to multiple tracks that are
associated with the same name. Usually, track points are used as static variables, using
the get_or_init
method to get the track for the active thread.for _ in 0..100 {
// Define a `TrackPoint` named "loop_duration", get (or init) the `Track` for the
// current thread, then create a span and assign it to a new local variable called
// `loop_duration`
micrometer::span!(loop_duration);
std::hint::black_box("do something");
// `loop_duration` is automatically dropped recording the measure
}
// Print a summary of the measurements
micrometer::summary();
std::thread::scope(|s| {
for t in 1..=4 {
s.spawn(move || {
for _ in 0..(10 * t) {
micrometer::span!(); // Name automatically assigned to source file and line
std::hint::black_box("do something");
}
});
}
});
// Print a summary of the measurements
micrometer::summary();
// Print a summary of the measurements, aggregating measures for the same location
micrometer::summary_grouped();
// This works like the `dbg!` macro, allowing you to transparently wrap an expression:
// a span is created, the expression is executed, then the span is closed and the result
// of the expression is passed along
let a = micrometer::span!(5 * 5, "fives_sq");
let b = micrometer::span!(a * a); // Name automatically assigned to source file and line
assert_eq!(a, 25);
assert_eq!(b, 25 * 25);
let a = 5;
micrometer::span!(guard, "a_sq");
let b = a * a;
drop(guard); // Measurement stops here
let c = b * a;