Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
a greenlet aware profiling module
Python
branch: master

Merge pull request #10 from doublereedkurt/master

sorry for the drive-by pull request, but localtrace could use some optimization
latest commit da70243d82
@srlindsay authored

README.md

gevent-profiler

This module provides a simple way to get detailed profiling information about a Python process that uses the gevent library. The normal Python profilers are not nearly as useful in this context, due to gevent's greenlet threading model.

Installation

$ sudo python setup.py install

Usage

To generate profiling information for a single function call:

from gevent import monkey
monkey.patch_all()
import gevent_profiler

def my_func(a, b, c):
    print a, b, c

gevent_profiler.profile(my_func, 1, 2, c=3)

To generate profiling information for an arbitrary section of code:

from gevent import monkey
monkey.patch_all()
import gevent_profiler

gevent_profiler.attach()
for x in range(42):
    print pow(x, 2)
gevent_profiler.detach()

To start generating profiling information when a specific signal is received, and to stop after a set amount of time has elapsed:

from gevent import monkey
monkey.patch_all()
import gevent_profiler

gevent_profiler.attach_on_signal(signum=signal.SIGUSR1, duration=60)

x = 2
while True:
    print pow(x, 50000)

To profile a Python app from the command line:

$ python gevent_profiler/__init__.py --help
$ python gevent_profiler/__init__.py my_app.py

Options

Set the filename for the stats file. Defaults to sys.stdout. May be set to None to disable.

gevent_profiler.set_stats_output('my-stats.txt')

Set the filename for the summary file. Defaults to sys.stdout. May be set to None to disable.

gevent_profiler.set_summary_output('my-summary.txt')

Set the filename for the trace file. Defaults to sys.stdout. May be set to None to disable.

gevent_profiler.set_trace_output('my-trace.txt')

Print runtime statistics as percentages of total runtime rather than absolute measurements in seconds:

gevent_profiler.print_percentages(True)

Count time blocking on IO towards the execution totals for each function:

gevent_profiler.time_blocking(True)
Something went wrong with that request. Please try again.