cherrypy.lib.profiler module

Profiler tools for CherryPy.

CherryPy users

You can profile any of your pages as follows:

from cherrypy.lib import profiler

class Root:
    p = profiler.Profiler("/path/to/profile/dir")

    @cherrypy.expose
    def index(self):
        self.p.run(self._index)

    def _index(self):
        return "Hello, world!"

cherrypy.tree.mount(Root())

You can also turn on profiling for all requests using the make_app function as WSGI middleware.

CherryPy developers

This module can be used whenever you make changes to CherryPy, to get a quick sanity-check on overall CP performance. Use the --profile flag when running the test suite. Then, use the serve() function to browse the results in a web browser. If you run this module from the command line, it will call serve() for you.

class cherrypy.lib.profiler.ProfileAggregator(path=None)[source]

Bases: Profiler

A profiling aggregator app.

run(func, *args, **params)[source]

Dump aggeregated profile data into self.path.

class cherrypy.lib.profiler.Profiler(path=None)[source]

Bases: object

A profiling app.

index()[source]

Render the profiling viewer index page.

menu()[source]

Render the profiler menu page html layout.

report(filename)[source]

Render a statistics report.

run(func, *args, **params)[source]

Dump profile data into self.path.

statfiles()[source]

Compose a list of statistics file names.

Returns:

A list of available profiles.

Return type:

list[str]

stats(filename, sortby='cumulative')[source]

Generate statistics from given profile.

Returns:

The sorted stats index printout.

Return type:

str

class cherrypy.lib.profiler.make_app(nextapp, path=None, aggregate=False)[source]

Bases: object

Profiling WSGI middleware wrapper.

cherrypy.lib.profiler.new_func_strip_path(func_name)[source]

Add __init__ modules’ parents.

This makes the profiler output more readable.

cherrypy.lib.profiler.serve(path=None, port=8080)[source]

Serve the web app with profiler activated.