mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 09:04:59 +08:00
Switch to a single view indicating current usage
This commit is contained in:
parent
879aa786a5
commit
ef49ae7d6f
@ -133,6 +133,14 @@ impl MemoryStats {
|
|||||||
bytes_reallocated: self.bytes_reallocated.checked_sub(other.bytes_reallocated)?,
|
bytes_reallocated: self.bytes_reallocated.checked_sub(other.bytes_reallocated)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn usage(&self) -> isize {
|
||||||
|
(self.bytes_allocated - self.bytes_deallocated) as isize + self.bytes_reallocated
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn operations(&self) -> usize {
|
||||||
|
self.allocations + self.deallocations + self.reallocations
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||||
|
@ -148,20 +148,14 @@ pub fn to_firefox_profile<R: std::io::Read>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct MemoryCounterHandles {
|
struct MemoryCounterHandles {
|
||||||
allocations: CounterHandle,
|
usage: CounterHandle,
|
||||||
deallocations: CounterHandle,
|
|
||||||
reallocations: CounterHandle,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryCounterHandles {
|
impl MemoryCounterHandles {
|
||||||
fn new(profile: &mut Profile, main: ProcessHandle) -> Self {
|
fn new(profile: &mut Profile, main: ProcessHandle) -> Self {
|
||||||
let allocations =
|
let usage =
|
||||||
profile.add_counter(main, "mimmalloc", "Memory", "Amount of allocated memory");
|
profile.add_counter(main, "mimmalloc", "Memory", "Amount of memory currently in use");
|
||||||
let deallocations =
|
Self { usage }
|
||||||
profile.add_counter(main, "mimmalloc", "Memory", "Amount of deallocated memory");
|
|
||||||
let reallocations =
|
|
||||||
profile.add_counter(main, "mimmalloc", "Memory", "Amount of reallocated memory");
|
|
||||||
Self { allocations, deallocations, reallocations }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,51 +165,23 @@ fn add_memory_samples(
|
|||||||
memory: Option<MemoryStats>,
|
memory: Option<MemoryStats>,
|
||||||
last_timestamp: Timestamp,
|
last_timestamp: Timestamp,
|
||||||
memory_counters: &mut Option<MemoryCounterHandles>,
|
memory_counters: &mut Option<MemoryCounterHandles>,
|
||||||
current_memory: &mut MemoryStats,
|
last_memory: &mut MemoryStats,
|
||||||
) {
|
) {
|
||||||
let Some(stats) = memory else {
|
let Some(stats) = memory else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(MemoryStats {
|
|
||||||
allocations,
|
|
||||||
deallocations,
|
|
||||||
reallocations,
|
|
||||||
bytes_allocated,
|
|
||||||
bytes_deallocated,
|
|
||||||
bytes_reallocated,
|
|
||||||
}) = stats.checked_sub(*current_memory)
|
|
||||||
else {
|
|
||||||
// since spans are recorded out-of-order it is possible they are not always monotonic.
|
|
||||||
// We ignore spans that made no difference.
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let memory_counters =
|
let memory_counters =
|
||||||
memory_counters.get_or_insert_with(|| MemoryCounterHandles::new(profile, main));
|
memory_counters.get_or_insert_with(|| MemoryCounterHandles::new(profile, main));
|
||||||
|
|
||||||
profile.add_counter_sample(
|
profile.add_counter_sample(
|
||||||
memory_counters.allocations,
|
memory_counters.usage,
|
||||||
last_timestamp,
|
last_timestamp,
|
||||||
bytes_allocated as f64,
|
stats.usage() as f64 - last_memory.usage() as f64,
|
||||||
allocations.try_into().unwrap(),
|
stats.operations().checked_sub(last_memory.operations()).unwrap_or_default() as u32,
|
||||||
);
|
);
|
||||||
|
|
||||||
profile.add_counter_sample(
|
*last_memory = stats;
|
||||||
memory_counters.deallocations,
|
|
||||||
last_timestamp,
|
|
||||||
bytes_deallocated as f64,
|
|
||||||
deallocations.try_into().unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
profile.add_counter_sample(
|
|
||||||
memory_counters.reallocations,
|
|
||||||
last_timestamp,
|
|
||||||
bytes_reallocated as f64,
|
|
||||||
reallocations.try_into().unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
*current_memory = stats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_timestamp(time: std::time::Duration) -> Timestamp {
|
fn to_timestamp(time: std::time::Duration) -> Timestamp {
|
||||||
@ -378,9 +344,9 @@ impl<'a> ProfilerMarker for SpanMarker<'a> {
|
|||||||
value["allocations"] = json!(allocations);
|
value["allocations"] = json!(allocations);
|
||||||
value["deallocations"] = json!(deallocations);
|
value["deallocations"] = json!(deallocations);
|
||||||
value["reallocations"] = json!(reallocations);
|
value["reallocations"] = json!(reallocations);
|
||||||
value["bytes_allocated"] = json!(bytes_allocated);
|
value["allocated_bytes"] = json!(bytes_allocated);
|
||||||
value["bytes_deallocated"] = json!(bytes_deallocated);
|
value["deallocated_bytes"] = json!(bytes_deallocated);
|
||||||
value["bytes_reallocated"] = json!(bytes_reallocated);
|
value["reallocated_bytes"] = json!(bytes_reallocated);
|
||||||
}
|
}
|
||||||
|
|
||||||
value
|
value
|
||||||
|
Loading…
Reference in New Issue
Block a user