一个用于django调试工具栏的面板,它集成了来自line_profiler的信息
django-debug-toolbar-line-profiler的Python项目详细描述
Django Debug Toolbar是一组可配置的面板,显示各种 有关当前请求/响应的调试信息,单击时显示 有关面板内容的更多详细信息。
这个包提供了一个面板,其中包含来自line_profiler
stock line_profiler只与python的2.x分支兼容 但是,python 3的修补版本可以安装:
pip install cython pip install -e hg+https://bitbucket.org/kmike/line_profiler@7999f21#egg=line_profiler
(参见http://stackoverflow.com/questions/6273139/profiling-by-line-with-python-3)
此面板仅在django_debug_toolbar>;=1.0时起作用,在此之前,它的功能 包含在debug_toolbar.panels.profilingpanel中。
这个django调试工具栏面板是在bsd许可下发布的,比如django 以及Django调试工具栏如果你喜欢,请考虑贡献!
Django调试工具栏最初是由Rob Hudson创建的 2008年8月,由许多捐助者进一步发展。
安装
要安装测线探查器面板,请首先使用pip install django-debug-toolbar-line-profiler安装此软件包,然后将调试工具栏测线探查器添加到已安装的应用:
INSTALLED_APPS = ( ... 'debug_toolbar_line_profiler', )
并将面板添加到调试工具栏面板:
DEBUG_TOOLBAR_PANELS = ( ... 'debug_toolbar_line_profiler.panel.ProfilingPanel', )
配置
默认情况下,面板将评测您的视图功能如果使用基于类的视图 面板将分析类中所有不以u开头的函数。如果你 要分析其他代码,请添加@profile\u附加装饰符,如下所示:
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): ...
信号
还有一个信号(debug_toolbar_line_profiler.signals.profiler_setup) 您可以附加到以集成基于类的视图,如django rest framework。
下面是一个示例:
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')