Profiling Web.py apps

92 views
Skip to first unread message

Megha Vishwanath

unread,
Oct 22, 2013, 8:25:51 AM10/22/13
to we...@googlegroups.com
How does one go about this?

We have a web.py + wsgi + apache. And we'd want call graph profiling.

Warm Regards,
Megha 

Jeffrey Zellman

unread,
Oct 22, 2013, 2:55:30 PM10/22/13
to we...@googlegroups.com
The simplest way would be to change app.run() to 

import cProfile
cProfile.run("app.run()")

Now when you hit ctrl+c from the terminal, the call graph will be printed.

If there is a particular function that you think is the culprit, you can always pass it into cProfile.run. For example, say there is a function in code.py called do_something, you could do the following from the python shell:

import code
import cProfile
cProfile.run("code.do_something()")

Check out the cProfile module though, since it supports dumping the profile info to a file which can be read with the pstats module: http://docs.python.org/2/library/profile.html#module-cProfile


Hope that helps,

Jeff

Anand Chitipothu

unread,
Oct 22, 2013, 3:22:59 PM10/22/13
to webpy
On Tue, Oct 22, 2013 at 5:25 AM, Megha Vishwanath <megha.vi...@gmail.com> wrote:
How does one go about this?

We have a web.py + wsgi + apache. And we'd want call graph profiling.

Did you look at web.profiler?

Anand

Jeffrey Zellman

unread,
Oct 22, 2013, 6:14:24 PM10/22/13
to we...@googlegroups.com

Good call, forgot about that one!

--
You received this message because you are subscribed to a topic in the Google Groups "web.py" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/webpy/alyQhQvTOj8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to webpy+un...@googlegroups.com.
To post to this group, send email to we...@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Megha Vishwanth

unread,
Oct 22, 2013, 11:34:39 PM10/22/13
to we...@googlegroups.com, we...@googlegroups.com
Will look at both these now. Thanks.

- Megha
You received this message because you are subscribed to the Google Groups "web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webpy+un...@googlegroups.com.

Megha Vishwanath

unread,
Oct 23, 2013, 4:47:25 AM10/23/13
to we...@googlegroups.com
Anand, Jeffrey,

This is how i'm trying to use the web.profiler. Is this right? And if yes, where do I see the profile? I have a log file in the app and the apache log file, both of which didn't really have any indicators.

import web.utils
...

application = web.application(urls,globals(),web.profiler).wsgifunc()

Warm Regards,
Megha 
________________________________________

Anand Chitipothu

unread,
Oct 23, 2013, 11:14:30 AM10/23/13
to webpy
On Wed, Oct 23, 2013 at 1:47 AM, Megha Vishwanath <megha.vi...@gmail.com> wrote:
Anand, Jeffrey,

This is how i'm trying to use the web.profiler. Is this right? And if yes, where do I see the profile? I have a log file in the app and the apache log file, both of which didn't really have any indicators.

import web.utils
...

application = web.application(urls,globals(),web.profiler).wsgifunc()

IIRC, it comes on the web page.

Anand

Jeffrey Zellman

unread,
Oct 23, 2013, 5:08:53 PM10/23/13
to we...@googlegroups.com
It does display on the bottom of the web page however I don't think your syntax is quite right. web.profiler is a middleware so it should be passed to run (and potentially wsgifunc, can't confirm since I can't test wsgifunc). This should work though:

application =  web.application(urls,globals())
if __name__ == "__main__":
    application.run(web.profiler)

and in theory, this should work:

application = web.application(urls,globals()).wsgifunc(web.profiler)


Jeff

 
Reply all
Reply to author
Forward
0 new messages