Convert Figma logo to code with AI

jiffyclub logosnakeviz

An in-browser Python profile viewer

2,317
136
2,317
57

Top Related Projects

🚴 Call stack profiler for Python. Shows you why your code is slow!

Converts profiling output to a dot graph.

11,659

Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python with AI-powered optimization proposals

Line-by-line profiling for Python

Was an interactive continuous Python profiler.

12,439

Sampling profiler for Python programs

Quick Overview

SnakeViz is a browser-based graphical viewer for Python profiling data. It provides an interactive visualization of cProfile or profile output, allowing developers to analyze and optimize their Python code's performance. SnakeViz presents the profiling data in a sunburst chart, making it easy to identify bottlenecks and time-consuming functions.

Pros

  • Interactive and visually appealing sunburst chart representation of profiling data
  • Easy-to-use command-line interface for launching the viewer
  • Supports both cProfile and profile output formats
  • Allows zooming and focusing on specific parts of the call graph

Cons

  • Limited customization options for the visualization
  • May be overwhelming for beginners unfamiliar with profiling concepts
  • Requires a web browser to view the results, which might not be ideal in all environments
  • Performance can be slow for very large profiling datasets

Getting Started

To install SnakeViz:

pip install snakeviz

To profile your Python script and view the results:

python -m cProfile -o profile_output.prof your_script.py
snakeviz profile_output.prof

This will launch the SnakeViz viewer in your default web browser, displaying the profiling data for your script.

Competitor Comparisons

🚴 Call stack profiler for Python. Shows you why your code is slow!

Pros of pyinstrument

  • Real-time profiling with minimal overhead
  • Intuitive HTML output with interactive flame graph
  • Supports async code and custom profiling sessions

Cons of pyinstrument

  • Less detailed information about individual function calls
  • May not be as suitable for large-scale applications
  • Limited customization options for output format

Code Comparison

SnakeViz:

import cProfile
import snakeviz

cProfile.run('your_function()', 'profile.stats')
snakeviz.snakeviz('profile.stats')

pyinstrument:

from pyinstrument import Profiler

profiler = Profiler()
profiler.start()
your_function()
profiler.stop()

profiler.print()

SnakeViz uses cProfile to generate profiling data and then visualizes it, while pyinstrument provides a more streamlined approach with built-in profiling and visualization. pyinstrument offers a simpler API and real-time profiling, but SnakeViz may provide more detailed information for complex applications. Both tools have their strengths, and the choice between them depends on the specific needs of your project and profiling requirements.

Converts profiling output to a dot graph.

Pros of gprof2dot

  • Supports a wider range of profiling formats (gprof, Valgrind, OProfile, etc.)
  • Generates static DOT files for easy sharing and integration with other tools
  • Offers more customization options for graph appearance

Cons of gprof2dot

  • Requires external tools (Graphviz) for visualization
  • Less interactive than SnakeViz's web-based interface
  • May have a steeper learning curve for users unfamiliar with DOT format

Code Comparison

SnakeViz (Python):

@app.route('/snakeviz/<profile_name>')
def snakeviz(profile_name):
    profile_path = os.path.join(PROFILE_DIR, profile_name)
    return render_template('snakeviz.html', profile_path=profile_path)

gprof2dot (Python):

def main():
    parser = optparse.OptionParser(
        usage="\n\t%prog [options] [file]")
    parser.add_option('-f', '--format', dest='format', default='auto',
                      help="profile format: " + ", ".join(formats) + " [default: %default]")

Both tools aim to visualize profiling data, but they take different approaches. SnakeViz focuses on providing an interactive web-based interface specifically for Python profiles, while gprof2dot offers a more versatile command-line tool that generates static graphs for various profiling formats. The choice between them depends on the user's specific needs and preferences for visualization and supported formats.

11,659

Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python with AI-powered optimization proposals

Pros of Scalene

  • Provides more detailed profiling information, including CPU, GPU, and memory usage
  • Offers real-time profiling capabilities, allowing for continuous monitoring
  • Supports profiling of multi-threaded and multi-process applications

Cons of Scalene

  • More complex setup and usage compared to SnakeViz's simplicity
  • May have a higher performance overhead during profiling
  • Requires Python 3.6 or later, while SnakeViz supports older versions

Code Comparison

Scalene usage:

from scalene import scalene_profiler

@scalene_profiler
def my_function():
    # Your code here

SnakeViz usage:

import cProfile

cProfile.run('my_function()', 'profile_output')
# Then visualize using: snakeviz profile_output

Both tools serve different purposes in the Python profiling ecosystem. Scalene offers more comprehensive profiling capabilities, including memory and GPU usage, making it suitable for complex applications and performance optimization. SnakeViz, on the other hand, provides a simpler, more accessible approach to visualizing profiling data, making it ideal for quick analysis and less experienced users. The choice between the two depends on the specific needs of the project and the level of detail required in the profiling process.

Line-by-line profiling for Python

Pros of line_profiler

  • Provides line-by-line profiling for more detailed analysis
  • Offers precise timing information for each line of code
  • Can be used as a decorator for easy integration into existing code

Cons of line_profiler

  • Requires manual installation of C extensions
  • Limited visualization options compared to SnakeViz
  • May have a higher performance overhead for large codebases

Code Comparison

line_profiler:

@profile
def my_function():
    # Your code here
    pass

# Run the profiler
kernprof -l script.py
python -m line_profiler script.py.lprof

SnakeViz:

import cProfile
cProfile.run('my_function()', 'profile_output')

# Visualize with SnakeViz
snakeviz profile_output

Summary

line_profiler excels in providing detailed, line-by-line profiling information, making it ideal for pinpointing specific performance bottlenecks. However, it requires additional setup and may have higher overhead. SnakeViz, on the other hand, offers easier installation and better visualization options, but provides less granular profiling data. The choice between the two depends on the level of detail required and the preference for visualization tools.

Was an interactive continuous Python profiler.

Pros of profiling

  • Provides live profiling capabilities, allowing real-time monitoring of performance
  • Offers a more comprehensive set of profiling tools, including memory and CPU profiling
  • Supports both synchronous and asynchronous code profiling

Cons of profiling

  • May have a higher learning curve due to its more advanced features
  • Could potentially introduce more overhead in some cases, especially with live profiling

Code Comparison

snakeviz:

import cProfile
import snakeviz

cProfile.run('your_function()', 'profile.stats')
snakeviz.snakeviz('profile.stats')

profiling:

from profiling import Profile

with Profile() as p:
    your_function()
p.run_viewer()

Both tools offer Python profiling capabilities, but they differ in their approach and features. snakeviz focuses on visualizing cProfile data, providing an interactive sunburst chart for easy interpretation of profiling results. It's straightforward to use and integrates well with existing cProfile workflows.

profiling, on the other hand, offers a more comprehensive suite of profiling tools, including live profiling capabilities. It provides detailed insights into both CPU and memory usage, making it suitable for more complex profiling needs. However, this added functionality may come at the cost of a steeper learning curve for some users.

12,439

Sampling profiler for Python programs

Pros of py-spy

  • Low-overhead sampling profiler that can be attached to running processes
  • Supports profiling multi-threaded Python programs
  • Can generate flame graphs for visualizing performance bottlenecks

Cons of py-spy

  • Requires root/admin privileges to attach to running processes
  • Limited to sampling-based profiling, which may miss short-lived function calls
  • Does not provide a web-based interface for exploring results

Code Comparison

py-spy:

py-spy record -o profile.svg --pid 12345

snakeviz:

import cProfile
cProfile.run('my_function()', 'profile.prof')
snakeviz profile.prof

Key Differences

py-spy is a sampling profiler that can attach to running processes, while snakeviz is a visualization tool for Python cProfile data. py-spy is better suited for profiling production systems with minimal overhead, whereas snakeviz offers an interactive web-based interface for exploring profiling results in detail.

py-spy generates flame graphs directly, which can be useful for quickly identifying performance bottlenecks. snakeviz, on the other hand, provides more detailed information about individual function calls and their relationships.

Both tools have their strengths and can be complementary in a Python developer's toolkit, depending on the specific profiling needs and constraints of the project.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SnakeViz

.. image:: https://github.com/jiffyclub/snakeviz/actions/workflows/ci.yml/badge.svg :target: https://github.com/jiffyclub/snakeviz/actions/workflows/ci.yml :alt: Build Status

.. image:: https://img.shields.io/pypi/v/snakeviz.svg :target: https://pypi.python.org/pypi/snakeviz/ :alt: Latest Version

.. image:: https://img.shields.io/pypi/pyversions/snakeviz.svg :target: https://pypi.python.org/pypi/snakeviz/ :alt: Supported Python versions

.. image:: https://img.shields.io/pypi/format/snakeviz.svg :target: https://pypi.python.org/pypi/snakeviz/ :alt: Wheel Status

About

SnakeViz is a viewer for Python profiling data that runs as a web application in your browser. It is inspired by the wxPython profile viewer RunSnakeRun <http://www.vrplumber.com/programming/runsnakerun/>_.

View the docs at https://jiffyclub.github.io/snakeviz/.