Print profiling report sorted by time
If root_region is specified, percentages are relative to that region’s total time. Otherwise, percentages are relative to the sum of all regions.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in), | optional | :: | title | ||
| character(len=*), | intent(in), | optional | :: | root_region |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=default_int), | private | :: | j | ||||
| character(len=256), | private | :: | line | ||||
| integer(kind=default_int), | private | :: | n_print | ||||
| real(kind=dp), | private | :: | pct | ||||
| integer(kind=default_int), | private | :: | region_map(MAX_REGIONS) | ||||
| integer(kind=default_int), | private | :: | root_idx | ||||
| integer(kind=int_index), | private | :: | sort_indices(0:MAX_REGIONS-1) | ||||
| real(kind=dp), | private | :: | times_to_sort(0:MAX_REGIONS-1) | ||||
| real(kind=dp), | private | :: | total_time |
subroutine profiler_report(title, root_region) !! Print profiling report sorted by time !! !! If root_region is specified, percentages are relative to that region's !! total time. Otherwise, percentages are relative to the sum of all regions. character(len=*), intent(in), optional :: title character(len=*), intent(in), optional :: root_region integer(default_int) :: i, j, root_idx, n_print integer(default_int) :: region_map(MAX_REGIONS) ! 0-based arrays for sort_index real(dp) :: times_to_sort(0:MAX_REGIONS - 1) integer(int_index) :: sort_indices(0:MAX_REGIONS - 1) real(dp) :: total_time, pct character(len=256) :: line #ifdef PIC_DISABLE_PROFILER return #endif if (state%num_regions == 0) return ! Find root region if specified root_idx = -1 if (present(root_region)) then do i = 1, state%num_regions if (trim(state%regions(i)%name) == trim(root_region)) then root_idx = i exit end if end do end if ! Calculate total time if (root_idx > 0) then total_time = state%regions(root_idx)%total_time else total_time = 0.0_dp do i = 1, state%num_regions total_time = total_time + state%regions(i)%total_time end do end if ! Build list of regions to print (excluding root and nvtx_only regions) ! and prepare arrays for sorting n_print = 0 do i = 1, state%num_regions if (i /= root_idx .and. .not. state%regions(i)%nvtx_only) then region_map(n_print + 1) = i times_to_sort(n_print) = state%regions(i)%total_time n_print = n_print + 1 end if end do ! Sort by time descending using PIC's sort_index if (n_print > 0) then call sort_index(times_to_sort(0:n_print - 1), sort_indices(0:n_print - 1), reverse=.true.) end if ! Print report call logger%info('') call logger%info('============================================================') if (present(title)) then call logger%info('Profiler Report: '//trim(title)) else call logger%info('Profiler Report') end if call logger%info('============================================================') call logger%info(' Region Time (s) Calls % ') call logger%info('------------------------------------------------------------') do i = 0, n_print - 1 ! sort_indices(i) is a 1-based index (Fortran standard) into times_to_sort ! region_map(sort_indices(i)) gives us the actual region index j = region_map(sort_indices(i)) if (total_time > 0.0_dp) then pct = 100.0_dp*state%regions(j)%total_time/total_time else pct = 0.0_dp end if write (line, '(A,A32,F12.6,I8,F8.1)') ' ', & state%regions(j)%name, & state%regions(j)%total_time, & state%regions(j)%call_count, & pct call logger%info(trim(line)) end do call logger%info('------------------------------------------------------------') write (line, '(A,F12.6)') ' Total: ', total_time call logger%info(trim(line)) call logger%info('============================================================') #ifdef PIC_USE_NVTX call logger%info(' (NVTX enabled - use Nsight Systems for GPU timeline)') #else call logger%info(' (NVTX disabled - compile with -DPIC_USE_NVTX to enable)') #endif end subroutine profiler_report