axonml-profile
Overview
axonml-profile provides comprehensive profiling capabilities for neural network training and inference. It includes memory tracking, compute profiling, timeline recording, and automatic bottleneck detection to help identify and resolve performance issues.
Features
- Memory Profiler: Track allocations, deallocations, peak usage, and detect memory leaks
- Compute Profiler: Measure operation times, FLOPS, throughput, and bandwidth
- Timeline Profiler: Record timestamped events for visualization and analysis
- Bottleneck Detection: Automatically identify slow operations, memory hotspots, and throughput issues
- Report Generation: Export reports in Text, JSON, Markdown, and HTML formats
- RAII Profiling: Scope-based profiling with automatic start/stop via guards
- Global Profiler: Singleton profiler instance for convenient access throughout codebase
- Thread-Safe: All profilers are thread-safe with parking_lot locks
Modules
| Module | Description |
|---|---|
memory |
Memory profiler for tracking allocations, peak usage, and leak detection |
compute |
Compute profiler for measuring operation times, FLOPS, and bandwidth |
timeline |
Timeline profiler for recording events with timestamps and metadata |
bottleneck |
Bottleneck analyzer for detecting performance issues with severity ratings |
report |
Report generation in multiple formats (Text, JSON, Markdown, HTML) |
error |
Error types and Result alias for profiling operations |
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Profiling
use Profiler;
// Create a profiler
let profiler = new;
// Profile an operation
profiler.start;
let output = model.forward;
profiler.stop;
// Check timing
let total = profiler.total_time;
let avg = profiler.avg_time;
println!;
Memory Tracking
use Profiler;
let profiler = new;
// Track allocations
profiler.record_alloc; // 4 MB
profiler.record_alloc; // 2 MB
// Check memory usage
println!;
println!;
// Record deallocation
profiler.record_free;
RAII Scope Profiling
use ;
let profiler = new;
// Using ProfileGuard directly
// Or using the macro
Bottleneck Analysis
use Profiler;
let profiler = new;
// Profile various operations
profiler.start;
// ... matrix multiplication
profiler.stop;
profiler.start;
// ... activation
profiler.stop;
// Analyze for bottlenecks
let bottlenecks = profiler.analyze_bottlenecks;
for b in &bottlenecks
Report Generation
use ;
use Path;
let profiler = new;
// ... profiling operations ...
// Generate and print summary
let report = profiler.summary;
println!;
// Export to file
report.export?;
report.export?;
report.export?;
Global Profiler
use ;
// Use global profiler functions
start;
// ... operation ...
stop;
record_alloc;
// Access the global profiler instance
let profiler = global_profiler;
profiler.print_summary;
Compute Statistics
use ComputeProfiler;
let mut profiler = new;
// Profile with FLOPS tracking
profiler.start_with_flops; // 2 GFLOPS
// ... operation ...
profiler.stop;
// Get top operations
for op in profiler.top_by_time
Bottleneck Types
| Type | Description | Detection Threshold |
|---|---|---|
SlowOperation |
Operation taking disproportionate time | >20% of total time |
HighCallCount |
Operation called too frequently | >10,000 calls |
MemoryHotspot |
Large memory allocation | >30% of peak memory |
MemoryLeak |
Memory not freed | >5% of allocations |
LowThroughput |
Low computational throughput | <1 GFLOPS |
Report Formats
| Format | Description | Use Case |
|---|---|---|
| Text | Plain text with ASCII tables | Console output |
| JSON | Structured JSON | Programmatic analysis |
| Markdown | GitHub-flavored Markdown | Documentation |
| HTML | Styled HTML page | Browser viewing |
Tests
Run the test suite:
License
Licensed under either of:
- MIT License
- Apache License, Version 2.0
at your option.