From: Stefan v. d. W. <st...@su...> - 2006-11-08 15:22:37
|
On Wed, Nov 08, 2006 at 01:32:44AM -0700, Fernando Perez wrote: > Hi all, >=20 > in the past, Arnd Baecker has made a number of very useful posts on > this matter, and provided some nice utilities to do it. I now needed > to profile some fairly complex codes prior to a big optimization push, > so I went over his material and wrote a little tool to make the whole > process as painless as possible. Here it is, hoping others may find > it useful: >=20 > http://amath.colorado.edu/faculty/fperez/python/profiling/ This looks very interesting. It works for me on simple scripts, but whenever I include the lines from numpy.testing import set_local_path set_local_path('../../..') in the input, pycachegrind aborts with File "/home/stefan//lib/python2.4/site-packages/numpy/testing/numpytest= .py", line 68, in set_local_path if f.f_locals['__name__']=3D=3D'__main__': KeyError: '__name__' I guess this is because the script is run in a separate namespace. I've managed to work around the problem by changing the definition of 'run' to: def run(code): loc =3D locals() loc['__name__'] =3D '__main__' loc['__file__'] =3D sys.argv[0] exec code in locals() Cheers St=E9fan |