pprof_integration/frameworks/
actix_web.rs

1use actix_web::{get, web, HttpResponse, Responder};
2use crate::profiling::{generate_profile, ProfileParams};
3
4#[get("/debug/pprof/profile")]
5async fn pprof_profile_actix(params: web::Query<ProfileParams>) -> impl Responder {
6    let duration = params.seconds.unwrap_or(30);
7    match generate_profile(duration).await {
8        Ok(body) => HttpResponse::Ok()
9                    .content_type("application/octet-stream")
10                    .append_header(("Content-Disposition", "attachment; filename=\"profile.pb.gz\""))
11                    .body(body),
12        Err(_) => HttpResponse::InternalServerError().finish(),
13    }
14}
15
16pub fn configure(cfg: &mut web::ServiceConfig) {
17    cfg.service(pprof_profile_actix);
18}