Use cProfile.runctx
in a function specific for profiling.
import yt
import cProfile
from mpi4py import MPI
# Must include this line, if you are running in parallel.
yt.enable_parallelism()
myrank = MPI.COMM_WORLD.Get_rank()
step = 0
def yt_inline_ProjectionPlot( fields ):
# Load the data, just like using yt.load()
ds = yt.frontends.libyt.libytDataset()
# Do yt operation
prjz = yt.ProjectionPlot(ds, 'z', fields)
# Include this line, otherwise yt will save one copy in each rank.
if yt.is_root():
prjz.save()
def test_function():
global step
field = "Dens"
cProfile.runctx("yt_inline_ProjectionPlot( field )", globals(), locals(), filename="YT_cProfile_Step" + str(step) + "_" + str(myrank) + ".out")
step += 1
-
Install
gpro2dot
,dot
:pip38 install gprof2dot sudo apt install graphviz
-
Generate graph from previous section profiling output.
gprof2dot -f pstats YT_cProfile_Step0_0.out | dot -Tpng -o YT_RecordTimeGraph.png