mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-17 10:22:56 +00:00
custom jemalloc opts
This commit is contained in:
@@ -11,8 +11,7 @@ use std::{
|
||||
net::TcpListener,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use tikv_jemalloc_ctl::{opt, prof};
|
||||
use tracing::{info, info_span};
|
||||
use tracing::{info, info_span, warn};
|
||||
use utils::http::{
|
||||
endpoint::{self, request_span},
|
||||
error::ApiError,
|
||||
@@ -27,8 +26,8 @@ async fn status_handler(_: Request<Body>) -> Result<Response<Body>, ApiError> {
|
||||
}
|
||||
|
||||
async fn prof_dump(_: Request<Body>) -> Result<Response<Body>, ApiError> {
|
||||
static PROF_MIB: Lazy<prof::dump_mib> =
|
||||
Lazy::new(|| prof::dump::mib().expect("could not create prof.dump MIB"));
|
||||
static PROF_MIB: Lazy<jemalloc::dump_mib> =
|
||||
Lazy::new(|| jemalloc::dump::mib().expect("could not create prof.dump MIB"));
|
||||
static PROF_DIR: Lazy<Utf8TempDir> =
|
||||
Lazy::new(|| camino_tempfile::tempdir().expect("could not create tempdir"));
|
||||
static PROF_FILE: Lazy<Utf8PathBuf> = Lazy::new(|| PROF_DIR.path().join("prof.dump"));
|
||||
@@ -54,16 +53,21 @@ fn make_router(metrics: AppMetrics) -> RouterBuilder<hyper::Body, ApiError> {
|
||||
metrics,
|
||||
}));
|
||||
|
||||
info!(enabled = opt::prof::read().unwrap(), "jemalloc profiling");
|
||||
prof::active::write(true).unwrap();
|
||||
|
||||
endpoint::make_router()
|
||||
let mut router = endpoint::make_router()
|
||||
.get("/metrics", move |r| {
|
||||
let state = state.clone();
|
||||
request_span(r, move |b| prometheus_metrics_handler(b, state))
|
||||
})
|
||||
.get("/v1/status", status_handler)
|
||||
.get("/v1/jemalloc/prof.dump", prof_dump)
|
||||
.get("/v1/status", status_handler);
|
||||
|
||||
let prof_enabled = jemalloc::prof::read().unwrap_or_default();
|
||||
if prof_enabled {
|
||||
warn!("activating jemalloc profiling");
|
||||
jemalloc::active::write(true).unwrap();
|
||||
router = router.get("/v1/jemalloc/prof.dump", prof_dump);
|
||||
}
|
||||
|
||||
router
|
||||
}
|
||||
|
||||
pub async fn task_main(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::{ffi::CStr, marker::PhantomData};
|
||||
|
||||
use measured::{
|
||||
label::NoLabels,
|
||||
@@ -9,7 +9,9 @@ use measured::{
|
||||
text::TextEncoder,
|
||||
LabelGroup, MetricGroup,
|
||||
};
|
||||
use tikv_jemalloc_ctl::{config, epoch, epoch_mib, stats, version};
|
||||
use tikv_jemalloc_ctl::{
|
||||
config, epoch, epoch_mib, raw, stats, version, Access, AsName, MibStr, Name,
|
||||
};
|
||||
|
||||
pub struct MetricRecorder {
|
||||
epoch: epoch_mib,
|
||||
@@ -114,3 +116,59 @@ jemalloc_gauge!(mapped, mapped_mib);
|
||||
jemalloc_gauge!(metadata, metadata_mib);
|
||||
jemalloc_gauge!(resident, resident_mib);
|
||||
jemalloc_gauge!(retained, retained_mib);
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct dump;
|
||||
|
||||
impl dump {
|
||||
pub fn mib() -> tikv_jemalloc_ctl::Result<dump_mib> {
|
||||
Ok(dump_mib(b"prof.dump\0".as_slice().name().mib_str()?))
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct dump_mib(pub MibStr<[usize; 2]>);
|
||||
|
||||
impl dump_mib {
|
||||
pub fn write(self, value: &'static CStr) -> tikv_jemalloc_ctl::Result<()> {
|
||||
// No support for Access<CStr> yet.
|
||||
// self.0.write(value)
|
||||
let mib = [self.0[0], self.0[1]];
|
||||
raw::write_str_mib(&mib, value.to_bytes_with_nul())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct active;
|
||||
|
||||
impl active {
|
||||
pub fn name() -> &'static Name {
|
||||
b"prof.active\0".as_slice().name()
|
||||
}
|
||||
}
|
||||
|
||||
impl active {
|
||||
pub fn read() -> tikv_jemalloc_ctl::Result<bool> {
|
||||
Self::name().read()
|
||||
}
|
||||
pub fn write(value: bool) -> tikv_jemalloc_ctl::Result<()> {
|
||||
Self::name().write(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct prof;
|
||||
|
||||
impl prof {
|
||||
pub fn name() -> &'static Name {
|
||||
b"opt.prof\0".as_slice().name()
|
||||
}
|
||||
}
|
||||
|
||||
impl prof {
|
||||
pub fn read() -> tikv_jemalloc_ctl::Result<bool> {
|
||||
Self::name().read()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user