mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 00:11:01 +00:00
Introduce jemalloc-allocator feature flag (#6675)
* Introduce jemalloc-stats feature flag * remove unneeded space * Update node/overseer/src/lib.rs Co-authored-by: Marcin S. <marcin@bytedude.com> * Update Cargo.toml Co-authored-by: Marcin S. <marcin@bytedude.com> * revert making tikv-jemallocator depend on jemalloc-stats * conditionally import memory_stats instead of using dead_code * fix test via expllicit import * Add jemalloc-stats feature to crates, propagate it from root * Apply `jemalloc-stats` feature to prepare mem stats; small refactor * effect changes recommended on PR * Update node/overseer/src/metrics.rs Co-authored-by: Marcin S. <marcin@bytedude.com> * fix compile error on in pipeline for linux. missing import * Update node/overseer/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * revert to defining collect_memory_stats inline --------- Co-authored-by: Marcin S. <marcin@bytedude.com> Co-authored-by: Marcin S <marcin@realemail.net> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -117,14 +117,13 @@ pub const KNOWN_LEAVES_CACHE_SIZE: NonZeroUsize = match NonZeroUsize::new(2 * 24
|
||||
None => panic!("Known leaves cache size must be non-zero"),
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
|
||||
mod memory_stats;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use sp_core::traits::SpawnNamed;
|
||||
|
||||
use memory_stats::MemoryAllocationTracker;
|
||||
|
||||
/// Glue to connect `trait orchestra::Spawner` and `SpawnNamed` from `substrate`.
|
||||
pub struct SpawnGlue<S>(pub S);
|
||||
|
||||
@@ -654,8 +653,9 @@ where
|
||||
}
|
||||
let subsystem_meters = overseer.map_subsystems(ExtractNameAndMeters);
|
||||
|
||||
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
|
||||
let collect_memory_stats: Box<dyn Fn(&OverseerMetrics) + Send> =
|
||||
match MemoryAllocationTracker::new() {
|
||||
match memory_stats::MemoryAllocationTracker::new() {
|
||||
Ok(memory_stats) =>
|
||||
Box::new(move |metrics: &OverseerMetrics| match memory_stats.snapshot() {
|
||||
Ok(memory_stats_snapshot) => {
|
||||
@@ -679,6 +679,9 @@ where
|
||||
},
|
||||
};
|
||||
|
||||
#[cfg(not(any(target_os = "linux", feature = "jemalloc-allocator")))]
|
||||
let collect_memory_stats: Box<dyn Fn(&OverseerMetrics) + Send> = Box::new(|_| {});
|
||||
|
||||
let metronome = Metronome::new(std::time::Duration::from_millis(950)).for_each(move |_| {
|
||||
collect_memory_stats(&metronome_metrics);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use tikv_jemalloc_ctl::{epoch, stats, Error};
|
||||
use tikv_jemalloc_ctl::stats;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MemoryAllocationTracker {
|
||||
@@ -24,15 +24,15 @@ pub struct MemoryAllocationTracker {
|
||||
}
|
||||
|
||||
impl MemoryAllocationTracker {
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
pub fn new() -> Result<Self, tikv_jemalloc_ctl::Error> {
|
||||
Ok(Self {
|
||||
epoch: epoch::mib()?,
|
||||
epoch: tikv_jemalloc_ctl::epoch::mib()?,
|
||||
allocated: stats::allocated::mib()?,
|
||||
resident: stats::resident::mib()?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn snapshot(&self) -> Result<MemoryAllocationSnapshot, Error> {
|
||||
pub fn snapshot(&self) -> Result<MemoryAllocationSnapshot, tikv_jemalloc_ctl::Error> {
|
||||
// update stats by advancing the allocation epoch
|
||||
self.epoch.advance()?;
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
use super::*;
|
||||
pub use polkadot_node_metrics::metrics::{self, prometheus, Metrics as MetricsTrait};
|
||||
|
||||
use memory_stats::MemoryAllocationSnapshot;
|
||||
|
||||
/// Overseer Prometheus metrics.
|
||||
#[derive(Clone)]
|
||||
struct MetricsInner {
|
||||
@@ -40,7 +38,9 @@ struct MetricsInner {
|
||||
signals_sent: prometheus::GaugeVec<prometheus::U64>,
|
||||
signals_received: prometheus::GaugeVec<prometheus::U64>,
|
||||
|
||||
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
|
||||
memory_stats_resident: prometheus::Gauge<prometheus::U64>,
|
||||
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
|
||||
memory_stats_allocated: prometheus::Gauge<prometheus::U64>,
|
||||
}
|
||||
|
||||
@@ -67,7 +67,11 @@ impl Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn memory_stats_snapshot(&self, memory_stats: MemoryAllocationSnapshot) {
|
||||
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
|
||||
pub(crate) fn memory_stats_snapshot(
|
||||
&self,
|
||||
memory_stats: memory_stats::MemoryAllocationSnapshot,
|
||||
) {
|
||||
if let Some(metrics) = &self.0 {
|
||||
metrics.memory_stats_allocated.set(memory_stats.allocated as u64);
|
||||
metrics.memory_stats_resident.set(memory_stats.resident as u64);
|
||||
@@ -246,7 +250,7 @@ impl MetricsTrait for Metrics {
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
|
||||
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
|
||||
memory_stats_allocated: prometheus::register(
|
||||
prometheus::Gauge::<prometheus::U64>::new(
|
||||
"polkadot_memory_allocated",
|
||||
@@ -254,6 +258,7 @@ impl MetricsTrait for Metrics {
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
|
||||
memory_stats_resident: prometheus::register(
|
||||
prometheus::Gauge::<prometheus::U64>::new(
|
||||
"polkadot_memory_resident",
|
||||
|
||||
Reference in New Issue
Block a user