Profiling with hotshot and wall clock time

Geert Jansen geert at boskant.nl
Thu Nov 24 15:33:03 EST 2005


Hi!

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.

<cut>
import os
import time
import hotshot
import hotshot.stats
import tempfile

def profile(call, *args):
    """Profile function `call', invoked with `args'."""
    fd, fprof = tempfile.mkstemp()
    os.close(fd)
    profiler = hotshot.Profile(fprof)
    profiler.runcall(call, *args)
    profiler.close()
    stats = hotshot.stats.load(fprof)
    stats.strip_dirs().sort_stats('time').print_stats()
    os.remove(fprof)

profile(time.sleep, 1)
</cut>

Regards,
Geert Jansen





More information about the Python-list mailing list