1 unstable release
Uses old Rust 2015
0.1.0 | Apr 6, 2017 |
---|
#8 in #reply
7KB
120 lines
tokio-timeit-middleware
Time how long it takes your Tokio Service
to send a Service::Response
in
reply to a Service::Request
.
Usage
First, add this to your Cargo.toml:
[dependencies]
tokio-timeit-middleware = { git = "https://github.com/fitzgen/tokio-timeit-middleware" }
Next, add this to your crate:
extern crate tokio_timeit_middleware;
To time your Tokio Service
's request/response times, wrap it in
tokio_timeit_middleware::Timeit
:
let timed_service = Timeit::new(my_tokio_service, Rc::new(|duration| {
println!("Responded to request in {}", duration);
));
lib.rs
:
tokio-timeit-middleware
provides a middleware Tokio Service
called
Timeit
to time how long it takes to reply to a
Service::Request
with a Service::Response
.
The recorded timings are sent to a TimeSink
which may be any smart pointer
type that Deref
s to a function that takes a
time::Duration
and is Clone
.
Example
// Send recorded timings to metrics or logging or whatever...
let time_sink = Rc::new(|timing: time::Duration| {
println!("Replied to a request with a response in {}", timing);
});
// Wrap a service in `Timeit`!
let my_timed_service = tokio_timeit_middleware::Timeit::new(my_tokio_service, time_sink);
Dependencies
~0.7–1MB
~15K SLoC