|
Alan Davies
alan at goatpunch.com
Mon Mar 7 17:10:26 EST 2005
I've had useful results too using profile with mod_python. Has anyone
written a similar module for tracking memory usage?
The interface to the profile module is a little unusual, I use
some quick and dirty code similar to this to append profiling results
to every request during debugging:
------- album.py ------------
from mod_python import apache
_profiling_req=None
def handler(req, profiling=True):
if profiling:
import profile, pstats, sys, StringIO, tempfile
global _profiling_req
_profiling_req = req
temp = tempfile.NamedTemporaryFile()
profile.run("import album; album.handler(album._profiling_req,
False)", temp.name)
stats = pstats.Stats(temp.name)
strstream = StringIO.StringIO()
sys.stdout = strstream
stats.sort_stats("cumulative")
stats.print_stats()
req.write("<pre>" + strstream.getvalue() + "</pre>)
_profiling_req = None
else:
# regular handler code goes here...
return apache.OK
-----------------------------
--Alan
On Mon, 07 Mar 2005 09:16:59 -0600, "Nick" <nick at dd.revealed.net> said:
> The Python profiler works great. I do a log_error at the end of the
> request
> with the default text report. If you want to profile an entire handler,
> just make a wrapper handler that sets up the profiler to call your normal
> handler, and point to that in your apache config.
>
> Nick
>
> Wagner,Harry wrote:
> > Does anyone have any experience using the python profiler with
> > mod_python, or know of any other tools available for diagnosing
> > performance problems? TIA... harry
> >
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
|