11. Profiling#
Reference:
11.1. log_view
#
-log_view [:filename]
Prints summary of log information-log_view :filename.py:ascii_info_detail
Saves logging information from each process as a Python file-log_view :filename.xml:ascii_xml
Saves a summary of the logging information in a nested format (see below for how to view it)-log_view :filename.txt:ascii_flamegraph
Saves logging information in a format suitable for visualising as a Flame Graph (see below for how to view it)-log_view_memory
Also display memory usage in each event-log_view_gpu_time
Also display time in each event for GPU kernels (Note this may slow the computation)-log_all
Saves a file Log.rank for each MPI rank with details of each step of the computation-log_trace [filename]
Displays a trace of what each process is doing
11.1.1. Flame graph#
运行代码时加上选现 -log_view :profile.txt:ascii_flamegraph
, 将会生成文件 profile.txt
, 该文件会记录某些代码块的运行时间, 可用于性能分析. 可以通过在线工具 https://www.speedscope.app/ 可视化该文件. 示例代码如下:
python test.py -log_view :profile.txt:ascii_flamegraph
可以通过 PETSc.Log.Event
和 PETSc.Log.EventDecorator
添加自定义事件, 用于测量代码块的运行事件. 如果如上运行代码, 事件名称和运行时间将会记录在上述 profile.txt
中.
PETSc.Log.Event
from firedrake.petsc import PETSc with PETSc.Log.Event("foo"): do_something_expensive()
PETSc.Log.EventDecorator
from firedrake.petsc import PETSc @PETSc.Log.EventDecorator("foo") def do_something_expensive(): ...
11.1.2. -log_view :profile.txt
#
Ref: https://petsc.org/release/manual/profiling/#interpreting-log-view-output-parallel-performance