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将Map<String,String>传递给需要Map<String,Object>   java在循环中使用字符串而不是StringBuilder是否会造成内存损失?   jnlp如何更新java控制台JRE?   java更改、修改和重新打包CXFAPI源文件   JavaFXJava应用程序在Fedora上运行一段时间后关闭   使用来自不同类的方法的java   java如何通过ant脚本在linux中使用subst?   java在使用camunda modeler进行base64编码/解码时出错   获取java。netbeans、weblogic和fastswap设置为true时的lang.NoSuchMethodError   java如何提高FinalizerThread在GC中收集对象的优先级   java检测具有相同根的单词   netbeans crud应用程序中的java错误