Code Monkey home page Code Monkey logo

gevent-profiler's Introduction

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)

gevent-profiler's People

Contributors

kurtbrose avatar srlindsay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gevent-profiler's Issues

publish in pypy

Is there a specific reason you didn't want to release it to pypy?

Would be awesome to install it through pip install gevent-profiler

curious result

Hi, Love the library!

I have a question on interpreting a result I am seeing. I have a function call that is taking a lot of time, and have profiled it. It's taking over 300ms per call (only 10 loc), but none of the operations seem to be responsible. Instead, the results show:

Call Name  Count  Cumulative    Own Cumul  Child Cumul    Per Call    Own/Total
========== ===== ============ ============ ============ ============ =========
None.None    1      0.000000     -0.321184    0.321184     0.000000    inf  

Any idea of what None.None means?

Profiling django web application

Hey there! Thanks for releasing this!

I'd love to use this to profile my django web application, but I'm confused on how I should go about doing that. I attached at the beginning of my view and then again at the end, then ran my Gunicorn server and it just wouldn't stop outputting waaaaaay too much info.

Is it because I'm attaching/detaching in the same view? How should I do this?

Documentation on result analysis

I think documentation is missing on how to analyze the profiling results that are gevent specific. I would like to know if my code is gevent friendly, if it yields or gives up the processor frequently. Can we know this by looking at the profiler results?

Crash when using gevent-profiler

The following crash is showing up:

[<greenlet.greenlet object at 0x7f31c19eab98>] call: threading: _note
[<greenlet.greenlet object at 0x7f31c19eab98>] return: threading: _note: 62
[<greenlet.greenlet object at 0x7f31c19eab98>] call: threading: __delete
[<greenlet.greenlet object at 0x7f31c19eab98>] return: threading: __delete: 613
[<greenlet.greenlet object at 0x7f31c19eab98>] return: threading: _exitfunc: 773
[<greenlet.greenlet object at 0x7f31c19eab98>] call: atexit: _run_exitfuncs
[<greenlet.greenlet object at 0x7f31c19eab98>] call: init: shutdown
[<greenlet.greenlet object at 0x7f31c19eab98>] return: init: shutdown: 1624
[<greenlet.greenlet object at 0x7f31c19eab98>] return: atexit: _run_exitfuncs: 13
Exception AttributeError: "'NoneType' object has no attribute 'greenlet'" in <function _remove at 0x7f31c195c8c0> ignored

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.