Skip to main content

A beautiful Python profiler with interactive HTML visualization

Project description

Profiler Viz

A beautiful Python profiler with interactive HTML visualization. Profile your Python functions and get stunning visual reports with charts, sortable tables, and call tree analysis.

Features

Beautiful HTML Reports - Interactive visualizations with charts and graphs

📊 Performance Charts - See top functions by time and call count at a glance

🔍 Sortable Statistics - Click column headers to sort by any metric

🌳 Call Tree Analysis - Click any function to see its callers and callees

🎯 Easy to Use - Just add a decorator to your function

Installation

pip install profiler-viz

Or install from source:

git clone https://github.com/nndat/profiler_viz.git
cd profiler-viz
pip install -e .

Quick Start

Basic Usage

from profiler_viz import func_profile

@func_profile()
def my_function():
    # Your code here
    result = sum(range(1000000))
    return result

# Run your function
my_function()

This will automatically:

  • Profile the function execution
  • Generate a .prof file
  • Create a beautiful HTML report
  • Both files named: my_function_YYYYMMDDHHmmss.{prof,html}

Custom Output Directory

from profiler_viz import func_profile

@func_profile(dest="./profiling_results")
def process_data():
    # Your code here
    pass

process_data()

Convert Existing .prof Files

from profiler_viz import view_profile_html

# Convert a .prof file to HTML
view_profile_html("my_profile.prof")

# Or specify output path
view_profile_html("my_profile.prof", "report.html")

Or use the command line:

profiler-viz my_profile.prof

HTML Report Features

The generated HTML report includes:

📈 Overview Section

  • Total functions profiled
  • Total function calls
  • Primitive calls
  • Total execution time

📊 Performance Charts

  1. Top 10 Functions by Cumulative Time - Functions that take the most time including their callees
  2. Top 10 Functions by Total Time - Functions that take the most time excluding callees
  3. Top 10 Most Called Functions - Functions called most frequently
  4. Time Distribution Pie Chart - Visual breakdown of where time is spent

📋 Sortable Statistics Table

  • Click any column header to sort
  • Filter functions by name or file path
  • View detailed metrics:
    • ncalls - Number of calls
    • tottime - Total time in function (excluding sub-functions)
    • percall - Time per call
    • cumtime - Cumulative time (including sub-functions)
    • filename:lineno(function) - Location and name

🌳 Call Tree Modal

  • Click any row to see:
    • Who calls this function (callers)
    • What this function calls (callees)
    • Call counts and timing for each relationship

Examples

Example 1: Profile a Recursive Function

from profiler_viz import func_profile

@func_profile()
def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)

result = fibonacci(20)

Example 2: Profile Data Processing

from profiler_viz import func_profile
import pandas as pd

@func_profile(dest="./analysis_reports")
def analyze_data(filename):
    df = pd.read_csv(filename)
    # Complex data processing
    result = df.groupby('category').agg({
        'value': ['sum', 'mean', 'std']
    })
    return result

analyze_data("large_dataset.csv")

Example 3: Profile with Custom Logic

from profiler_viz import func_profile

@func_profile(dest="./benchmarks")
def benchmark_algorithm(data_size):
    data = list(range(data_size))
    # Test different sorting approaches
    sorted_data = sorted(data, reverse=True)
    return sorted_data

# Run benchmark
benchmark_algorithm(1000000)

Understanding the Output

File Naming

Files are automatically named using the pattern:

<function_name>_YYYYMMDDHHmmss.prof
<function_name>_YYYYMMDDHHmmss.html

For example:

my_function_20231128143022.prof
my_function_20231128143022.html

Metrics Explained

  • ncalls: Number of calls. If shown as X/Y, Y is primitive calls, X is total calls
  • tottime: Time spent in this function alone (excluding calls to sub-functions)
  • percall: Average time per call (tottime / ncalls)
  • cumtime: Total time spent in this function including all sub-functions
  • percall: Average cumulative time (cumtime / primitive calls)

What to Look For

  1. High cumtime - Functions that take the most overall time
  2. High tottime - Functions doing expensive operations themselves
  3. High ncalls - Functions called many times (candidates for caching/optimization)
  4. High percall - Individual calls that are slow

Tips and Best Practices

  1. Start with cumtime - Sort by cumulative time to find the biggest bottlenecks
  2. Check the call tree - Click on slow functions to understand the call chain
  3. Look for patterns - Use the filter box to find related functions
  4. Compare runs - Profile before and after optimizations to measure impact
  5. Use custom directories - Organize profiles by feature or test case

Requirements

  • Python 3.7+
  • No external dependencies (uses only Python standard library)

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues, questions, or contributions, please visit: https://github.com/nndat/profiler_viz/issues

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

profiler_viz-0.1.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

profiler_viz-0.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file profiler_viz-0.1.0.tar.gz.

File metadata

  • Download URL: profiler_viz-0.1.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for profiler_viz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 048670f3787391948deab0bd8179f2b033405a933858b5fc8c76e143668cb421
MD5 d66676081123746d581d81d91dc113af
BLAKE2b-256 084abfadf634ef63ac23b2b4e9b6d58618d7389af01ae9aeea6a9aeb8ad25728

See more details on using hashes here.

File details

Details for the file profiler_viz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: profiler_viz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for profiler_viz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae5cc83aa258785be39ba3202127f57b667b7e7046f9bcd2af4190edda5b1d6c
MD5 ce63c5d34c9b0f1357ba4507d3020700
BLAKE2b-256 a585257d4688acc9ae2a7e4cf2b6bac16e7bb46ccea6c9a14735bff09d4a0e70

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