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.
β¨ 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
pip install profiler-vizOr install from source:
git clone https://github.com/nndat/profiler_viz.git
cd profiler-viz
pip install -e .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
.proffile - Create a beautiful HTML report
- Both files named:
my_function_YYYYMMDDHHmmss.{prof,html}
from profiler_viz import func_profile
@func_profile(dest="./profiling_results")
def process_data():
# Your code here
pass
process_data()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.profThe generated HTML report includes:
- Total functions profiled
- Total function calls
- Primitive calls
- Total execution time
- Top 10 Functions by Cumulative Time - Functions that take the most time including their callees
- Top 10 Functions by Total Time - Functions that take the most time excluding callees
- Top 10 Most Called Functions - Functions called most frequently
- Time Distribution Pie Chart - Visual breakdown of where time is spent
- Click any column header to sort
- Filter functions by name or file path
- View detailed metrics:
ncalls- Number of callstottime- Total time in function (excluding sub-functions)percall- Time per callcumtime- Cumulative time (including sub-functions)filename:lineno(function)- Location and name
- Click any row to see:
- Who calls this function (callers)
- What this function calls (callees)
- Call counts and timing for each relationship
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)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")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)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
- 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)
- High cumtime - Functions that take the most overall time
- High tottime - Functions doing expensive operations themselves
- High ncalls - Functions called many times (candidates for caching/optimization)
- High percall - Individual calls that are slow
- Start with cumtime - Sort by cumulative time to find the biggest bottlenecks
- Check the call tree - Click on slow functions to understand the call chain
- Look for patterns - Use the filter box to find related functions
- Compare runs - Profile before and after optimizations to measure impact
- Use custom directories - Organize profiles by feature or test case
- Python 3.7+
- No external dependencies (uses only Python standard library)
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
For issues, questions, or contributions, please visit: https://github.com/nndat/profiler_viz/issues