views:

33

answers:

1

How can I test the time it takes to render a pylons page request?

Where do I hook this in? (and what class/method do I use to output this information)

I'm sort of new to both pylons and python.

+2  A: 

There are several ways you could do this and it depends on whether you want to do with for profiling/testing or for production.

If you want to profile then the simplest thing to setup is repoze.profile. It is a WSGI middleware that profiles everything that happens after it in the WSGI stack. To use put it just before your app in your middleware.py

For example:

# The Pylons WSGI app
app = PylonsApp()

#Profile the app
app = AccumulatingProfileMiddleware(
        app,
        log_filename='/profiling.log',
        cachegrind_filename='/cachegrind.out',
        discard_first_request=True,
        flush_at_shutdown=True,
        path='/__profile__'
)

This will profile just your app and give you a web page where you can look at the output. Be aware the output takes some getting used to and if you are using SqlAlchemy most of the calls will be in there. DO NOT use this is production environment as it adds massive overhead

If you want the page times for testing then using the timeit module and the pylons url() method will allow you to test the rendering of a single page. If I have time to put together a sample I'll add it to this answer.

Ben