Profiling Python scripts on Mod_wsgi

How can I profile a python script running on mod_wsgi on apache

I would like to use cProfile, but it seems to require me to call the function manually. Is there a way to enable cProfile globally and keep track of the results.

+5
source share
2 answers

You need to wrap the wsgi application function inside another function that simply calls your function with cProfile and use it as an application. Or you can reuse your existing WSGI middleware to do this for you, for example repoze.profile does pretty much what you think you need.

+9
source

The following is the WSGI profile middleware for WHIFF (currently only available from the Mercury Repository): profile.py . That should get you started. If you want to change it to run outside of the WHIFF context, change the line

 gateway.putResource(env, resourcePath, report)

to something like

 file("/tmp/profile.txt", "w").write(report)
0
source

All Articles