11. Profiling#
Reference:
11.1. log_view#
-log_view [:filename]Prints summary of log information-log_view :filename.py:ascii_info_detailSaves logging information from each process as a Python file-log_view :filename.xml:ascii_xmlSaves a summary of the logging information in a nested format (see below for how to view it)-log_view :filename.txt:ascii_flamegraphSaves logging information in a format suitable for visualising as a Flame Graph (see below for how to view it)-log_view_memoryAlso display memory usage in each event-log_view_gpu_timeAlso display time in each event for GPU kernels (Note this may slow the computation)-log_allSaves 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.Eventfrom firedrake.petsc import PETSc with PETSc.Log.Event("foo"): do_something_expensive()
PETSc.Log.EventDecoratorfrom 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