system-profile

Crates.iosystem-profile
lib.rssystem-profile
version0.1.1
created_at2025-08-22 11:42:30.830965+00
updated_at2025-11-03 21:52:10.475316+00
descriptionCached system profile information for runtime optimization decisions
homepagehttps://gitlab.com/deepbrain.space/system-profile
repositoryhttps://gitlab.com/deepbrain.space/system-profile
max_upload_size
id1806220
size39,698
nayeem.ai (wizardsupreme)

documentation

README

System Profile

Crates.io Documentation License: MIT

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:

[dependencies]
system-profile = "0.1.0"

Usage

use system_profile::SystemProfile;

// Get cached system profile (initialized on first call)
let profile = SystemProfile::global();

// Use profile information for runtime decisions
let worker_count = if profile.cpu_count() > 8 {
    8 // Cap at 8 workers for large systems
} else {
    profile.cpu_count()
};

// Check available memory for workload sizing
let available_memory = profile.available_memory_mb();
if available_memory < 1000 {
    println!("Warning: Low memory available");
}

// Make optimization decisions based on system capabilities
let batch_size = match (profile.cpu_count(), available_memory) {
    (cpu, mem) if cpu >= 8 && mem >= 8000 => 1000,  // High-end system
    (cpu, mem) if cpu >= 4 && mem >= 4000 => 500,   // Mid-range system
    _ => 100,                                         // Conservative default
};

API

Core Methods

  • SystemProfile::global() - Get the global cached system profile
  • cpu_count() - Number of logical CPU cores
  • total_memory_mb() - Total system memory in megabytes
  • available_memory_mb() - Available system memory in megabytes
  • is_low_memory() - Returns true if available memory is below threshold

Advanced Features

Optional GPU detection (requires gpu feature):

[dependencies]
system-profile = { version = "0.1.0", features = ["gpu"] }

Use Cases

Parallel Processing Optimization

use system_profile::SystemProfile;

let profile = SystemProfile::global();
let optimal_workers = profile.cpu_count().min(8);

// Use optimal worker count for parallel processing
rayon::ThreadPoolBuilder::new()
    .num_threads(optimal_workers)
    .build_global()
    .unwrap();

Memory-Aware Caching

use system_profile::SystemProfile;

let profile = SystemProfile::global();
let cache_size = if profile.available_memory_mb() > 4000 {
    1000 // Large cache for systems with plenty of memory
} else {
    100  // Conservative cache for memory-constrained systems
};

Adaptive Batch Processing

use system_profile::SystemProfile;

fn determine_batch_size() -> usize {
    let profile = SystemProfile::global();

    match profile.cpu_count() {
        n if n >= 16 => 1000,  // High-performance server
        n if n >= 8 => 500,    // Desktop/workstation
        n if n >= 4 => 250,    // Laptop
        _ => 100,              // Single/dual-core system
    }
}

Performance

  • Initialization: ~1-5ms (one-time cost)
  • Subsequent Access: ~1ns (cached value lookup)
  • Memory Overhead: <1KB per profile instance
  • Thread Safety: Uses std::sync::LazyLock for safe concurrent access

License

MIT License - see LICENSE for details.

Contributing

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

Support

Commit count: 0

cargo fmt