profiler_stop Subroutine

public subroutine profiler_stop(name)

Stop a profiling region

If name is omitted, stops the most recently started region (stack-based). If name is provided, stops that specific region (for explicit control). Time is accumulated across multiple start/stop pairs.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in), optional :: name

Calls

proc~~profiler_stop~~CallsGraph proc~profiler_stop profiler_stop proc~nvtx_range_pop nvtx_range_pop proc~profiler_stop->proc~nvtx_range_pop proc~remove_from_stack remove_from_stack proc~profiler_stop->proc~remove_from_stack proc~timer_get_elapsed_time timer_type%timer_get_elapsed_time proc~profiler_stop->proc~timer_get_elapsed_time

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: idx

Source Code

   subroutine profiler_stop(name)
      !! Stop a profiling region
      !!
      !! If name is omitted, stops the most recently started region (stack-based).
      !! If name is provided, stops that specific region (for explicit control).
      !! Time is accumulated across multiple start/stop pairs.
      character(len=*), intent(in), optional :: name
      integer(default_int) :: idx

#ifdef PIC_DISABLE_PROFILER
      return
#endif

      if (.not. state%enabled) return

      if (present(name)) then
         ! Find the region by name
         do idx = 1, state%num_regions
            if (trim(state%regions(idx)%name) == trim(name)) exit
         end do
         if (idx > state%num_regions) return
         if (.not. state%regions(idx)%active) return

         ! Remove from stack (may not be at top if using explicit names)
         call remove_from_stack(idx)
      else
         ! Stack-based: pop the most recent region
         if (state%stack_depth == 0) return
         idx = state%stack(state%stack_depth)
         state%stack_depth = state%stack_depth - 1
         if (.not. state%regions(idx)%active) return
      end if

      call state%regions(idx)%timer%stop()
      call nvtx_range_pop()

      state%regions(idx)%total_time = state%regions(idx)%total_time + &
                                      state%regions(idx)%timer%get_elapsed_time()
      state%regions(idx)%call_count = state%regions(idx)%call_count + 1
      state%regions(idx)%active = .false.
   end subroutine profiler_stop