mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Replace stats_alloc with procfs
This commit is contained in:
parent
e773dfa9ba
commit
b393823f36
9 changed files with 99 additions and 192 deletions
|
@ -227,8 +227,8 @@ fn add_memory_samples(
|
|||
profile.add_counter_sample(
|
||||
memory_counters.usage,
|
||||
last_timestamp,
|
||||
stats.usage() as f64 - last_memory.usage() as f64,
|
||||
stats.operations().checked_sub(last_memory.operations()).unwrap_or_default() as u32,
|
||||
stats.resident as f64 - last_memory.resident as f64,
|
||||
0,
|
||||
);
|
||||
|
||||
let delta = stats.checked_sub(*last_memory);
|
||||
|
@ -317,39 +317,21 @@ impl<'a> ProfilerMarker for SpanMarker<'a> {
|
|||
searchable: true,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "allocations",
|
||||
label: "Number of allocation operations while this function was executing",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "deallocations",
|
||||
label: "Number of deallocation operations while this function was executing",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "reallocations",
|
||||
label: "Number of reallocation operations while this function was executing",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "allocated_bytes",
|
||||
label: "Number of allocated bytes while this function was executing",
|
||||
key: "resident",
|
||||
label: "Resident set size, measured in bytes while this function was executing",
|
||||
format: MarkerFieldFormat::Bytes,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "deallocated_bytes",
|
||||
label: "Number of deallocated bytes while this function was executing",
|
||||
key: "shared",
|
||||
label: "Number of resident shared pages (i.e., backed by a file) while this function was executing",
|
||||
format: MarkerFieldFormat::Bytes,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "reallocated_bytes",
|
||||
label: "Number of reallocated bytes while this function was executing",
|
||||
format: MarkerFieldFormat::Bytes,
|
||||
key: "oom_score",
|
||||
label: "The current score that the kernel gives to this process for the purpose of selecting a process for the OOM-killer while this function was executing",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
];
|
||||
|
@ -384,21 +366,10 @@ impl<'a> ProfilerMarker for SpanMarker<'a> {
|
|||
"thread_id": thread_id,
|
||||
});
|
||||
|
||||
if let Some(MemoryStats {
|
||||
allocations,
|
||||
deallocations,
|
||||
reallocations,
|
||||
bytes_allocated,
|
||||
bytes_deallocated,
|
||||
bytes_reallocated,
|
||||
}) = self.memory_delta
|
||||
{
|
||||
value["allocations"] = json!(allocations);
|
||||
value["deallocations"] = json!(deallocations);
|
||||
value["reallocations"] = json!(reallocations);
|
||||
value["allocated_bytes"] = json!(bytes_allocated);
|
||||
value["deallocated_bytes"] = json!(bytes_deallocated);
|
||||
value["reallocated_bytes"] = json!(bytes_reallocated);
|
||||
if let Some(MemoryStats { resident, shared, oom_score }) = self.memory_delta {
|
||||
value["resident"] = json!(resident);
|
||||
value["shared"] = json!(shared);
|
||||
value["oom_score"] = json!(oom_score);
|
||||
}
|
||||
|
||||
value
|
||||
|
@ -447,39 +418,21 @@ impl<'a> ProfilerMarker for EventMarker<'a> {
|
|||
searchable: true,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "allocations",
|
||||
label: "Number of allocation operations since last measure",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "deallocations",
|
||||
label: "Number of deallocation operations since last measure",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "reallocations",
|
||||
label: "Number of reallocation operations since last measure",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "allocated_bytes",
|
||||
label: "Number of allocated bytes since last measure",
|
||||
key: "resident",
|
||||
label: "Resident set size, measured in bytes while this function was executing",
|
||||
format: MarkerFieldFormat::Bytes,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "deallocated_bytes",
|
||||
label: "Number of deallocated bytes since last measure",
|
||||
key: "shared",
|
||||
label: "Number of resident shared pages (i.e., backed by a file) while this function was executing",
|
||||
format: MarkerFieldFormat::Bytes,
|
||||
searchable: false,
|
||||
}),
|
||||
MarkerSchemaField::Dynamic(MarkerDynamicField {
|
||||
key: "reallocated_bytes",
|
||||
label: "Number of reallocated bytes since last measure",
|
||||
format: MarkerFieldFormat::Bytes,
|
||||
key: "oom_score",
|
||||
label: "The current score that the kernel gives to this process for the purpose of selecting a process for the OOM-killer while this function was executing",
|
||||
format: MarkerFieldFormat::Integer,
|
||||
searchable: false,
|
||||
}),
|
||||
];
|
||||
|
@ -514,21 +467,10 @@ impl<'a> ProfilerMarker for EventMarker<'a> {
|
|||
"thread_id": thread_id,
|
||||
});
|
||||
|
||||
if let Some(MemoryStats {
|
||||
allocations,
|
||||
deallocations,
|
||||
reallocations,
|
||||
bytes_allocated,
|
||||
bytes_deallocated,
|
||||
bytes_reallocated,
|
||||
}) = self.memory_delta
|
||||
{
|
||||
value["allocations"] = json!(allocations);
|
||||
value["deallocations"] = json!(deallocations);
|
||||
value["reallocations"] = json!(reallocations);
|
||||
value["allocated_bytes"] = json!(bytes_allocated);
|
||||
value["deallocated_bytes"] = json!(bytes_deallocated);
|
||||
value["reallocated_bytes"] = json!(bytes_reallocated);
|
||||
if let Some(MemoryStats { resident, shared, oom_score }) = self.memory_delta {
|
||||
value["resident"] = json!(resident);
|
||||
value["shared"] = json!(shared);
|
||||
value["oom_score"] = json!(oom_score);
|
||||
}
|
||||
|
||||
value
|
||||
|
|
|
@ -188,23 +188,9 @@ fn print_duration(duration: std::time::Duration) -> String {
|
|||
}
|
||||
|
||||
/// Format only the allocated bytes, deallocated bytes and reallocated bytes in GiB, MiB, KiB, Bytes.
|
||||
fn print_memory(memory: MemoryStats) -> String {
|
||||
fn print_memory(MemoryStats { resident, shared, oom_score }: MemoryStats) -> String {
|
||||
use byte_unit::Byte;
|
||||
|
||||
let allocated_bytes = Byte::from_bytes(memory.bytes_allocated.try_into().unwrap());
|
||||
let deallocated_bytes = Byte::from_bytes(memory.bytes_deallocated.try_into().unwrap());
|
||||
|
||||
let reallocated_sign = if memory.bytes_reallocated < 0 { "-" } else { "" };
|
||||
let reallocated_bytes =
|
||||
Byte::from_bytes(memory.bytes_reallocated.abs_diff(0).try_into().unwrap());
|
||||
|
||||
let adjusted_allocated_bytes = allocated_bytes.get_appropriate_unit(true);
|
||||
let adjusted_deallocated_bytes = deallocated_bytes.get_appropriate_unit(true);
|
||||
let adjusted_reallocated_bytes = reallocated_bytes.get_appropriate_unit(true);
|
||||
|
||||
format!(
|
||||
"Allocated {adjusted_allocated_bytes:.2}, \
|
||||
Deallocated {adjusted_deallocated_bytes:.2}, \
|
||||
Reallocated {reallocated_sign}{adjusted_reallocated_bytes:.2}"
|
||||
)
|
||||
let rss_bytes = Byte::from_bytes(resident).get_appropriate_unit(true);
|
||||
let shared_bytes = Byte::from_bytes(shared).get_appropriate_unit(true);
|
||||
format!("RSS {rss_bytes:.2}, Shared {shared_bytes:.2}, OOM score {oom_score}")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue