pic_profiler Module

Lightweight profiler for named code regions with optional NVTX support


Uses

  • module~~pic_profiler~~UsesGraph module~pic_profiler pic_profiler module~pic_logger pic_logger module~pic_profiler->module~pic_logger module~pic_sorting pic_sorting module~pic_profiler->module~pic_sorting module~pic_timer pic_timer module~pic_profiler->module~pic_timer module~pic_types pic_types module~pic_profiler->module~pic_types module~pic_logger->module~pic_types module~pic_global_definitions pic_global_definitions module~pic_logger->module~pic_global_definitions module~pic_sorting->module~pic_types module~pic_optional_value pic_optional_value module~pic_sorting->module~pic_optional_value module~pic_timer->module~pic_types module~pic_io pic_io module~pic_timer->module~pic_io iso_c_binding iso_c_binding module~pic_types->iso_c_binding iso_fortran_env iso_fortran_env module~pic_types->iso_fortran_env module~pic_global_definitions->module~pic_types module~pic_io->module~pic_types module~pic_ascii pic_ascii module~pic_io->module~pic_ascii module~pic_optional_value->module~pic_types module~pic_ascii->module~pic_types

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private, parameter :: MAX_NAME_LEN = 64

Maximum length of region names

integer(kind=default_int), private, parameter :: MAX_REGIONS = 256

Maximum number of distinct profiling regions

type(profiler_state), private, save :: state

Global profiler state (module-level singleton)


Derived Types

type, private ::  profiler_state

Internal type for global profiler state

Components

Type Visibility Attributes Name Initial
logical, public :: enabled = .true.
logical, public :: initialized = .false.
integer(kind=default_int), public :: num_regions = 0
type(tracked_region), public :: regions(MAX_REGIONS)
integer(kind=default_int), public :: stack(MAX_REGIONS)

Stack of active region indices (for stack-based stop)

integer(kind=default_int), public :: stack_depth = 0

Current depth of the active region stack

type, private ::  tracked_region

Internal type for tracking a single profiling region

Components

Type Visibility Attributes Name Initial
logical, public :: active = .false.
integer(kind=default_int), public :: call_count = 0
character(len=MAX_NAME_LEN), public :: name = ''
logical, public :: nvtx_only = .false.

If true, only shows in NVTX timeline, not in text report

type(timer_type), public :: timer

PIC timer for this region

real(kind=dp), public :: total_time = 0.0_dp

Functions

public function profiler_get_time(name) result(t)

Get accumulated time for a named region

Read more…

Arguments

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

Return Value real(kind=dp)

private function find_or_create_region(name) result(idx)

Find an existing region by name or create a new one Returns -1 if MAX_REGIONS is exceeded

Arguments

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

Return Value integer(kind=default_int)


Subroutines

public subroutine profiler_disable()

Disable profiling temporarily

Read more…

Arguments

None

public subroutine profiler_enable()

Enable profiling (if it was disabled)

Arguments

None

public subroutine profiler_finalize()

Finalize the profiler and release resources

Read more…

Arguments

None

public subroutine profiler_init(enabled)

Initialize the profiler

Read more…

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: enabled

public subroutine profiler_report(title, root_region)

Print profiling report sorted by time

Read more…

Arguments

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

public subroutine profiler_reset()

Reset all timing data while keeping region names

Read more…

Arguments

None

public subroutine profiler_start(name, nvtx_only)

Start a named profiling region

Read more…

Arguments

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

public subroutine profiler_stop(name)

Stop a profiling region

Read more…

Arguments

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

private subroutine nvtx_range_pop()

Pop an NVTX range (no-op if PIC_USE_NVTX not defined)

Arguments

None

private subroutine nvtx_range_push(name)

Push an NVTX range (no-op if PIC_USE_NVTX not defined)

Arguments

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

private subroutine remove_from_stack(idx)

Remove a region index from the stack (helper for explicit stop)

Arguments

Type IntentOptional Attributes Name
integer(kind=default_int), intent(in) :: idx