System Profile
Cached system profile information for runtime optimization decisions.
Overview
System Profile provides a lazily-initialized, cached view of system resources that applications can use to make intelligent runtime optimization decisions. Information is gathered once at first access and cached for the lifetime of the application.
Features
- 🚀 Lazy Initialization - System profiling only happens on first access
- 💾 Cached Results - Profile information is computed once and reused
- 🔧 Zero Runtime Overhead - No repeated system calls after initialization
- 🎯 Targeted Information - Only gathers what's needed for optimization decisions
- 🌐 Cross-Platform - Works on Linux, macOS, and Windows
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Usage
use SystemProfile;
// Get cached system profile (initialized on first call)
let profile = global;
// Use profile information for runtime decisions
let worker_count = if profile.cpu_count > 8 else ;
// Check available memory for workload sizing
let available_memory = profile.available_memory_mb;
if available_memory < 1000
// Make optimization decisions based on system capabilities
let batch_size = match ;
API
Core Methods
SystemProfile::global()- Get the global cached system profilecpu_count()- Number of logical CPU corestotal_memory_mb()- Total system memory in megabytesavailable_memory_mb()- Available system memory in megabytesis_low_memory()- Returns true if available memory is below threshold
Advanced Features
Optional GPU detection (requires gpu feature):
[]
= { = "0.1.0", = ["gpu"] }
Use Cases
Parallel Processing Optimization
use SystemProfile;
let profile = global;
let optimal_workers = profile.cpu_count.min;
// Use optimal worker count for parallel processing
new
.num_threads
.build_global
.unwrap;
Memory-Aware Caching
use SystemProfile;
let profile = global;
let cache_size = if profile.available_memory_mb > 4000 else ;
Adaptive Batch Processing
use SystemProfile;
Performance
- Initialization: ~1-5ms (one-time cost)
- Subsequent Access: ~1ns (cached value lookup)
- Memory Overhead: <1KB per profile instance
- Thread Safety: Uses
std::sync::LazyLockfor safe concurrent access
License
MIT License - see LICENSE for details.
Contributing
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
Support
- 📚 Documentation
- 🐛 Issues
- 💬 Discussions