Package: django-profiler
django-profiler is util for profiling python code mainly in django projects
but can be used also on ordinary python code. It counts sql queries a measures
time of code execution. It logs its output via standard
python logging library and uses loggerprofiling. If your profiler name
doesn’t contain any empty spaces e.g. Profiler(‘Profiler1’) django-profiler will
log all the output to theprofiling.Profilerlogger.Requirementspython 2.7+InstallationInstall viapipor copy this module into your project or into your PYTHON_PATH.Configurationdjango settings.py constantsPROFILING_LOGGER_NAME
PROFILING_SQL_QUERIESIt is possible to change default django-profiler logger name by defining
PROFILING_LOGGER_NAME = ‘logger_name’ in your djangosettings.py.To log also sql queries into profiler logger set PROFILING_SQL_QUERIES to True
in your djangosettings.pymodule.ExamplesExample 1Using context manager approach. Output will be logged toprofilinglogger.from profiling import Profiler
with Profiler('Complex Computation'):
    # code with some complex computationsExample 2Using context manager approach. Output will be logged toprofiling.Computationlogger.from profiling import Profiler
with Profiler('Computation'):
    # code with some complex computationsExample 3Using standard approach. Output will be logged toprofilinglogger.from profiling import Profiler
profiler =  Profiler('Complex Computation')
profiler.start()
# code with some complex computations
profiler.stop()Example 4Using standard approach and starting directly in constructor. Output will be logged toprofilinglogger.from profiling import Profiler
profiler =  Profiler('Complex Computation', start=True)
# code with some complex computations
profiler.stop()Example 5Using decorator approach. Output will be logged toprofiling.complex_computationslogger.from profiling import profile

@profile
def complex_computations():
    #some complex computationsExample 6Using decorator approach. Output will be logged toprofiling.ComplexClass.complex_computationslogger.from profiling import profile

class ComplexClass(object):
    @profile
    def complex_computations():
        #some complex computationsExample 7Using decorator approach. Output will be logged toprofiling.complex_computationslogger.profileexecution stats are logged toprofiling.complex_computationslogger.from profiling import profile

@profile(stats=True)
def complex_computations():
    #some complex computationsExample 8Using decorator approach. Output will be logged toprofiling.complex_computationslogger.profileexecution stats are printed to sys.stdout.import sys

from profiling import profile

@profile(stats=True, stats_buffer=sys.stdout)
def complex_computations():
    #some complex computationsExample 9Using decorator approach. Output will be logged toprofiling.ComplexClass.complex_computationslogger.profilestats will be logged toprofiling.ComplexClass.complex_computations.from profiling import profile

class ComplexClass(object)
   @profile(stats=True)
   def complex_computations():
       #some complex computationsTestsTested on evnironmentXubuntu Linux 11.10 oneiric 64-bitpython 2.7.2+python unittestRunning testsTo run the test run command:$ python test.py
$ python setup.py testAuthorchar0n (Vladimír Gorej, CodeScale s.r.o.)email:gorej@codescale.netweb:http://www.codescale.netReferenceshttp://github.com/CodeScaleInc/django-profilerhttp://pypi.python.org/pypi/django-profiler/http://www.codescale.net/en/community#django-profiler