blueprint-profiling
Job profiling and resource benchmarking for Blueprint services.
Overview
This crate provides automated profiling tools to measure resource usage of Blueprint jobs. The profiling data is used for:
- FaaS compatibility detection - Determine if jobs can run on serverless platforms (AWS Lambda, GCP Functions, etc.)
- VM sizing recommendations - Right-size compute resources based on actual usage
- Cost estimation - Predict infrastructure costs before deployment
- QoS baseline establishment - Set performance expectations for monitoring
Features
- ✅ Cross-platform memory profiling - Works on macOS and Linux using
libc::getrusage - ✅ Statistical analysis - Multiple runs with percentile calculation (p95, p99)
- ✅ Configurable profiling - Control sample size, warm-up runs, and timeouts
- ✅ Async/await support - Profile async Blueprint jobs
- ✅ Production-ready - Zero TODOs, no mocks, fully tested
Usage
use ;
use Duration;
async
Architecture
This crate is separate from blueprint-manager to avoid circular dependencies:
blueprint-profiling- Build/test-time profiling tool (this crate)blueprint-manager- Runtime tool that reads profiles from metadata
The profiling workflow:
- Developer adds profiling tests to their Blueprint
- Tests execute jobs multiple times to collect statistics
- Profiles can be embedded in
blueprint.jsonmetadata - Blueprint Manager reads profiles to make deployment decisions
Examples
See examples/basic_usage.rs for a complete working example:
Inspired By
This design is inspired by Substrate's benchmarking framework:
- Automated execution as part of build/test process
- Statistical rigor with percentile analysis
- Conservative defaults (no profile = assume incompatible)
- Cross-platform measurement
Platform Support
- ✅ macOS - Uses
ru_maxrssin bytes - ✅ Linux - Uses
ru_maxrssin kilobytes - ⚠️ Windows - Fallback to 0 (platform-specific implementation needed)
API Reference
ProfileConfig
Configuration for profiling runs:
sample_size: u32- Number of measurement runs (default: 10)warmup_runs: u32- Warm-up iterations before measurement (default: 2)max_execution_time: Duration- Timeout per execution (default: 300s)
JobProfile
Statistical summary of job resource usage:
avg_duration_ms: u64- Average execution timep95_duration_ms: u64- 95th percentile durationp99_duration_ms: u64- 99th percentile durationpeak_memory_mb: u32- Peak memory usagestateful: bool- Whether job maintains statepersistent_connections: bool- Whether job uses persistent connectionssample_size: u32- Number of samples collected
ProfileRunner::profile_job
Profile a job by executing it multiple times:
pub async