Hi Kristjan and folks:
Once again thanks for the help. And thanks for the explanation. However I am
still having trouble. I removed the import blue, line 22, and line 20 (the
Timer than makes a reference later to blue.os()).
here is a code fragment:
if __name__ == "__main__":
profiler = Profile()
profiler.run('body()')
/home/user> python profiled.py 1 100
Traceback (most recent call last):
File "profiled.py", line 63, in <module>
profiler.run('body()')
File "/usr/local/lib/python2.5/profile.py", line 456, in run
return self.runctx(cmd, dict, dict)
File "/home/user/slprofile.py", line 51, in runctx
profile.Profile.runctx(self, cmd, globals, locals)
File "/usr/local/lib/python2.5/profile.py", line 460, in runctx
sys.setprofile(self.dispatcher)
AttributeError: Profile instance has no attribute 'dispatcher'
I have included a sample programme. Eventually I want to run slprofile inside a
server. I would greatly appreciate it if you can show me how to properly use
slprofile.py
Cheers,
Andrew
--- On Fri, 12/19/08, Kristján Valur Jónsson <[email protected]> wrote:
> From: Kristján Valur Jónsson <[email protected]>
> Subject: RE: [Stackless] Question abut slprofile.py
> To: "Kristján Valur Jónsson" <[email protected]>,
> "[email protected]" <[email protected]>, "[email protected]"
> <[email protected]>
> Date: Friday, December 19, 2008, 6:52 AM
> Blue is a module that is part of the eve engine.
> It is used in this module solely to provide a timer. Just
> remove it, and line 22, and then you are all set.
>
> Stackless has, since python 2.3, I think, a special
> "per tasklet" trace flag. That is, stackless
> saves and restores the trace flag in the python trhread
> state for each tasklet. This is an attempt, I think, at
> making profiling (and tracing) sensible, by focusing on a
> single tasklet only.
> It is not very useful for us, however.
> We want to have a running application, and then, just turn
> on profiling (using slprofile.Profile.start()) and stop it
> using slprofile.Profile.stop(), ans see what the app has
> been upto in the meantime.
> In order to do this, we had to disable the per-tasklet
> saving feature of stackless.
>
> I attach the three files that have the relevant
> modifications, for stackless 2.5
>
> Good luck,
> Kristján
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Kristján Valur Jónsson
> Sent: 18. desember 2008 09:11
> To: [email protected]; [email protected]
> Subject: Re: [Stackless] Question abut slprofile.py
>
> Attached.
> Note that what we also used is a custom flag in stackless,
> "globaltrace" which makes the tracing state of
> python global (for the thread) instead of being maintained
> for each tasklet.
> Not only does it allow us to take a profiling
> "snapshot" of a running application, it also
> prevented crashes in stackless, which was crashing horribly
> if any exceptions were being raised in the trace callbacks.
> Actually, the last issue was fixed by us changing slprofile
> to not rely on the stackless tasklet switching callbacks,
> which tend to have weird behaviour, but rather just querying
> for the current tasklet in the trace functions.
>
> If you want, I can provide you with the changed files to
> the the "globaltrace" functionality, but it is a
> little more work.
> K
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Andrew
> Francis
> Sent: 17. desember 2008 22:17
> To: [email protected]
> Subject: [Stackless] Question abut slprofile.py
>
> Hi Folks:
>
> A while ago, I recall a thread about using a modified
> profile module, slprofile for use with Stackless. Where can
> I find slprofile.py and its documentation?
>
> Thanks,
> Andrew
>
>
>
>
> _______________________________________________
> Stackless mailing list
> [email protected]
> http://www.stackless.com/mailman/listinfo/stackless
"""
The purpose of serverTest.py is to examine how channel preferences change
scheduling order
For this example, there is one producer and multiple consumers
usage:
serverTest.py preference number_of_consumer_taskets
-1 prefer receiver
1 prefer sender
"""
import profile
import sys
import string
import stackless
import time
OUTPUT = True
MAX = 0
from slprofile import Profile
def producer(channel):
global MAX
pStart = time.time()
for i in range(0, MAX):
if OUTPUT:
print "producer about to send"
channel.send('a')
if OUTPUT:
print "producer sent", "next", name[stackless.getcurrent().next]
pFinish = time.time() - pStart
print "%s: %f %s: %f" % ("producer finished", pFinish, "throughput", MAX/pFinish)
def consumer(channel, n):
cStart = time.time()
if OUTPUT:
print "consumer ", n, "about to receive"
channel.receive()
if OUTPUT:
print "consumer ", n, "time: ", time.time() - cStart, "received next",name[stackless.getcurrent().next]
def body():
name = {}
channel = stackless.channel()
channel.preference = string.atoi(sys.argv[1])
MAX = string.atoi(sys.argv[2])
start = time.time()
for i in range(0,MAX):
t = stackless.tasklet(consumer)(channel, i)
name[t] = i
t = stackless.tasklet(producer)(channel)
name[t] = "producer"
stackless.run()
print "time", time.time() - start
if __name__ == "__main__":
profiler = Profile()
profiler.run('body()')
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless