Python traceモジュールでは、プログラムの実行をトレースできます。個別に各プロセスのトレースを保存するためには、あなたが関数内のコードをラップする必要があります。その後、
def my_program(*args, **kwargs):
# insert your code here
pass
そしてtrace.Trace.runfunc
でそれを実行します。
import sys
import trace
# define Trace object: trace line numbers at runtime, exclude some modules
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
ignoremods=[
'inspect', 'contextlib', '_bootstrap',
'_weakrefset', 'abc', 'posixpath', 'genericpath', 'textwrap'
],
trace=1,
count=0)
# by default trace goes to stdout
# redirect to a different file for each processes
sys.stdout = open('trace_{:04d}.txt'.format(COMM_WORLD.rank), 'w')
tracer.runfunc(my_program)
今、各プロセスのトレースが可能になります別のファイルtrace_0001.txt
などで書かれています。低レベルの呼び出しを省略するには、とignoremods
引数を使用します。