Problems with profiling results (hotshot or normal) : almost all are incorrect

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Wed Nov 3 12:38:18 EST 2004


Bengt Richter wrote:
> On Wed, 03 Nov 2004 00:43:31 +0100, Irmen de Jong <irmen at -nospam-remove-this-xs4all.nl> wrote:
> 
> 
>>Hello
>>I haven't received any responses on my original posting,
>>and it could very well be that it never made it to the newsgroup
>>(because I can't find it back on my news server here).
>>So I'm posting this again. Sorry if it *did* make it to
>>the group.. Please consider trying my test-program that is given
>>here and let me know how it works on your python installation.
>>
>>Thanks for any insight on this.
>>
> 
> Traceback (most recent call last):
>   File "C:\pywk\clp\irmen2.py", line 86, in ?
>     import hotshot, hotshot.stats, wait
> ImportError: No module named wait
> 
> Where does wait come from?

Aww, terribly sorry. Should test any code that I post.
(I called the test script "wait.py" on my system, that's
why it worked here, locally)

Here's a fixed version:

import time

def foo():
     # idle wait loop
     time.sleep(0.5)
def bar():
     # busy (CPU) wait loop
     s=time.time()
     while time.time()<(s+0.5):
         pass

def test():
     for i in range(10):
         foo()
         bar()

if __name__=="__main__":
     import hotshot, hotshot.stats
     import profile, pstats

     print "HOTSHOT profiling..."
     prof = hotshot.Profile("wait.prof")
     prof.runcall(test)
     prof.close()
     print "PROFILE DONE"
     stats = hotshot.stats.load("wait.prof")
     stats.strip_dirs()
     stats.sort_stats('time', 'calls')
     stats.print_stats(40)

     print "Normal profiler..."
     profile.run('test()', 'wait.prof')
     print "profile done"
     stats = pstats.Stats('wait.prof')
     stats.strip_dirs()
     stats.sort_stats('time', 'calls')
     stats.print_stats(40)



More information about the Python-list mailing list