RssMemoryGauge.F90 Source File


This file depends on

sourcefile~~rssmemorygauge.f90~~EfferentGraph sourcefile~rssmemorygauge.f90 RssMemoryGauge.F90 sourcefile~abstractgauge.f90 AbstractGauge.F90 sourcefile~rssmemorygauge.f90->sourcefile~abstractgauge.f90 sourcefile~abstractmeter.f90 AbstractMeter.F90 sourcefile~abstractgauge.f90->sourcefile~abstractmeter.f90 sourcefile~mapl_errorhandling.f90 MAPL_ErrorHandling.F90 sourcefile~abstractmeter.f90->sourcefile~mapl_errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~mapl_errorhandling.f90->sourcefile~mapl_throw.f90

Files dependent on this one

sourcefile~~rssmemorygauge.f90~~AfferentGraph sourcefile~rssmemorygauge.f90 RssMemoryGauge.F90 sourcefile~mapl_profiler.f90~2 MAPL_Profiler.F90 sourcefile~mapl_profiler.f90~2->sourcefile~rssmemorygauge.f90 sourcefile~memoryprofiler.f90 MemoryProfiler.F90 sourcefile~mapl_profiler.f90~2->sourcefile~memoryprofiler.f90 sourcefile~memoryprofiler.f90->sourcefile~rssmemorygauge.f90 sourcefile~abstractserver.f90 AbstractServer.F90 sourcefile~abstractserver.f90->sourcefile~mapl_profiler.f90~2 sourcefile~applicationsupport.f90 ApplicationSupport.F90 sourcefile~applicationsupport.f90->sourcefile~mapl_profiler.f90~2 sourcefile~demo.f90 demo.F90 sourcefile~demo.f90->sourcefile~mapl_profiler.f90~2 sourcefile~extdatadrivergridcomp.f90 ExtDataDriverGridComp.F90 sourcefile~extdatadrivergridcomp.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mapl.f90 MAPL.F90 sourcefile~mapl.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mapl_bundleio_test.f90 mapl_bundleio_test.F90 sourcefile~mapl_bundleio_test.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mapl_capgridcomp.f90 MAPL_CapGridComp.F90 sourcefile~mapl_capgridcomp.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mapl_generic.f90 MAPL_Generic.F90 sourcefile~mapl_generic.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mapl_nuopcwrappermod.f90 MAPL_NUOPCWrapperMod.F90 sourcefile~mapl_nuopcwrappermod.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mapl_verticalmethods.f90 MAPL_VerticalMethods.F90 sourcefile~mapl_verticalmethods.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mpi_demo.f90 mpi_demo.F90 sourcefile~mpi_demo.f90->sourcefile~mapl_profiler.f90~2 sourcefile~mpiserver.f90 MpiServer.F90 sourcefile~mpiserver.f90->sourcefile~mapl_profiler.f90~2 sourcefile~multigroupserver.f90 MultiGroupServer.F90 sourcefile~multigroupserver.f90->sourcefile~mapl_profiler.f90~2 sourcefile~regrid_util.f90 Regrid_Util.F90 sourcefile~regrid_util.f90->sourcefile~mapl_profiler.f90~2 sourcefile~serverthread.f90 ServerThread.F90 sourcefile~serverthread.f90->sourcefile~mapl_profiler.f90~2 sourcefile~test_advancedmeter.pf test_AdvancedMeter.pf sourcefile~test_advancedmeter.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_column.pf test_Column.pf sourcefile~test_column.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_distributedmeter.pf test_DistributedMeter.pf sourcefile~test_distributedmeter.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_exclusivecolumn.pf test_ExclusiveColumn.pf sourcefile~test_exclusivecolumn.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_meternode.pf test_MeterNode.pf sourcefile~test_meternode.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_meternodeiterator.pf test_MeterNodeIterator.pf sourcefile~test_meternodeiterator.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_namecolumn.pf test_NameColumn.pf sourcefile~test_namecolumn.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_percentagecolumn.pf test_PercentageColumn.pf sourcefile~test_percentagecolumn.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_profilereporter.pf test_ProfileReporter.pf sourcefile~test_profilereporter.pf->sourcefile~mapl_profiler.f90~2 sourcefile~test_timeprofiler.pf test_TimeProfiler.pf sourcefile~test_timeprofiler.pf->sourcefile~mapl_profiler.f90~2

Source Code

#include "unused_dummy.H"

module MAPL_RssMemoryGauge
   use, intrinsic :: iso_fortran_env, only: REAL64, INT64
   use MAPL_AbstractGauge
   implicit none
   private

   public :: RssMemoryGauge


   type, extends(AbstractGauge) :: RssMemoryGauge
      private
      integer(kind=INT64) :: baseline = 0
      character(:), allocatable :: command
   contains
      procedure :: get_measurement
   end type RssMemoryGauge

   interface RssMemoryGauge
      module procedure :: new_RssMemoryGauge
   end interface RssMemoryGauge

#define PID_T kind(1)

   interface
      function getpid() bind(c)
         integer(kind=PID_T) :: getpid
      end function getpid
   end interface

contains


   function new_RssMemoryGauge() result(gauge)
      type (RssMemoryGauge) :: gauge

      integer :: length

      call get_command_argument(0, length=length)
      allocate(character(len=length) :: gauge%command)
      call get_command_argument(0, value=gauge%command)

   end function new_RssMemoryGauge


   function get_measurement(this) result(mem_use)
      class (RssMemoryGauge), intent(inout) :: this
      real(kind=REAL64) :: mem_use

      integer :: unit
      integer(kind=INT64) :: MEM_UNITS = 1024 ! KB
      character(:), allocatable :: tmp_file

      integer(kind=PID_T) :: pid
      
      character(16) :: buffer
      character(:), allocatable :: pid_str

      _UNUSED_DUMMY(this)
      pid = getpid()
      write(buffer,'(i0)')pid
      pid_str = trim(buffer)
      tmp_file = 'tmp.pid'//pid_str
      call execute_command_line("ps -p " // pid_str // " -ocommand='',rss='' | awk '{ print $NF }'> " // tmp_file)
      
      open(newunit=unit, file=tmp_file, form='formatted', access='sequential', status='old')
      read(unit,*) mem_use
      mem_use = mem_use * MEM_UNITS
      close(unit, status='delete')


   end function get_measurement


end module MAPL_RssMemoryGauge