pprof_server 0.2.0

A simple pprof server in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use actix_web::{get, web, HttpResponse, Responder};
use crate::profiling::{generate_profile, ProfileParams};

#[get("/debug/pprof/profile")]
async fn pprof_profile_actix(params: web::Query<ProfileParams>) -> impl Responder {
    let duration = params.seconds.unwrap_or(30);
    match generate_profile(duration).await {
        Ok(body) => HttpResponse::Ok()
                    .content_type("application/octet-stream")
                    .append_header(("Content-Disposition", "attachment; filename=\"profile.pb.gz\""))
                    .body(body),
        Err(_) => HttpResponse::InternalServerError().finish(),
    }
}

pub fn configure(cfg: &mut web::ServiceConfig) {
    cfg.service(pprof_profile_actix);
}