memscope_rs/query/
presets.rs1use super::types::Query;
8
9pub struct QueryPresets;
11
12impl QueryPresets {
13 pub fn top_allocations_by_size(limit: usize) -> Query {
15 Query::TopAllocationsBySize { limit }
16 }
17
18 pub fn top_allocations_by_count(limit: usize) -> Query {
20 Query::TopAllocationsByCount { limit }
21 }
22
23 pub fn memory_leaks(min_age_ms: u64) -> Query {
25 Query::MemoryLeaks { min_age_ms }
26 }
27
28 pub fn large_allocations(min_size: usize) -> Query {
30 Query::LargeAllocations { min_size }
31 }
32
33 pub fn thread_memory_stats(thread_id: u64) -> Query {
35 Query::ThreadMemoryStats { thread_id }
36 }
37
38 pub fn scope_memory_stats(scope_name: String) -> Query {
40 Query::ScopeMemoryStats { scope_name }
41 }
42
43 pub fn type_memory_stats(type_name: String) -> Query {
45 Query::TypeMemoryStats { type_name }
46 }
47
48 pub fn system_summary() -> Query {
50 Query::Summary
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_top_allocations_by_size() {
60 let query = QueryPresets::top_allocations_by_size(10);
61 assert!(matches!(query, Query::TopAllocationsBySize { limit: 10 }));
62 }
63
64 #[test]
65 fn test_memory_leaks() {
66 let query = QueryPresets::memory_leaks(1000);
67 assert!(matches!(query, Query::MemoryLeaks { min_age_ms: 1000 }));
68 }
69
70 #[test]
71 fn test_large_allocations() {
72 let query = QueryPresets::large_allocations(1024);
73 assert!(matches!(query, Query::LargeAllocations { min_size: 1024 }));
74 }
75}