From 1635c965fea07f50cfe651feb91e0b4538427f69 Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Thu, 7 Aug 2025 18:27:03 +0200 Subject: [PATCH] Add Fortran API --- rvprof_module.f90 | 80 ++++++++++++++++++++++++++++++++++++++++++++ src/rvprof_fortran.c | 28 ++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 rvprof_module.f90 create mode 100644 src/rvprof_fortran.c diff --git a/rvprof_module.f90 b/rvprof_module.f90 new file mode 100644 index 0000000..2869228 --- /dev/null +++ b/rvprof_module.f90 @@ -0,0 +1,80 @@ +! Fortran API + +module rvprof + use iso_c_binding + use iso_fortran_env, only: int64 + implicit none + + private + + public :: rvprof_init + public :: rvprof_finalize + public :: rvprof_region_begin + public :: rvprof_region_end + public :: rvprof_set_cpu_frequency + public :: rvprof_set_program_name + + interface + ! no need to call directly anymore + subroutine rvprof_init_c(filename) bind(C, name="rvprof_init_c") + use iso_c_binding + character(c_char), intent(in) :: filename(*) + end subroutine rvprof_init_c + + ! no need to call directly anymore + subroutine rvprof_finalize_c() bind(C, name="rvprof_finalize_c") + use iso_c_binding + end subroutine rvprof_finalize_c + + subroutine rvprof_region_begin_c(name) bind(C, name="rvprof_region_begin_c") + use iso_c_binding + character(c_char), intent(in) :: name(*) + end subroutine rvprof_region_begin_c + + subroutine rvprof_region_end_c(name) bind(C, name="rvprof_region_end_c") + use iso_c_binding + character(c_char), intent(in) :: name(*) + end subroutine rvprof_region_end_c + + ! no need to call directly anymore + subroutine rvprof_set_program_name_c(name) bind(C, name="rvprof_set_program_name_c") + use iso_c_binding + character(c_char), intent(in) :: name(*) + end subroutine rvprof_set_program_name_c + end interface + +contains + ! no need to call directly anymore + subroutine rvprof_init(filename) + character(len=*), intent(in), optional :: filename + + if (present(filename)) then + call rvprof_init_c(trim(filename)//c_null_char) + else + ! Use automatic filename generation: program_name_rvprof.log + call rvprof_init_c(''//c_null_char) + end if + end subroutine rvprof_init + + ! no need to call directly anymore + subroutine rvprof_finalize() + call rvprof_finalize_c() + end subroutine rvprof_finalize + + subroutine rvprof_region_begin(name) + character(len=*), intent(in) :: name + call rvprof_region_begin_c(trim(name)//c_null_char) + end subroutine rvprof_region_begin + + subroutine rvprof_region_end(name) + character(len=*), intent(in) :: name + call rvprof_region_end_c(trim(name)//c_null_char) + end subroutine rvprof_region_end + + ! no need to call directly anymore + subroutine rvprof_set_program_name(name) + character(len=*), intent(in) :: name + call rvprof_set_program_name_c(trim(name)//c_null_char) + end subroutine rvprof_set_program_name + +end module rvprof diff --git a/src/rvprof_fortran.c b/src/rvprof_fortran.c new file mode 100644 index 0000000..08e7c4d --- /dev/null +++ b/src/rvprof_fortran.c @@ -0,0 +1,28 @@ +#include "rvprof_internal.h" + +// no need to call directly anymore +void rvprof_init_c(const char* filename) { + if (!filename || strlen(filename) == 0) { + rvprof_init(NULL); + } else { + rvprof_init(filename); + } +} + +// no need to call directly anymore +void rvprof_finalize_c(void) { + rvprof_finalize(); +} + +void rvprof_region_begin_c(const char* name) { + rvprof_region_begin(name); +} + +void rvprof_region_end_c(const char* name) { + rvprof_region_end(name); +} + +// no need to call directly anymore +void rvprof_set_program_name_c(const char* name) { + rvprof_set_program_name(name); +}