UTIL主要用于在Django项目中分析Python代码,但也可以用于普通的Python代码

django-profiler的Python项目详细描述


django profiler主要用于在django项目中分析python代码。 但也可以用于普通的python代码。它将SQL查询计算为一个度量值 代码执行时间。它通过标准记录输出 python日志库并使用loggerprofiling。如果您的探查器名称 不包含任何空格,例如profiler('profiler1')django profiler将 将所有输出记录到profiling.profiler记录器。

要求

  • Python2.7+

安装

通过pip安装,或者将此模块复制到项目或python路径中。

配置

django settings.py常量

PROFILING_LOGGER_NAME
PROFILING_SQL_QUERIES

可以通过定义 profiling_logger_name='logger_name'在djangosettings.py中。

要将sql查询也记录到profiler logger中,请将profileing_sql_querys设置为true 在djangosettings.py模块中。

示例

示例1

使用上下文管理器方法。输出将记录到profiling记录器。

from profiling import Profiler
with Profiler('Complex Computation'):
    # code with some complex computations

示例2

使用上下文管理器方法。输出将记录到profiling.computation记录器。

from profiling import Profiler
with Profiler('Computation'):
    # code with some complex computations

示例3

使用标准方法。输出将记录到profiling记录器。

from profiling import Profiler
profiler =  Profiler('Complex Computation')
profiler.start()
# code with some complex computations
profiler.stop()

示例4

使用标准方法并直接从构造函数开始。输出将记录到profiling记录器。

from profiling import Profiler
profiler =  Profiler('Complex Computation', start=True)
# code with some complex computations
profiler.stop()

示例5

使用decorator方法。输出将记录到profiling.complex_computeslogger。

from profiling import profile

@profile
def complex_computations():
    #some complex computations

示例6

使用decorator方法。输出将记录到profiling.complexclass.complex_computes记录器。

from profiling import profile

class ComplexClass(object):
    @profile
    def complex_computations():
        #some complex computations

示例7

使用decorator方法。输出将记录到profiling.complex_computeslogger。 配置文件执行状态记录到profiling.complex\u computes记录器。

from profiling import profile

@profile(stats=True)
def complex_computations():
    #some complex computations

示例8

使用decorator方法。输出将记录到profiling.complex_computeslogger。 配置文件执行状态将打印到sys.stdout。

import sys

from profiling import profile

@profile(stats=True, stats_buffer=sys.stdout)
def complex_computations():
    #some complex computations

示例9

使用decorator方法。输出将记录到profiling.complexclass.complex_computes记录器。 配置文件统计信息将记录到profiling.complexclass.complex\u计算中。

from profiling import profile

class ComplexClass(object)
   @profile(stats=True)
   def complex_computations():
       #some complex computations

测试

在evnironment上测试

  • Xubuntu Linux 11.10 OneIRIC 64位
  • Python2.7.2+
  • python单元测试

运行测试

运行测试运行命令:

$ python test.py
$ python setup.py test

作者

字符(vladimír gorej,codescale s.r.o.)
电子邮件:gorej@codescale.net
网页:http://www.codescale.net

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java播放流媒体音乐   LWJGL中的java纹理未显示   java从父集合中删除时删除子对象   mysql希望在我的代码中添加验证,如果表不存在,它应该用java创建新表   java我可以关闭客户端的socket而不引起服务器端的EOFEException吗?   java Primefaces对话框框架咆哮和showMessageInDialog不工作   hadoop配置单元无法初始化类java。网网络接口   关键字中缺少oracle11g Java iBatis   java在RESTAPI中创建PUT和POST端点,而不创建GET端点?   java Math abs和ceil输出编译错误   java Tomcat 8.017代md5及其摘要。球棒   java SpringBean配置xml文件在IteliJ Idea中加载   java为什么在使用Powershell指定Xms和Xmx时,它们什么都不做,但通过Netbeans IDE可以正常工作?   java Drools项目构建失败,kjar打包从7.7版开始