473,569 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Hotshot problem...

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 how many people keep telling me
"Extend Python instead!" when clearly I can't do that in this case. If somebody
here tells me this, I will explode in an appropriately gory fashion.) It's a
great program, and it works mainly on plugins other people write. Well, I had
been working on a guitar synth plugin in the summer, which started to sound
good. Then I lost the code (I was trying to rewrite it anyway but I wanted to
keep it as reference.) So I began to think about ways to try to make it better.

I eventually hit on the idea of using a scripting language to do this. I
started designing a language with a simple grammar (I like doing this kind of
thing in a semi-compulsive manner, heh)...but I tossed that aside, worked on a
ROM hacking/translating project some...well, my ROM hacking project required me
to write a small script, so I decided it was finally time to learn Python.

Geez, I love this language. :)

Anyway, now it's a couple months later, translation project gets put on hold
for reasons outside of my control, so I'm trying the guitar synth again. And I
thought...why don't I use Python? I was told I could never get it to run in
real time (we're talking about DSP, after all). I was about to give up on
pursuing the idea when I heard about Psyco, which should help speed up
everything that isn't rewritten as a C extension. I decided I'll give that a
shot, no matter how ridiculous the idea seems. My experience with ridiculous
ideas is that sometimes they actually work. :)

Well, to make a long story longer, I got it running and it does produce sound
(not the sound I would like to hear from it, though!) But brokenness of the
sound suggested that it's running too freakin' slow, and it was: Buzz's CPU
display said my own plugin was hogging the whole CPU! Well, okay, it's not
hopeless yet, I can profile it and see what I can do about the bottlenecks.

Which finally leads me to my problem: I can't get Hotshot to work properly. I
can't fix a bottleneck if I don't know where it is! ;) Remember, I'm calling
various Python functions from C++. See, in my module's init code, I'm basically
I'm creating the hotshot.Profile object with the required path, bound to
_profiler, then I do _profiler.start () ...at the very end, I do
_profiler.stop( ) and _profiler.close (), and then I try to load the stats back
with hotshot.stats.l oad() with the same path. Well, it finds the file just
fine, but it can't read it. It raises an IndexError from trying to pop an empty
list or some such. I've tested Hotshot with simple test scripts in pure Python
and it works just fine. I thought Psyco might be the problem, but I commented
out all use of Psyco in my script and the problem still exists, so I think the
use of C++ to call Python code is messing it up.

Is this a bug in the Hotshot package? Is there a workaround? Oh, yes, I also
uploaded the offending profiler stats snapshot, in case you want to look at it.

http://members.aol.com/keflimarcvsx/hotshot.prof

If you open it in the interactive Python interpreter and try
hotshot.stats.l oad('hotshot.pr of') you should get the same result I do,
complete with traceback.

- Kef

P.S. Sorry for making this post so long :P
Jul 18 '05 #1
6 1697
KefX:
Well, it finds the file just
fine, but it can't read it. It raises an IndexError from trying to pop an empty list or some such. I've tested Hotshot with simple test scripts in pure Python and it works just fine.


I saw a similar issue that could be 'fixed' by running Python in
optimized '-O' mode rather than normal mode as -O turns off assertions.

Neil
Jul 18 '05 #2
I wrote:
I saw a similar issue that could be 'fixed' by running Python in
optimized '-O' mode rather than normal mode as -O turns off assertions.


Disregard that - it doesn't solve your problem.

Neil
Jul 18 '05 #3
Nope...doesn't fix anything.

- Kef
I saw a similar issue that could be 'fixed' by running Python in
optimized '-O' mode rather than normal mode as -O turns off assertions.

Jul 18 '05 #4
Well, I found a rather unhelpful non-solution (just posting about it so nobody
else suggests it). I figured that the Work() function (being called the most
often given the architecture of the plugin, and the only one called from the
C++ code while outputting sound) would probably have the biggest bottleneck, so
I renamed my Work function to Work_Impl, and added a new Work function with
this:

def Work(num_sample s):
if _profiler is not None:
return _profiler.runca ll(Work_Impl, num_samples)
else:
return Work_Impl(num_s amples)

This technically worked (my code finally produced a readable log in the proper
place). However, it was a failure in that this seemed to circumvent Psyco
completely (making my code WAY too slow), and the results weren't too helpful
in any case. An obvious solution is to make sure to call psyco.bind(Work _Impl),
and while this did speed it up I get no information on the functions that
Work_Impl called. Is there any other way to profile code that uses Psyco?
(Other than the older 'profile' module, which is probably even less likely to
work well...)
Jul 18 '05 #5

kefx> (Other than the older 'profile' module, which is probably even
kefx> less likely to work well...)

The profile module might help, though since it's written in Python, it will
definitely run slower than the hotshot profiler (what about profile+psyco?) .
If nothing else you should be able to get some call counts. Another option
is to use the trace module to count executed lines. If you submit a bug
report to SourceForge (http://sourceforge.net/projects/python and assign it
to Fred Drake (fdrake I believe) you'll at least be alerting the primary
author of the hotshot code.

Skip
Jul 18 '05 #6
"KefX" <ke**********@a ol.comNOSPAM> wrote in message
news:20******** *************** ****@mb-m05.aol.com...
See, in my module's init code, I'm basically
I'm creating the hotshot.Profile object with the required path, bound to
_profiler, then I do _profiler.start () ...at the very end, I do
_profiler.stop( ) and _profiler.close (), and then I try to load the stats back with hotshot.stats.l oad() with the same path. Well, it finds the file just
fine, but it can't read it. It raises an IndexError from trying to pop an empty list or some such.


Not that this is going to help, but: me too. I've seen the exact same
problem -- loading saved stats throws an exception -- when profiling with
Hotshot.

This was in a pure-Python project, and it seemed sensitive to the exact code
being profiled: it'd work fine on some inputs, but then I'd change one or
two lines to attempt an optimisation and it'd fail.

I ended up giving up and going back to profile -- slower, but livable with.

James
Jul 18 '05 #7

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

Similar topics

0
1584
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 instance I have this output: 3 function calls in 26.931 CPU seconds Ordered by: internal time, call count
0
1228
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 profiler stats, however, give me a total of 16.903 CPU seconds (that's ~17 seconds, right?). The results *are* relevant, as they helped me to pull...
0
464
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 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...
0
1398
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 = hotshot.Profile('ScanHot.prof', lineevents=1) though it runs all right, when I try to load the resulting file I get this: >>> hs =...
0
1198
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. It works fine when used like profile. But when I run it using this line, prof = hotshot.Profile('ScanHot.prof', lineevents=1) though it runs all...
6
3738
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 speed things up implementing some of the functions in C. So I need profiling. I first tried to use the default python profiler, but profiling my...
1
1754
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. 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...
0
1077
by: Lars Woetmann | last post by:
what is the definition of sub-functions in the hotshot profiler? and just as important what is not sub-functions from the output I can see that functions I made and functions in /usr/lib/python2.4/textwrap.py is considered sub-functions, but I call a lot of other functions in the python library and they are not in the output, so how come...
1
1925
by: Yang | last post by:
Note: I realize hotshot is obsoleted by cProfile, but 2.5 breaks several packages I depend on. I'm using Python 2.4.3. I'm getting an AssertionError on "assert not self._stack" when calling hotshot.stats.load() on my app's hotshot profile. The app consistently causes hotshot to generate such a problematic profile, but I have no idea what's...
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.