[][src]Macro metrics::timing

macro_rules! timing {
    ($name:expr, $value:expr) => { ... };
    ($name:expr, $start:expr, $end:expr) => { ... };
    ($name:expr, $start:expr, $end:expr, $($labels:tt)*) => { ... };
    ($name:expr, $value:expr, $($labels:tt)*) => { ... };
}

Records a timing.

This will register an histogram with the given name, if it does not already exist, then add data point with the given timing. This timing must implement AsNanoseconds. Optionally, a set of labels, of the form key => value, can be passed to further describe the histogram.

Functionally equivalent to calling Recorder::record_histogram.

Examples

use metrics::timing;
use std::time::Instant;

fn handle_request() {
    let start = Instant::now();
    process();
    let end = Instant::now();

    // We can pass instances of `Instant` directly:
    timing!("perf.request_processed", start, end);

    // Or we can pass just the delta:
    let delta = end - start;
    timing!("perf.request_processed", delta);

    // And we can even pass unsigned values, both for the start/end notation:
    let start: u64 = 100;
    let end: u64 = 200;
    timing!("perf.request_processed", start, end);

    // And the delta notation:
    let delta: u64 = end - start;
    timing!("perf.request_processed", delta);
}

Labels can also be passed along:

use metrics::timing;
use std::time::Instant;

fn handle_request() {
    let start = Instant::now();
    process();
    let end = Instant::now();

    // We can pass instances of `Instant` directly:
    timing!("perf.request_processed", start, end, "service" => "http", "type" => "checkout");

    // Or we can pass just the delta:
    let delta = end - start;
    timing!("perf.request_processed", delta, "service" => "http", "type" => "checkout");

    // And we can even pass unsigned values, both for the start/end notation:
    let start: u64 = 100;
    let end: u64 = 200;
    timing!("perf.request_processed", start, end, "service" => "http", "type" => "checkout");

    // And the delta notation:
    let delta: u64 = end - start;
    timing!("perf.request_processed", delta, "service" => "http", "type" => "checkout");
}