Comprehensive Python profiling toolkit with memory tracking, bottleneck detection, and historical analysis
Project description
Performance Profiler & Optimizer 🚀
A comprehensive Python toolkit for profiling and optimizing code performance with intelligent auto-suggestions and historical tracking.
✨ Features
- 💾 Memory Profiling - Track memory usage and allocations across your application
- 🔍 Line-by-Line Analysis - Detailed performance insights for each line of code
- 💡 Auto-Optimization Suggestions - AI-powered recommendations for code improvements
- 📊 Before/After Comparisons - Visual performance improvement metrics
- 🎯 Bottleneck Highlighting - Automatically identify and prioritize slow code
- 📈 Historical Tracking - Monitor performance trends over time with SQLite database
📦 Installation
pip install performance-profiler-optimizer
Or install from source:
git clone https://github.com/yourusername/performance-profiler-optimizer.git
cd performance-profiler-optimizer
pip install -e .
🚀 Quick Start
Basic Performance Profiling
from performance_profiler import PerformanceProfiler
profiler = PerformanceProfiler()
@profiler.profile
def my_function():
return sum(range(1000000))
my_function()
profiler.print_results()
Memory Profiling
from performance_profiler import MemoryProfiler
memory_profiler = MemoryProfiler()
memory_profiler.enable()
@memory_profiler.profile_memory
def memory_intensive_task():
return [i**2 for i in range(1000000)]
memory_intensive_task()
memory_profiler.print_results()
Line-by-Line Analysis
from performance_profiler import LineByLineProfiler
line_profiler = LineByLineProfiler()
@line_profiler.profile_lines
def complex_function():
data = [i for i in range(10000)]
filtered = [x for x in data if x % 2 == 0]
return sum(filtered)
complex_function()
line_profiler.print_results(top_n=15)
Auto-Optimization Suggestions
from performance_profiler import OptimizerEngine
optimizer = OptimizerEngine()
# Analyze code
code = """
def inefficient():
result = []
for i in range(1000):
result.append(i * 2)
return result
"""
suggestions = optimizer.analyze_code(code)
optimizer.print_suggestions(suggestions)
Before/After Comparisons
from performance_profiler import ComparisonEngine
comparator = ComparisonEngine()
def before_optimization(n):
result = ""
for i in range(n):
result += str(i)
return result
def after_optimization(n):
return ''.join(str(i) for i in range(n))
result = comparator.compare_functions(
before_func=before_optimization,
after_func=after_optimization,
args=(1000,),
iterations=100
)
comparator.print_comparison(result)
Bottleneck Detection
from performance_profiler import BottleneckDetector
detector = BottleneckDetector()
@detector.detect_bottlenecks
def slow_function():
result = 0
for i in range(1000):
for j in range(1000):
result += i * j
return result
slow_function()
detector.print_bottlenecks()
Historical Tracking
from performance_profiler import HistoricalTracker
tracker = HistoricalTracker(db_path="performance.db")
@tracker.track
def monitored_function():
return sum(range(100000))
# Run multiple times to build history
for _ in range(10):
monitored_function()
# View history and trends
tracker.print_history("monitored_function", limit=10)
trend = tracker.get_trend("monitored_function", "execution_time")
print(f"Performance trend: {trend['trend']}")
📖 Documentation
Module Overview
PerformanceProfiler
Basic execution time profiling with call statistics.
MemoryProfiler
Track memory allocations, peak usage, and memory changes.
LineByLineProfiler
Detailed line-by-line execution analysis with hotspot detection.
OptimizerEngine
Pattern-based and AST code analysis for optimization suggestions.
ComparisonEngine
Compare before/after optimization metrics with improvement calculations.
BottleneckDetector
Detect and classify performance bottlenecks by severity (critical, high, medium).
HistoricalTracker
SQLite-backed performance tracking with trend analysis and reporting.
📊 Examples
Check the examples/ directory for comprehensive demonstrations:
basic_usage.py- Simple profiling examplememory_profiling.py- Memory tracking demoline_profiling.py- Line-by-line analysisoptimization_suggestions.py- Auto-optimization examplesbefore_after_comparison.py- Comparison demonstrationsbottleneck_detection.py- Bottleneck identificationhistorical_tracking.py- Historical data tracking
🔧 Requirements
- Python 3.7+
- psutil >= 5.8.0
📝 Development History
This project was developed incrementally with the following milestones:
- Jan 2020: Initial project structure and core profiler
- Apr 2020: Memory profiling capabilities
- Jul 2020: Line-by-line analysis implementation
- Oct 2020: Auto-optimization suggestion engine
- Jan 2021: Before/after comparison system
- Apr 2021: Bottleneck detection and highlighting
- Jul 2021: Historical tracking with database (v1.0.0)
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with Python's built-in profiling capabilities
- Uses psutil for system-level metrics
- Inspired by various profiling tools in the Python ecosystem
📧 Contact
For questions, issues, or suggestions, please open an issue on GitHub.
Made with ❤️ by the Performance Optimizer Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file performance_profiler_optimizer-1.0.0.tar.gz.
File metadata
- Download URL: performance_profiler_optimizer-1.0.0.tar.gz
- Upload date:
- Size: 25.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
430e1dfbb2fc838412a73b4c0cb5ce3ec498de6148ab526e072ec7f78d246a2d
|
|
| MD5 |
d9593f339c5d0aa71df4c142d090cb4e
|
|
| BLAKE2b-256 |
38b204676fa24fbb5b9b8faa52c5789c10cbe4978b2c2f8ee6d4f6a9a3e57083
|
File details
Details for the file performance_profiler_optimizer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: performance_profiler_optimizer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39dce5bdeab42f0e22ddf48cb4ff931b47d79127c0843eab55ffd1d439f29d71
|
|
| MD5 |
69cf180707660dc5931929ebbc526505
|
|
| BLAKE2b-256 |
9c39e4056b7b208ddb627c26d443e222e32dc2e693e43c97d5fab65580c90f36
|