krabka_telemetry/profiling.rs
1//! In-process profiling admin server.
2//!
3//! On Unix targets, the server always serves a CPU pprof profile at
4//! `GET /debug/pprof/profile?seconds=N`. With the `heap-profiling` feature,
5//! which needs jemalloc, the server also serves a heap pprof profile at
6//! `GET /debug/pprof/heap`. Grafana Alloy `pyroscope.scrape` scrapes both. The
7//! same admin server can carry more routes, for example `/metrics`.
8//!
9//! The bodies are gzipped `Profile` protobufs. This is the standard pprof file
10//! format, and it is what Go's net/http/pprof serves. Alloy's
11//! `pyroscope.scrape` forwards the scraped bytes without a change as the push
12//! API's `raw_profile`, and the ingester gunzips them. An uncompressed
13//! protobuf body makes that gunzip fail with "invalid gzip header".
14//!
15//! CPU profiling uses POSIX signals, so it is available only on Unix. On
16//! non-Unix targets the server returns a 503 stub, and the crate thus compiles
17//! on all platforms. On `wasm32-wasip1` there is no server at all, because the
18//! admin server binds its own socket: the module exports only the
19//! configuration types there.
20
21mod config;
22#[cfg(not(target_family = "wasm"))]
23mod routes;
24#[cfg(not(target_family = "wasm"))]
25mod server;
26
27pub use self::config::{ProfilingConfig, ProfilingError, ProfilingSampleFrequency};
28#[cfg(not(target_family = "wasm"))]
29pub use self::{
30 routes::{pprof_router, pprof_router_with_config},
31 server::{
32 await_admin_exit, serve_admin, serve_admin_from_env, serve_admin_from_env_with,
33 serve_admin_from_env_with_config, serve_admin_with_config,
34 spawn_admin_from_env_with_config, spawn_admin_with_config,
35 },
36};