Skip to main content

A simple tool for giving immediate visual feedback on the hotspots in your code.

Project description

HeatProfile

HeatProfile is a Python decorator for profiling the execution time of individual lines within a function. It provides a detailed overview of the function's performance by highlighting each line's cumulative execution time, call count, and average time per call. Additionally, it uses color coding to visually represent the relative time spent on each line, making it easy to spot performance bottlenecks.

Features

  • Line-by-Line Profiling: Detailed execution time analysis for each line within the function.
  • Color-Coded Output: Visual representation using colors to indicate lines with higher execution times.
  • Threshold-Based Coloring: Lines with execution times significantly lower than the maximum are displayed with a white background, ensuring clarity in highlighting performance-critical areas.
  • Dynamic Column Widths: Adjusts column widths based on the length of the source code lines, ensuring readability.

Example Output

image info

Installation

To use HeatProfile, simply copy the heatprofile.py file to your project directory.

Usage

To profile a function, import heatprofile from heatprofile.py and use it as a decorator:

from heatprofile import heatprofile

@heatprofile
def your_function(args):
    # function implementation
    pass

Run your Python script as usual, and the profiling output will be displayed in the console.

Output Format

  • Function Name: Name of the profiled function.
  • Function Location: File location of the function.
  • Total Function Time: Total execution time of the function.
  • Line: Line number in the source code.
  • Source Code: The actual source code of the line.
  • Cumulative Time(s): Total time spent on this line across all calls.
  • Call Count: Number of times this line was executed.
  • Time/Call(s): Average execution time per call for this line.

Color Coding

  • Red: Lines with higher relative execution times.
  • White: Lines with negligible execution times compared to the maximum.

Compatibility

HeatProfile is compatible with Python 3.x. It has been tested on various platforms with standard Python interpreters.

Contributing

Contributions to HeatProfile are welcome. Please feel free to submit pull requests, report bugs, or suggest features through the GitHub issue tracker.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

heatprofile-0.0.6.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

heatprofile-0.0.6-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

Supported by

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