hotshot profiler: how to distinguish between cpu time and wait (idle) time?

Irmen de Jong irmen at
Wed Jun 9 15:33:57 CEST 2004

when using the hotshot profiler, I can see no difference in the
measurement of a function that is busy eating CPU cycles, and
a function that is blocking/waiting on IO (or sleeping)...

For instance I have this output:

     3 function calls in 26.931 CPU seconds

Ordered by: internal time, call count
ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      1   13.465   13.465   13.465   13.465
      1   13.464   13.464   13.464   13.464
      1    0.002    0.002   26.931   26.931
      0    0.000             0.000          profile:0(profiler)

My test program (see below) consists of two functions called sequentially:
a cpu() function eating 13+ seconds of CPU cycles when calculating
sha-hashes, and a sleep() function that only has time.sleep(13) in it.

What would be really useful, is that the profiler would show that sleep()
is actually not doing *anything*, while cpu() is doing all the hard work.
I.E.: measure CPU-time, not user-time.

How do I do this? Is this possible? (I'm using Python 2.3.4)

--Irmen de Jong.

--------------- test program ------------------
import hotshot, hotshot.stats
import time
import sha

def cpu():
     for i in range(1000000):

def sleep():

def main():
     print "cpu..."
     print "sleep..."
     print "done"

prof = hotshot.Profile("/tmp/")
result = prof.runcall(main)
print "PROFILE DONE, result=",result,type(result)
stats = hotshot.stats.load("/tmp/")
stats.sort_stats('time', 'calls')

More information about the Python-list mailing list