use super::types::Query;
pub struct QueryPresets;
impl QueryPresets {
pub fn top_allocations_by_size(limit: usize) -> Query {
Query::TopAllocationsBySize { limit }
}
pub fn top_allocations_by_count(limit: usize) -> Query {
Query::TopAllocationsByCount { limit }
}
pub fn memory_leaks(min_age_ms: u64) -> Query {
Query::MemoryLeaks { min_age_ms }
}
pub fn large_allocations(min_size: usize) -> Query {
Query::LargeAllocations { min_size }
}
pub fn thread_memory_stats(thread_id: u64) -> Query {
Query::ThreadMemoryStats { thread_id }
}
pub fn scope_memory_stats(scope_name: String) -> Query {
Query::ScopeMemoryStats { scope_name }
}
pub fn type_memory_stats(type_name: String) -> Query {
Query::TypeMemoryStats { type_name }
}
pub fn system_summary() -> Query {
Query::Summary
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_top_allocations_by_size() {
let query = QueryPresets::top_allocations_by_size(10);
assert!(matches!(query, Query::TopAllocationsBySize { limit: 10 }));
}
#[test]
fn test_memory_leaks() {
let query = QueryPresets::memory_leaks(1000);
assert!(matches!(query, Query::MemoryLeaks { min_age_ms: 1000 }));
}
#[test]
fn test_large_allocations() {
let query = QueryPresets::large_allocations(1024);
assert!(matches!(query, Query::LargeAllocations { min_size: 1024 }));
}
}