Coder Social home page Coder Social logo

matrach / django-debug-toolbar-line-profiler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dmclain/django-debug-toolbar-line-profiler

0.0 1.0 0.0 22 KB

License: BSD 3-Clause "New" or "Revised" License

Python 82.31% JavaScript 5.95% HTML 11.74%

django-debug-toolbar-line-profiler's Introduction

Django Debug Toolbar Line Profile Panel

The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.

This package provides a panel that incorporates output from line_profiler

The stock line_profiler is only compatible with the 2.x branch of python but a patched version for Python 3 can be installed with:

pip install cython
pip install -e hg+https://bitbucket.org/kmike/line_profiler@7999f21#egg=line_profiler

(cf. http://stackoverflow.com/questions/6273139/profiling-by-line-with-python-3)

This panel will only function with django_debug_toolbar>=1.0, before that it's functionality was contained in the debug_toolbar.panels.profiling.ProfilingPanel.

This Django Debug Toolbar panel is released under the BSD license, like Django and the Django Debug Toolbar. If you like it, please consider contributing!

The Django Debug Toolbar was originally created by Rob Hudson in August 2008 and was further developed by many contributors.

Installation

To install the line_profiler panel, first install this package with pip install django-debug-toolbar-line-profiler, then add debug_toolbar_line_profiler to the INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'debug_toolbar_line_profiler',
)

and add the panel to DEBUG_TOOLBAR_PANELS:

DEBUG_TOOLBAR_PANELS = (
    ...
    'debug_toolbar_line_profiler.panel.ProfilingPanel',
)

Configuration

By default, the panel will profile your view function. If you use class based views the panel will profile all functions on the class that don't start with _. If you want additional code to be profiled, add the @profile_additional decorator like so:

from debug_toolbar_line_profiler import profile_additional
from boto.s3.connection import S3Connection

...

@profile_additional(S3Connection.make_request)
def your_view_code(*args, **kwargs):
    ...

Signals

There is also a signal (debug_toolbar_line_profiler.signals.profiler_setup) that you can attach to for integrating class based views like django rest framework.

Here is an example:

from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from debug_toolbar_line_profiler import signals


class AViewSet(ViewSet):
    def list(self, request):
        return Response([])

    def retrieve(self, request, pk=None):
        return Response({})


def register_profile_views(sender, profiler, **kwargs):
    profiler.add_function(AViewSet.list)
    profiler.add_function(AViewSet.retrieve)


signals.profiler_setup.connect(register_profile_views,
                               dispatch_uid='register_profile_views')

django-debug-toolbar-line-profiler's People

Contributors

dmclain avatar jbking avatar lerela avatar pahaz avatar

Watchers

 avatar

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.