mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
Gather memory usage statistics through parity-util-mem (#3893)
* Gather memory usage statistics through `parity-util-mem` * Update `Cargo.lock`
This commit is contained in:
@@ -108,8 +108,7 @@ use polkadot_node_metrics::{
|
||||
Metronome,
|
||||
};
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
use polkadot_node_metrics::memory_stats::MemoryAllocationTracker;
|
||||
use parity_util_mem::MemoryAllocationTracker;
|
||||
|
||||
pub use polkadot_overseer_gen as gen;
|
||||
pub use polkadot_overseer_gen::{
|
||||
@@ -649,28 +648,39 @@ where
|
||||
}
|
||||
let subsystem_meters = overseer.map_subsystems(ExtractNameAndMeters);
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
let memory_stats = MemoryAllocationTracker::new().expect("Jemalloc is the default allocator. qed");
|
||||
let memory_stats = match MemoryAllocationTracker::new() {
|
||||
Ok(memory_stats) => Some(memory_stats),
|
||||
Err(error) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
"Failed to initialize memory allocation tracker: {:?}",
|
||||
error
|
||||
);
|
||||
|
||||
None
|
||||
},
|
||||
};
|
||||
|
||||
let metronome_metrics = metrics.clone();
|
||||
let metronome =
|
||||
Metronome::new(std::time::Duration::from_millis(950)).for_each(move |_| {
|
||||
#[cfg(feature = "memory-stats")]
|
||||
match memory_stats.snapshot() {
|
||||
Ok(memory_stats_snapshot) => {
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
"memory_stats: {:?}",
|
||||
&memory_stats_snapshot
|
||||
);
|
||||
metronome_metrics.memory_stats_snapshot(memory_stats_snapshot);
|
||||
},
|
||||
if let Some(ref memory_stats) = memory_stats {
|
||||
match memory_stats.snapshot() {
|
||||
Ok(memory_stats_snapshot) => {
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
"memory_stats: {:?}",
|
||||
&memory_stats_snapshot
|
||||
);
|
||||
metronome_metrics.memory_stats_snapshot(memory_stats_snapshot);
|
||||
},
|
||||
|
||||
Err(e) => tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
"Failed to obtain memory stats: {:?}",
|
||||
e
|
||||
),
|
||||
Err(e) => tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
"Failed to obtain memory stats: {:?}",
|
||||
e
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// We combine the amount of messages from subsystems to the overseer
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
use super::*;
|
||||
pub use polkadot_node_metrics::metrics::{self, prometheus, Metrics as MetricsTrait};
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
use polkadot_node_metrics::MemoryAllocationSnapshot;
|
||||
use parity_util_mem::MemoryAllocationSnapshot;
|
||||
|
||||
/// Overseer Prometheus metrics.
|
||||
#[derive(Clone)]
|
||||
@@ -35,10 +34,7 @@ struct MetricsInner {
|
||||
signals_sent: prometheus::GaugeVec<prometheus::U64>,
|
||||
signals_received: prometheus::GaugeVec<prometheus::U64>,
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
memory_stats_resident: prometheus::Gauge<prometheus::U64>,
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
memory_stats_allocated: prometheus::Gauge<prometheus::U64>,
|
||||
}
|
||||
|
||||
@@ -65,13 +61,10 @@ impl Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
pub(crate) fn memory_stats_snapshot(&self, memory_stats: MemoryAllocationSnapshot) {
|
||||
if let Some(metrics) = &self.0 {
|
||||
let MemoryAllocationSnapshot { resident, allocated } = memory_stats;
|
||||
|
||||
metrics.memory_stats_allocated.set(allocated);
|
||||
metrics.memory_stats_resident.set(resident);
|
||||
metrics.memory_stats_allocated.set(memory_stats.allocated);
|
||||
metrics.memory_stats_resident.set(memory_stats.resident);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +195,6 @@ impl MetricsTrait for Metrics {
|
||||
registry,
|
||||
)?,
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
memory_stats_allocated: prometheus::register(
|
||||
prometheus::Gauge::<prometheus::U64>::new(
|
||||
"memory_allocated",
|
||||
@@ -210,8 +202,6 @@ impl MetricsTrait for Metrics {
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
|
||||
#[cfg(feature = "memory-stats")]
|
||||
memory_stats_resident: prometheus::register(
|
||||
prometheus::Gauge::<prometheus::U64>::new(
|
||||
"memory_resident",
|
||||
|
||||
Reference in New Issue
Block a user