10. Profiling#

Reference:

  1. https://www.firedrakeproject.org/optimising.html

  2. https://petsc.org/main/manual/profiling/

  3. https://petsc.org/main/manualpages/Sys/PetscInitialize/

  4. https://petsc.org/main/manualpages/Profiling/PetscLogView/

10.1. log_view#

  1. -log_view [:filename] Prints summary of log information

  2. -log_view :filename.py:ascii_info_detail Saves logging information from each process as a Python file

  3. -log_view :filename.xml:ascii_xml Saves a summary of the logging information in a nested format (see below for how to view it)

  4. -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)

  5. -log_view_memory Also display memory usage in each event

  6. -log_view_gpu_time Also display time in each event for GPU kernels (Note this may slow the computation)

  7. -log_all Saves a file Log.rank for each MPI rank with details of each step of the computation

  8. -log_trace [filename] Displays a trace of what each process is doing

10.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.EventPETSc.Log.EventDecorator 添加自定义事件, 用于测量代码块的运行事件. 如果如上运行代码, 事件名称和运行时间将会记录在上述 profile.txt 中.

  1. PETSc.Log.Event

    from firedrake.petsc import PETSc
    
    with PETSc.Log.Event("foo"):
        do_something_expensive()
    
  2. PETSc.Log.EventDecorator

    from firedrake.petsc import PETSc
    
    @PETSc.Log.EventDecorator("foo")
    def do_something_expensive():
        ...
    

10.1.2. -log_view :profile.txt#

Ref: https://petsc.org/release/manual/profiling/#interpreting-log-view-output-parallel-performance