增加观测日志

This commit is contained in:
xiuting.xu
2026-05-13 16:49:10 +08:00
parent ad76745619
commit a11f2bc864
4 changed files with 86 additions and 2 deletions

38
src/rtr/cache/core.rs vendored
View File

@@ -651,6 +651,44 @@ pub enum SerialResult {
ResetRequired,
}
#[derive(Debug, Clone, Copy)]
pub struct CacheMemoryStats {
pub serials: [u32; VERSION_COUNT],
pub snapshot_payload_counts: [usize; VERSION_COUNT],
pub delta_lengths: [usize; VERSION_COUNT],
pub delta_payload_counts: [usize; VERSION_COUNT],
pub snapshot_arc_strong_counts: [usize; VERSION_COUNT],
pub rtr_payloads_arc_strong_counts: [usize; VERSION_COUNT],
}
impl RtrCache {
pub fn memory_stats(&self) -> CacheMemoryStats {
let snapshot_payload_counts =
std::array::from_fn(|idx| self.versions[idx].rtr_payloads.len());
let delta_lengths = std::array::from_fn(|idx| self.versions[idx].deltas.len());
let delta_payload_counts = std::array::from_fn(|idx| {
self.versions[idx]
.deltas
.iter()
.map(|delta| delta.announced().len() + delta.withdrawn().len())
.sum()
});
let snapshot_arc_strong_counts =
std::array::from_fn(|idx| Arc::strong_count(&self.versions[idx].snapshot));
let rtr_payloads_arc_strong_counts =
std::array::from_fn(|idx| Arc::strong_count(&self.versions[idx].rtr_payloads));
CacheMemoryStats {
serials: self.serials(),
snapshot_payload_counts,
delta_lengths,
delta_payload_counts,
snapshot_arc_strong_counts,
rtr_payloads_arc_strong_counts,
}
}
}
#[derive(Clone)]
pub(super) struct AppliedUpdate {
pub(super) availability: CacheAvailability,

View File

@@ -3,7 +3,9 @@ mod model;
mod ordering;
mod store;
pub use core::{CacheAvailability, RtrCache, RtrCacheBuilder, SerialResult, SessionIds};
pub use core::{
CacheAvailability, CacheMemoryStats, RtrCache, RtrCacheBuilder, SerialResult, SessionIds,
};
pub use model::{Delta, DualTime, Snapshot};
pub use ordering::{
OrderingViolation, validate_payload_update_refs_for_rtr, validate_payload_updates_for_rtr,

View File

@@ -13,4 +13,8 @@ impl RtrNotifier {
pub fn notify_cache_updated(&self) -> usize {
self.tx.send(()).unwrap_or_default()
}
pub fn listener_count(&self) -> usize {
self.tx.receiver_count()
}
}