#tide #usdt #dtrace #middleware #trace #bpf #dynamically

tide-trace

Minimum overhead USDT middleware to dynamically trace tide with BPF or DTrace

4 releases (breaking)

0.5.0 Jan 31, 2021
0.4.0 Jan 27, 2021
0.3.0 Jul 17, 2020
0.1.1 Jun 28, 2020
0.1.0 Jun 28, 2020

#394 in Unix APIs

Apache-2.0

20KB
119 lines

tide-trace

Minimum overhead USDT middleware to dynamically trace tide with BPF or DTrace.

$ cargo run --example histogram

$ sudo bpftrace -p $(pgrep histogram) tools/route-histogram.bt
Attaching 2 probes...

$ curl http://localhost:8080/route1 && curl http://localhost:8080/route2


^C
@us[GET, /favicon.ico]: 
[32, 64)               1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|

@us[GET, /route1]: 
[32, 64)               2 |@@@@@@@@@@@@@@@@@                                   |
[64, 128)              6 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[128, 256)             2 |@@@@@@@@@@@@@@@@@                                   |

@us[GET, /route2]: 
[32, 64)               2 |@@@@@@@@@@@@@@@@@@@@                                |
[64, 128)              5 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[128, 256)             4 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           |

pre-requisites

linux

ubuntu

$ sudo apt-get install systemtap-sdt-dev bpftrace

fedora

$ sudo dnf install systemtap-sdt-devel bpftrace

mac

This middleware is intended to work on mac but has not been fully tested

$ brew install make 

example usage

For a prebuilt applications see examples folder

Make a project

$ cargo init sample-project

Cargo.toml

tide = "0.16"
async-std = { version = "1.8.0", features = ["attributes"] }
tide-trace = { version = "0.4.0" }

main.rs

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
    tide::log::start();
    let mut app = tide::new();
    app.middleware(tide_trace::USDTMiddleware::new(0));
    app.at("/").get(|_| async { Ok("Hello, world!") });
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}

trace requests

$ sudo bpftrace -p $(pgrep sample-project) tools/routes.bt 
$ curl http://localhost:8080/

tests

$ cargo build --examples 
$ sudo ./tests/test-all.sh

Dependencies

~11–22MB
~335K SLoC