Profiling with hotshot and wall clock time

Carl Friedrich Bolz cfbolz at
Mon Nov 28 00:07:04 CET 2005


Geert Jansen wrote:
> I'm trying to profile an application that I believe is blocking on I/O 
> for a significant amount of time. In trying to dig down where this 
> happens, I profiled the application with hotshot. The results are not 
> really usable however as it seems to display the amount of CPU time 
> which for my application is much lower than the total run time.
> Is possible to use hotshot with wall clock time, i.e. is it possible to 
> have the code fragment below show one second as opposed to zero? The old 
> profiler seems to have functionality choosing a timer function but it 
> crashed on my code.

There is a nice profiling module that PyPy has used profitably recently: 
it is called lsprof and can be found at (svn repository):

It was written by Brett Rosen and Ted Czotter, with further changes from 
Michael Hudson and Armin Rigo.

I did not really check what timer function it uses, although it seems to 
provide more exact results than hotshot while maintaining the speed of 
same. It seems to handle your example just fine:

 >>> import lsprof
 >>> import time
 >>> def f():
...   time.sleep(1)
 >>> lsprof.profile(f).pprint()
    CallCount    Recursive    Total(ms)   Inline(ms) module:lineno(function)
            1            0    999.0380    999.0380   <<stdin>>:1(f)

(profiling time.sleep directly does not work, but I guess that this is 
also not so useful).


Carl Friedrich Bolz

More information about the Python-list mailing list