My favorites | Sign in
Project Logo
                
Search
for
Updated Nov 11, 2008 by eyal.lotem
Labels: Featured
ExampleUse  
Example use of the tracer

Example use

Creating a trace

To use the tracer, just run pytracefile.py with a Python source.

For example, lets look at test.py:

import time

def g():
    time.sleep(0.1)
    print 'g'

def f():
    for i in xrange(10):
        g()

if __name__ == '__main__':
    f()

Lets run it:

$ python test.py
g
g
g
g
g
g
g
g
g
g

To get a trace, we can just run:

$ pytracefile.py test.py
g
g
g
g
g
g
g
g
g
g

This will create or overwrite a profile/trace output file called "profile.out". You can rename this to whatever you wish, but there is currently no way to control the output filename from pytracefile.py itself.

Note: The python paths are not currently fixed in accordance with normal script running, so you may need to use PYTHONPATH=

<scriptpath>
pytracefile.py .... in order for it to run correctly.

Viewing a trace

To view the trace, we can run:

$ pytracefile.py -v profile.out

which results in a Gtk+ trace viewer that looks like:

It is possible to have the viewer automatically be spawned immediately when the trace is complete. See pytracefile.py --help for more details.


Comment by sander.jonkers, Oct 02, 2008

How can I solve this error?

sander@fujitsu:~/usr/bin$ python hello-world.py Hello, World!

sander@fujitsu:~/usr/bin$ ./pytracefile.py python hello-world.py Traceback (most recent call last):

File "./pytracefile.py", line 5, in <module>
from pytracer import Tracer
ImportError?: No module named pytracer sander@fujitsu:~/usr/bin$

Comment by eyal.lotem, Nov 11, 2008

Sanders: Did you try the new release? Do you still get that error?

Comment by kamel.derouiche, May 11, 2009

Hi,, Recently tested pytrace on netbsd., please explain this error?

pytracefile.py -v profile.out Traceback (most recent call last):

File "/usr/pkg/bin/pytracefile.py", line 103, in <module>
main()
File "/usr/pkg/bin/pytracefile.py", line 100, in main
pytracerview.tracerview(view_prefix)
File "/usr/pkg/lib/python2.5/site-packages/pytracerview.py", line 344, in tracerview
graph_reader = Reader(open(filename, "rb"))
File "graphfile.pyx", line 54, in graphfile.Reader.cinit
graphfile.Error: graphfile_reader_init


Sign in to add a comment
Hosted by Google Code