Index: XIOS3/trunk/scripts/index_load.html
===================================================================
--- XIOS3/trunk/scripts/index_load.html	(revision 2418)
+++ XIOS3/trunk/scripts/index_load.html	(revision 2418)
@@ -0,0 +1,75 @@
+
+<head>
+  <script src="https://cdn.anychart.com/releases/8.11.0/js/anychart-base.min.js" type="text/javascript"></script>
+  <script src="https://cdn.anychart.com/releases/8.11.0/js/anychart-stock.min.js"></script>
+
+</head>
+
+<body>
+  <!--
+      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
+
+    <script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
+
+    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
+    <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" type="text/css" />
+
+    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
+    <link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css" rel="stylesheet" type="text/css" />
+
+    <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
+    <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
+
+  <div id="container" >
+    <div class="row">
+      <label class="btn btn-primary" for="file">
+        <input type="file" id="file" style="display:none" onchange="$('#upload-file-info').html(this.files[0].name)">
+        Load a JS XIOS memory file
+      </label>
+      <button type="button" class="btn btn-default disabled" id="upload-file-info">...</button>
+    </div>
+  </div>
+  -->
+
+  <div id="container" ></div>
+  <script src="mem_4.js" ></script>
+
+  <script>
+    anychart.onDocumentLoad(function () {
+
+      
+        
+    // create a data table using this data
+    var dataTable = anychart.data.table();
+    dataTable.addData(get_xios_mem_data());
+ 
+    mapping_mem = dataTable.mapAs();
+    mapping_mem.addField('value', 2);
+    mapping_event = dataTable.mapAs();
+    mapping_event.addField('value', 1);
+ 
+    // create a stock chart
+    var chart = anychart.stock();
+
+    // create a plot on the chart
+    var plot = chart.plot(0);		
+	
+    // create a line series
+    var lineSeries2 = plot.line(mapping_event);
+    lineSeries2.name("Event");
+    var lineSeries1 = plot.line(mapping_mem);
+    lineSeries1.name("Mo");
+	
+    // set the container id
+    chart.container("container");
+ 
+    // initiate drawing the chart
+    chart.draw();
+
+
+
+	
+    });
+  </script>
+  
+</body>
Index: XIOS3/trunk/src/client.cpp
===================================================================
--- XIOS3/trunk/src/client.cpp	(revision 2417)
+++ XIOS3/trunk/src/client.cpp	(revision 2418)
@@ -18,4 +18,5 @@
 #include "workflow_graph.hpp"
 #include "release_static_allocation.hpp"
+#include "mem_checker.hpp"
 
 namespace xios
@@ -520,4 +521,5 @@
       report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ;
       report(100)<<CTimer::getAllCumulatedTime()<<endl ;
+      report(100)<<CMemChecker::getAllCumulatedMem()<<endl ;
       CWorkflowGraph::drawWorkFlowGraph_client();
 
Index: XIOS3/trunk/src/cxios.cpp
===================================================================
--- XIOS3/trunk/src/cxios.cpp	(revision 2417)
+++ XIOS3/trunk/src/cxios.cpp	(revision 2418)
@@ -151,4 +151,5 @@
       CClient::openErrorStream();
     }
+    CMemChecker::logMem("CXios::initClientSide");
   }
   CATCH
@@ -156,4 +157,6 @@
   void CXios::clientFinalize(void)
   {
+     CMemChecker::logMem("CXios::clientFinalize", true);
+
      CClient::finalize() ;
           
@@ -233,5 +236,4 @@
 #endif
     CMemChecker::get("xios").suspend() ;
-    report(0)<<CMemChecker::getAllCumulatedMem() ;
     CServer::closeInfoStream();
   }
Index: XIOS3/trunk/src/filter/model_to_client_source_filter.cpp
===================================================================
--- XIOS3/trunk/src/filter/model_to_client_source_filter.cpp	(revision 2417)
+++ XIOS3/trunk/src/filter/model_to_client_source_filter.cpp	(revision 2418)
@@ -5,4 +5,5 @@
 #include <limits> 
 #include "workflow_graph.hpp"
+#include "mem_checker.hpp"
 
 namespace xios
@@ -37,4 +38,6 @@
     packet->data.resize(connector->getDstSize()) ;
     connector->transfer(data, packet->data, nanValue) ;
+
+    CMemChecker::logMem( "CModelToClientSourceFilter::streamData" );
 
     if (hasMissingValue_)
Index: XIOS3/trunk/src/filter/temporal_filter.cpp
===================================================================
--- XIOS3/trunk/src/filter/temporal_filter.cpp	(revision 2417)
+++ XIOS3/trunk/src/filter/temporal_filter.cpp	(revision 2418)
@@ -3,4 +3,5 @@
 #include "calendar_util.hpp"
 #include "workflow_graph.hpp"
+#include "mem_checker.hpp"
 
 namespace xios
@@ -117,4 +118,6 @@
           packet = data[0];
 
+	CMemChecker::logMem( "CTemporalFilter::apply" );
+
         isFirstOperation = false;
         graphCycleCompleted = true;
Index: XIOS3/trunk/src/interface/c/icmem_checker.cpp
===================================================================
--- XIOS3/trunk/src/interface/c/icmem_checker.cpp	(revision 2418)
+++ XIOS3/trunk/src/interface/c/icmem_checker.cpp	(revision 2418)
@@ -0,0 +1,24 @@
+
+#include "mem_checker.hpp"
+#include <string>
+#include <iostream>
+
+
+using namespace xios;
+
+extern "C"
+{
+  void cxios_mem_checker_get(double* mem)
+  {
+    *mem=CMemChecker::getMemRSS();
+  }
+
+  void cxios_mem_checker_log(const char* mem_id, int len_mem_id, bool* finalize)
+  {
+    std::string str(mem_id,len_mem_id);
+    CMemChecker::logMem(str, *finalize);
+  }
+
+}
+
+
Index: XIOS3/trunk/src/interface/fortran/imem_checker.F90
===================================================================
--- XIOS3/trunk/src/interface/fortran/imem_checker.F90	(revision 2418)
+++ XIOS3/trunk/src/interface/fortran/imem_checker.F90	(revision 2418)
@@ -0,0 +1,46 @@
+#include "xios_fortran_prefix.hpp"
+
+MODULE IMEM_CHECKER
+   USE, INTRINSIC :: ISO_C_BINDING
+   
+   INTERFACE ! Ne pas appeler directement/Interface FORTRAN 2003 <-> C99
+      
+      SUBROUTINE cxios_mem_checker_get(mem) BIND(C)
+         USE ISO_C_BINDING
+         REAL     (kind = C_DOUBLE), VALUE        :: mem
+      END SUBROUTINE cxios_mem_checker_get
+
+      SUBROUTINE cxios_mem_checker_log(memid, memid_size, finalize) BIND(C)
+         USE ISO_C_BINDING
+         CHARACTER(kind = C_CHAR)  , DIMENSION(*) :: memid
+         INTEGER  (kind = C_INT)   , VALUE        :: memid_size
+         LOGICAL  (kind = C_BOOL)                 :: finalize
+      END SUBROUTINE cxios_mem_checker_log
+       
+   END INTERFACE
+
+   CONTAINS ! Fonctions disponibles pour les utilisateurs.
+
+   FUNCTION xios(mem_checker_get)() RESULT(mem)
+      IMPLICIT NONE
+      REAL                                       :: mem
+      REAL(KIND=C_DOUBLE)                        :: mem_
+      
+      CALL cxios_mem_checker_get(mem_)
+      mem=mem_
+   END FUNCTION xios(mem_checker_get)
+ 
+   SUBROUTINE xios(mem_checker_log)(mem_id, finalize)
+   USE ISO_C_BINDING
+      IMPLICIT NONE
+      CHARACTER(len = *) , INTENT(IN) :: mem_id
+      LOGICAL, OPTIONAL,INTENT(IN)    :: finalize
+      LOGICAL (KIND=C_BOOL)           :: finalize_               
+
+      finalize_=.FALSE.
+      IF (PRESENT(finalize)) finalize_ = finalize
+      CALL cxios_mem_checker_log(mem_id, len(mem_id), finalize_)
+
+   END SUBROUTINE xios(mem_checker_log)
+
+END MODULE IMEM_CHECKER
Index: XIOS3/trunk/src/interface/fortran/ixios.F90
===================================================================
--- XIOS3/trunk/src/interface/fortran/ixios.F90	(revision 2417)
+++ XIOS3/trunk/src/interface/fortran/ixios.F90	(revision 2418)
@@ -38,4 +38,5 @@
                   ASSIGNMENT(=)
 USE itimer, ONLY : xios(timer_resume), xios(timer_suspend), xios(timer_reset), xios(timer_get_time)
+USE imem_checker, ONLY : xios(mem_checker_get), xios(mem_checker_log)
 
 USE ifield, ONLY : txios(field), txios(fieldgroup), xios(is_valid_field), xios(is_valid_fieldgroup)
Index: XIOS3/trunk/src/mem_checker.cpp
===================================================================
--- XIOS3/trunk/src/mem_checker.cpp	(revision 2417)
+++ XIOS3/trunk/src/mem_checker.cpp	(revision 2418)
@@ -7,4 +7,9 @@
 #include <fstream>
 
+#include <fcntl.h>
+#include <iomanip>
+#include <unistd.h>
+#include <cstring>
+
 namespace xios
 {
@@ -13,4 +18,6 @@
   bool CMemChecker::enabled_=true;
   bool CMemChecker::first_=true;
+  double CMemChecker::vsize_init_=0;
+  double CMemChecker::time_init_=0;
 
   CMemChecker::CMemChecker(const std::string& name) : name_(name) 
@@ -37,4 +44,60 @@
     return vsize ;
   }
+  double CMemChecker::getMemRSS(void)
+  {
+    //sleep( 1 ) ;
+    if (first_) check() ;
+    if (!enabled_) return 0;
+    std::ifstream statStream("/proc/self/stat",std::ios_base::in);
+    std::string dummy ;
+    for(int i=1;i<=23;i++) statStream>>dummy ;
+    double vsize; 
+    statStream>>vsize ;
+    if (vsize_init_==0) {
+      vsize_init_ = vsize;
+      time_init_=MPI_Wtime();
+    }
+    vsize -= vsize_init_;
+    vsize *= 4096; //getconf("PAGE_SIZE");
+    return vsize ;
+  }
+  void CMemChecker::logMem( std::string id, bool finalizeLog )
+  {
+    // function get_xios_mem_data() {
+    //   return [
+    //        ...
+    //        [ "2000-01-01 01:00:10.XXX", "XIOS close context def", 1000],
+    //        [ "2000-01-01 01:00:11.XXX", "update timestep"       , 1000],
+    //        [ "2000-01-01 01:00:15.XXX", "send field"            , 2000],
+    //        ...
+    //   ];
+    // }
+    
+    std::ofstream fout;
+    int rk = 0;
+    MPI_Comm_rank( MPI_COMM_WORLD, &rk );
+    std::string logName("mem_"+std::to_string(rk)+".js");
+    double mem = getMemRSS();
+    if (!mem) {
+      fout.open( logName );
+      fout << "function get_xios_mem_data() {" << std::endl;
+      fout << "  return [" << std::endl;
+    }
+    else
+    {
+      fout.open( logName, std::ios_base::app );
+    }
+
+    // Time format : YYYY-MM-DD HH:MM:SS.XXX -> seconds * 1000.
+    fout << "        [ " << (MPI_Wtime()-time_init_)*1000. << ", \"" << id << "\"," << mem/1000000. << "]," << std::endl;
+
+    if (finalizeLog)
+    {
+      fout << "  ];" << std::endl;
+      fout << "}" << std::endl;
+    }
+    fout.close();
+  }
+
   
   void CMemChecker::suspend(void)
@@ -53,5 +116,22 @@
     suspended_ = false;
   }
+
+  void CMemChecker::suspendRSS(void)
+  {
+    if (first_) check() ;
+    if (!enabled_) return ;
+    if (!suspended_) cumulatedMem_ += getMemRSS() - lastMem_;
+    suspended_ = true;
+  }
   
+  void CMemChecker::resumeRSS(void)
+  {
+    if (first_) check() ;
+    if (!enabled_) return ;
+    if (suspended_) lastMem_ = getMemRSS();
+    suspended_ = false;
+  }
+  
+
   void CMemChecker::reset(void)
   {
Index: XIOS3/trunk/src/mem_checker.hpp
===================================================================
--- XIOS3/trunk/src/mem_checker.hpp	(revision 2417)
+++ XIOS3/trunk/src/mem_checker.hpp	(revision 2418)
@@ -13,7 +13,11 @@
       void suspend(void);
       void resume(void);
+      void suspendRSS(void);
+      void resumeRSS(void);
       void reset(void);
       double getCumulatedMem(void);
       static double getMem(void);
+      static double getMemRSS(void);
+      static void logMem( std::string id, bool finalizeLog = false );
       static CMemChecker& get(std::string name);
       static std::string getAllCumulatedMem(void) ;
@@ -32,4 +36,7 @@
       static bool first_ ;
       static bool enabled_ ;
+
+      static double vsize_init_;
+      static double time_init_;
   };
 }
Index: XIOS3/trunk/src/node/context.cpp
===================================================================
--- XIOS3/trunk/src/node/context.cpp	(revision 2417)
+++ XIOS3/trunk/src/node/context.cpp	(revision 2418)
@@ -17,4 +17,5 @@
 #include "xios_spl.hpp"
 #include "timer.hpp"
+#include "mem_checker.hpp"
 #include "memtrack.hpp"
 #include <limits>
@@ -888,4 +889,6 @@
    TRY
    {
+     CMemChecker::logMem( "CContext::closeDefinition" );
+
      CTimer::get("Context : close definition").resume() ;
      
@@ -1159,6 +1162,6 @@
     for(auto& it : fieldBufferEvaluation) it.first->setBufferSize(it.second) ;
 
-
      CTimer::get("Context : close definition").suspend() ;
+     CMemChecker::logMem( "CContext::closeDefinition END" );
   }
   CATCH_DUMP_ATTR
@@ -2022,4 +2025,5 @@
       if (prevStep < step)
       {
+        CMemChecker::logMem( "CContext::updateCalendar_"+std::to_string(step) );
         if (serviceType_==CServicesManager::CLIENT) // For now we only use server level 1 to read data
         {
Index: XIOS3/trunk/src/server.cpp
===================================================================
--- XIOS3/trunk/src/server.cpp	(revision 2417)
+++ XIOS3/trunk/src/server.cpp	(revision 2418)
@@ -13,4 +13,5 @@
 #include "tracer.hpp"
 #include "timer.hpp"
+#include "mem_checker.hpp"
 #include "event_scheduler.hpp"
 #include "string_tools.hpp"
@@ -159,4 +160,6 @@
       CServer::openInfoStream(CXios::serverFile);
       CServer::openErrorStream(CXios::serverFile);
+
+      CMemChecker::logMem( "CServer::initialize" );
 
       /////////////////////////////////////////
@@ -431,4 +434,5 @@
       CXios::getMpiGarbageCollector().release() ; // release unfree MPI ressources
 
+      CMemChecker::logMem( "CServer::finalize", true );
       if (!is_MPI_Initialized)
       {
@@ -440,4 +444,5 @@
       report(0)<<"Performance report : Ratio : "<<CTimer::get("Process events").getCumulatedTime()/CTimer::get("XIOS server").getCumulatedTime()*100.<<"%"<<endl  ;
       report(100)<<CTimer::getAllCumulatedTime()<<endl ;
+      report(100)<<CMemChecker::getAllCumulatedMem()<<endl ;
       
       CWorkflowGraph::drawWorkFlowGraph_server();
