Skip to main content

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.

Python Version Version License

✨ 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 example
  • memory_profiling.py - Memory tracking demo
  • line_profiling.py - Line-by-line analysis
  • optimization_suggestions.py - Auto-optimization examples
  • before_after_comparison.py - Comparison demonstrations
  • bottleneck_detection.py - Bottleneck identification
  • historical_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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

performance_profiler_optimizer-1.0.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

performance_profiler_optimizer-1.0.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file performance_profiler_optimizer-1.0.0.tar.gz.

File metadata

File hashes

Hashes for performance_profiler_optimizer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 430e1dfbb2fc838412a73b4c0cb5ce3ec498de6148ab526e072ec7f78d246a2d
MD5 d9593f339c5d0aa71df4c142d090cb4e
BLAKE2b-256 38b204676fa24fbb5b9b8faa52c5789c10cbe4978b2c2f8ee6d4f6a9a3e57083

See more details on using hashes here.

File details

Details for the file performance_profiler_optimizer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for performance_profiler_optimizer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39dce5bdeab42f0e22ddf48cb4ff931b47d79127c0843eab55ffd1d439f29d71
MD5 69cf180707660dc5931929ebbc526505
BLAKE2b-256 9c39e4056b7b208ddb627c26d443e222e32dc2e693e43c97d5fab65580c90f36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page