473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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.

--Irmen

[original message follows]

Irmen de Jong wrote:
Okay I tried some profiling, but am uncertain about the
results I'm getting. They confuse the hell out of me.

I have a test program (see below) that essentially has
two loops that get called repeatedly. One that is an idle
wait loop, and one that is a busy-wait CPU hogger.
I wanted to see what profiling results that would give.
The total runtime of the program is 10 seconds, where 5
seconds are spent in the CPU-loop and 5 seconds in the idle
wait loop.

But what I'm getting is not what I expected.

For instance, with python2.3.4 on windows, it says:
(hotshot:) 21 function calls in 35.772 CPU seconds
(normal: ) 23 function calls in 10.008 CPU seconds
Python 2.4b1 on windows gives:
(hotshot:) 21 function calls in 0.001 CPU seconds
(normal: ) 260362 function calls in 6.724 CPU seconds

I know that timing information on Windows is sometimes
difficult to get, but the above is really weird. Anyway
so I also tried it on my Linux (mandrake 10) computer:

Python 2.3.4 on linux:
(hotshot:) 21 function calls in 17.542 CPU seconds
(normal: ) 23 function calls in 5.000 CPU seconds
Python 2.4b1 on linux:
(hotshot:) 21 function calls in 0.000 CPU seconds
(normal: ) 52474 function calls in 1.650 CPU seconds

Conclusion: only *one* of the above test runs gives the
right summary (in my opinion): the normal profiler of
python 2.3.4 on linux (5 CPU seconds).
The normal profiler of python 2.3.4 on windows also counts
the idle loop time apparently, and gives 10 CPU seconds.
But all the others are waaaay off!

(and I haven't event talked about the detailed function
call profiling statistics).

Can anybody please help me out? Am I doing something wrong,
or is the profiler just not reliable yet?

Confused-ly y'rs,
--Irmen de Jong
PS using the 'time' command on linux, when running the test
program, gives 0:20.19elapsed 50%CPU which is what I expected.
-------------------- test program ---------------
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, wait
import profile, pstats

print "HOTSHOT profiling..."
prof = hotshot.Profile("wait.prof")
prof.runcall(wait.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('wait.test()', 'wait.prof')
print "profile done"
stats = pstats.Stats('wait.prof')
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(40)

Jul 18 '05 #1
2 2136
On Wed, 03 Nov 2004 00:43:31 +0100, Irmen de Jong <irmen@-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?

Regards,
Bengt Richter
Jul 18 '05 #2
Bengt Richter wrote:
On Wed, 03 Nov 2004 00:43:31 +0100, Irmen de Jong <irmen@-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)
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: KefX | last post by:
Hi guys! I'm still a bit of a Python newbie, but regardless I decided to embed Python into a plugin for a freeware (closed-source) Windows music program called Jeskola Buzz. (Man, I can't believe...
4
by: KefX | last post by:
Hey...as for what I'm doing with Python, look at my post "Strange Hotshot problem". To make a long story short, I'm embedding Python in order to write a plugin to a freeware music program; the...
0
by: Irmen de Jong | last post by:
Hi, 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...
0
by: Rodrigo Daunaravicius | last post by:
I'm having trouble understanding hotshot's results. It's the first time I use a profiler. I'm trying to profile a loop that takes almost six hours (~21000 seconds) to execute in production. The...
0
by: Irmen de Jong | last post by:
Okay I tried some profiling, but am uncertain about the results I'm getting. They confuse the hell out of me. I have a test program (see below) that essentially has two loops that get called...
0
by: Charles Hartman | last post by:
I've used profile before, but wanted to get more information so I thought I'd try hotshot instead. It works fine when used like profile. But when I run it using this line, prof =...
0
by: Charles Hartman | last post by:
(I asked this a day or two ago; if there was an answer, I missed it. Anybody using hotshot?) I've used profile before, but wanted to get more information so I thought I'd try hotshot instead....
6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
1
by: Geert Jansen | last post by:
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....
13
by: guitarromantic | last post by:
Hey everyone. I'm editing some stuff I did last summer, trying to bugfix and improve stuff. One improvement (or an oversight of the original design) is adding dynamic <title> tags to my pages....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.