Skip to main content

memscope_rs/query/
types.rs

1//! Query types - Data structures for query results
2//!
3//! This module defines the data structures used for query results.
4
5use crate::snapshot::types::{ActiveAllocation, ThreadMemoryStats};
6use serde::{Deserialize, Serialize};
7
8/// Query type enumeration
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub enum Query {
11    /// Top allocations by size
12    TopAllocationsBySize { limit: usize },
13    /// Top allocations by count
14    TopAllocationsByCount { limit: usize },
15    /// Memory leaks
16    MemoryLeaks { min_age_ms: u64 },
17    /// Large allocations
18    LargeAllocations { min_size: usize },
19    /// Thread memory statistics
20    ThreadMemoryStats { thread_id: u64 },
21    /// Scope memory statistics
22    ScopeMemoryStats { scope_name: String },
23    /// Type memory statistics
24    TypeMemoryStats { type_name: String },
25    /// System summary
26    Summary,
27}
28
29/// Query result type
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub enum QueryResult {
32    /// Allocation query result
33    Allocations(AllocationQueryResult),
34    /// Thread query result
35    Threads(ThreadQueryResult),
36    /// Summary query result
37    Summary(SummaryQueryResult),
38    /// Empty result
39    Empty,
40}
41
42/// Result of an allocation query
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct AllocationQueryResult {
45    /// Number of allocations in the result
46    pub count: usize,
47    /// Total bytes
48    pub total_bytes: usize,
49    /// The allocations
50    pub allocations: Vec<ActiveAllocation>,
51}
52
53/// Result of a thread query
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct ThreadQueryResult {
56    /// Number of threads in the result
57    pub count: usize,
58    /// Total bytes across all threads
59    pub total_bytes: usize,
60    /// Thread statistics
61    pub threads: Vec<ThreadMemoryStats>,
62}
63
64/// Result of a summary query
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct SummaryQueryResult {
67    /// Total number of allocations
68    pub total_allocations: usize,
69    /// Total number of deallocations
70    pub total_deallocations: usize,
71    /// Number of active allocations
72    pub active_allocations: usize,
73    /// Total bytes allocated
74    pub total_allocated: usize,
75    /// Total bytes deallocated
76    pub total_deallocated: usize,
77    /// Current memory usage
78    pub current_memory: usize,
79    /// Peak memory usage
80    pub peak_memory: usize,
81    /// Number of threads
82    pub thread_count: usize,
83}