Skip to main content

memscope_rs/capture/types/
mod.rs

1//! Capture types module.
2//!
3//! This module contains all type definitions for the capture engine,
4//! organized into logical submodules for better maintainability.
5//!
6//! # Organization
7//!
8//! Types are organized by their functional area:
9//! - `allocation`: Memory allocation tracking types
10//! - `smart_pointer`: Smart pointer tracking (Rc, Arc, Box)
11//! - `error`: Error types for tracking operations
12//! - `stats`: Memory statistics and analysis
13//! - `scope`: Scope tracking and lifecycle
14//! - `memory_layout`: Memory layout analysis
15//! - `generic`: Generic type tracking
16//! - `dynamic_type`: Dynamic type (trait object) tracking
17//! - `runtime_state`: Runtime state information
18//! - `fragmentation`: Memory fragmentation analysis
19//! - `ownership`: Ownership hierarchy tracking
20//! - `drop_chain`: Drop chain analysis
21//! - `leak_detection`: Memory leak detection
22//! - `timeline`: Timeline visualization types
23//! - `access_tracking`: Memory access pattern tracking
24//! - `stack`: Stack allocation tracking
25//! - `temporary`: Temporary object tracking
26//! - `tracking`: Function call tracking
27
28pub mod access_tracking;
29pub mod allocation;
30pub mod drop_chain;
31pub mod dynamic_type;
32pub mod error;
33pub mod fragmentation;
34pub mod generic;
35pub mod leak_detection;
36pub mod lifecycle;
37pub mod memory_layout;
38pub mod ownership;
39pub mod runtime_state;
40pub mod scope;
41pub mod smart_pointer;
42pub mod stack;
43pub mod stats;
44pub mod temporary;
45pub mod timeline;
46pub mod tracking;
47
48// Re-export common types for convenience
49pub use access_tracking::{
50    AccessPattern, AccessPatternType, AddressRange, BandwidthBottleneck,
51    BandwidthBottleneckLocation, BandwidthUtilization, CacheAccessInfo, CacheLatencyBreakdown,
52    ImplementationDifficulty, LocalityMetrics, MemoryAccessEvent, MemoryAccessPerformanceImpact,
53    MemoryAccessStatistics, MemoryAccessTrackingInfo, MemoryAccessType,
54    MemoryOptimizationRecommendation, MemoryOptimizationType, StridePattern,
55};
56pub use allocation::{
57    AllocationInfo, BorrowInfo, BottleneckType, CloneInfo, ContextPerformanceMetrics, ContextType,
58    HotPath, ImpactLevel, ImplementationDifficulty as AllocImplDifficulty,
59    OptimizationRecommendation, PerformanceBottleneck, PerformanceSnapshot, Priority,
60    RecommendationType, TypePerformanceImpact, TypeUsageInfo, UsageContext, UsageTimePoint,
61};
62pub use drop_chain::{
63    CleanupAction, CleanupActionType, DropBottleneckType, DropChainAnalysis, DropChainNode,
64    DropChainPerformanceMetrics, DropImplementationType, DropPerformanceBottleneck,
65    DropPerformanceCharacteristics,
66};
67pub use dynamic_type::{
68    DispatchOverhead, DynamicTypeInfo, PerformanceImpact, TypeErasureInfo, VTableInfo, VTableMethod,
69};
70pub use error::{TrackingError, TrackingResult};
71pub use fragmentation::{
72    BlockSizeRange, EnhancedFragmentationAnalysis, FragmentationCause, FragmentationCauseType,
73    FragmentationMetrics, FragmentationSeverity,
74};
75pub use generic::{
76    BranchPredictionImpact, CacheImpact, CodeBloatLevel, CompilationImpact, ConcreteTypeParameter,
77    ConstraintType, GenericConstraint, GenericInstantiationInfo, GenericTypeInfo, MemoryImpact,
78    MonomorphizationInfo, OptimizationDifficulty, PerformanceCharacteristics, SourceLocation,
79    TypeCategory, TypeParameter,
80};
81pub use leak_detection::{
82    EnhancedPotentialLeak, LeakEvidence, LeakEvidenceType, LeakImpact,
83    LeakPreventionRecommendation, LeakPreventionType, LeakRiskLevel, LeakType,
84    ResourceLeakAnalysis, ResourcePatternType, ResourceUsagePattern,
85};
86pub use lifecycle::{
87    BorrowState, EventPerformanceMetrics, LifecycleEfficiencyMetrics, LifecycleEvent,
88    LifecycleEventType, LifecyclePattern, LifecyclePatternType, LifecycleStageDurations,
89    MemoryLocationType, MemoryState, ObjectLifecycleInfo, ResourceWasteAssessment,
90    SimpleLifecyclePattern,
91};
92pub use memory_layout::{
93    AccessEfficiency, CapacityUtilization, ContainerAnalysis, ContainerEfficiencyMetrics,
94    ContainerType, FieldLayoutInfo, GrowthPattern, LayoutEfficiency, MemoryLayoutInfo,
95    OptimizationPotential, PaddingAnalysis, PaddingLocation, PaddingReason, ReallocationFrequency,
96    ReallocationPatterns, UtilizationEfficiency,
97};
98pub use ownership::{
99    ChildTypeInfo, CircularReferenceInfo, CircularReferenceType, ComposedTypeInfo, CompositionType,
100    OwnershipHierarchy, OwnershipNode, OwnershipTransferEvent, OwnershipTransferType,
101    OwnershipType, ParentTypeInfo, RelationshipType, TypeRelationshipInfo, WeakReferenceInfo,
102    WeakReferenceType,
103};
104pub use runtime_state::{
105    AllocatorStateInfo, CachePerformanceInfo, CpuUsageInfo, GcInfo, MemoryAccessPattern,
106    MemoryPressureInfo, MemoryPressureLevel, RuntimeStateInfo,
107};
108pub use scope::{
109    AllocationEventType, BorrowEvent, GrowthEvent, GrowthReason, MoveEvent, PotentialLeak,
110    RiskDistribution, ScopeAnalysis, ScopeEventType, ScopeHierarchy, ScopeInfo,
111    ScopeLifecycleMetrics, TypeLifecyclePattern, VariableRelationship,
112};
113pub use smart_pointer::{RefCountSnapshot, SmartPointerInfo, SmartPointerType};
114pub use stack::{ScopeType, StackAllocationInfo, StackScopeInfo};
115pub use stats::{
116    ConcurrencyAnalysis, FragmentationAnalysis as StatsFragmentationAnalysis, LibraryUsage,
117    MemoryStats, MemoryTypeInfo, SystemLibraryStats, TypeMemoryUsage,
118};
119pub use temporary::{CreationContext, ExpressionType, TemporaryObjectInfo, TemporaryUsagePattern};
120pub use timeline::{
121    AllocationEvent, AllocationHotspot, AllocationPattern, HotspotLocation, MemorySnapshot,
122    SafetyViolation, StackFrame, StackTraceData, StackTraceHotspot, TimeRange, TimelineData,
123};
124pub use tracking::{
125    CallPattern, CallPatternType, CallSequence, CallStackInfo, ConcurrencyCharacteristics,
126    DeadlockRisk, FunctionCallTrackingInfo, FunctionMemoryCharacteristics,
127    FunctionPerformanceCharacteristics, IOCharacteristics, LeakPotential, MemoryUsagePattern,
128    RecursionPerformanceImpact, RecursiveCallInfo, StackOverflowRisk, ThreadSafetyLevel,
129};
130
131#[cfg(test)]
132mod tests {
133    use super::*;
134
135    #[test]
136    fn test_error_reexports() {
137        let error = TrackingError::TrackingDisabled;
138        assert!(matches!(error, TrackingError::TrackingDisabled));
139    }
140
141    #[test]
142    fn test_allocation_info_creation() {
143        let info = AllocationInfo::new(0x1000, 1024);
144        assert_eq!(info.ptr, 0x1000);
145        assert_eq!(info.size, 1024);
146    }
147
148    #[test]
149    fn test_smart_pointer_info_creation() {
150        let info = SmartPointerInfo::new_rc_arc(0x1000, SmartPointerType::Rc, 1, 0);
151        assert_eq!(info.data_ptr, 0x1000);
152        assert!(info.is_data_owner);
153    }
154
155    #[test]
156    fn test_memory_stats_creation() {
157        let stats = MemoryStats::new();
158        assert_eq!(stats.total_allocations, 0);
159    }
160}