TAU can automatically instrument all Python routines when the tau python package is imported. Add <TAUROOT>/<ARCH>/lib/bindings-<options> to the PYTHONPATH environment variable in order to use the TAU module.
To execute the program, tau.run routine is invoked with the name of the top level Python code. For e.g.,
#!/usr/bin/env python import tau from time import sleep def f2(): print "Inside f2: sleeping for 2 secs..." sleep(2) def f1(): print "Inside f1, calling f2..." f2() def OurMain(): f1() tau.run('OurMain()')
OurMain(), f1() and
f2() although there are no instrumentation calls in the
routines. To use this feature, TAU must be configured with the
-pythoninc=<dir> option (and -pythonlib=<dir> if running
under IBM). Before running the application, the environment variable
LD_LIBRARY_PATH should be set to include the TAU library
directory (where tau.py is stored). Manual instrumentation of Python
sources is also possible using the Python API and the
pytau package. For e.g.,
#!/usr/bin/env python import pytau from time import sleep x = pytau.profileTimer("A Sleep for excl 5 secs") y = pytau.profileTimer("B Sleep for excl 2 secs") pytau.start(x) print "Sleeping for 5 secs ..." sleep(5) pytau.start(y) print "Sleeping for 2 secs ..." sleep(2) pytau.stop(y) pytau.dbDump() pytau.stop(x)
shows how two timers x and y are created and used. Note, multiple timers can be nested, but not overlapping. Overlapping timers are detected by TAU at runtime and flagged with a warning (as exclusive time is not defined when timers overlap).