Index: XIOS/trunk/make_xios
===================================================================
--- XIOS/trunk/make_xios	(revision 1136)
+++ XIOS/trunk/make_xios	(revision 1137)
@@ -47,5 +47,5 @@
          "--job")   job=$2              ; shift ; shift ;;
          "--netcdf_lib")   netcdf_lib=$2 ; shift ; shift ;;
-         "--memtrack")   use_memtrack="true" ; shift ;;
+         "--memtrack")  use_memtrack="true" memtrack=$2  ; shift ; shift ;;
          *)         code="$1"           ; shift ;;
       esac
@@ -172,6 +172,17 @@
 if [[ "$use_memtrack" == "true" ]]
    then
-   XIOS_LIB="$ADDR2LINE_LIBDIR $ADDR2LINE_LIB $XIOS_LIB"
    XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK"
+
+    if [[ "$memtrack" == "light" ]]
+    then
+	XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_LIGHT"
+    elif [[ "$memtrack" == "FULL"  ]]
+    then
+      XIOS_LIB="$ADDR2LINE_LIBDIR $ADDR2LINE_LIB $XIOS_LIB"
+      XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_FULL"
+    else
+	echo "Bad choice for --memtrack argument : choose between 'light','full'"
+	exit
+    fi
 fi 
 
Index: XIOS/trunk/src/cxios.cpp
===================================================================
--- XIOS/trunk/src/cxios.cpp	(revision 1136)
+++ XIOS/trunk/src/cxios.cpp	(revision 1137)
@@ -111,10 +111,19 @@
        delete globalRegistry ;
      }
-     CClient::closeInfoStream();
-  
 
 #ifdef XIOS_MEMTRACK
+
+#ifdef XIOS_MEMTRACK_LIGHT
+       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
+       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
+#endif
+
+#ifdef XIOS_MEMTRACK_FULL
      MemTrack::TrackListMemoryUsage() ;
      MemTrack::TrackDumpBlocks();
+#endif
+
+     CClient::closeInfoStream();
+
 #endif
   }
@@ -163,4 +172,17 @@
      }
     CServer::finalize();
+
+#ifdef XIOS_MEMTRACK
+
+#ifdef XIOS_MEMTRACK_LIGHT
+       report(10) << " Memory report : current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
+       report(10) << " Memory report : maximum memory used by XIOS : "<<  MemTrack::getMaxMemorySize()*1.0/(1024*1024)<<" Mbyte" << endl ;
+#endif
+
+#ifdef XIOS_MEMTRACK_FULL
+     MemTrack::TrackListMemoryUsage() ;
+     MemTrack::TrackDumpBlocks();
+#endif
+#endif
     CServer::closeInfoStream();
   }
Index: XIOS/trunk/src/memtrack.cpp
===================================================================
--- XIOS/trunk/src/memtrack.cpp	(revision 1136)
+++ XIOS/trunk/src/memtrack.cpp	(revision 1137)
@@ -44,4 +44,5 @@
 #include <sstream>
 #include <string>
+
 #include <execinfo.h>
 
@@ -52,4 +53,7 @@
 {
   void addr2line(const char *file_name, char** addr, int naddr) ;
+#ifdef XIOS_MEMTRACK_LIGHT
+  void addr2line(const char *file_name, char** addr, int naddr) {} 
+#endif
 }
 /* ------------------------------------------------------------ */
@@ -59,4 +63,9 @@
 namespace MemTrack
 {
+    size_t currentMemorySize=0 ;
+    size_t maxMemorySize=0 ; 
+
+    size_t getCurrentMemorySize(void) {return currentMemorySize; }
+    size_t getMaxMemorySize(void) {return maxMemorySize ; }
 
     /* ------------------------------------------------------------ */
@@ -375,4 +384,7 @@
         // Get the offset to the user chunk and return it.
         UserChunk *pUser = GetUserAddress(pProlog);
+
+        currentMemorySize += size ;
+        if (currentMemorySize>maxMemorySize) maxMemorySize=currentMemorySize ;
         
         return pUser;
@@ -400,4 +412,5 @@
         // Unlink the block header from the list and destroy it.
         BlockHeader *pBlockHeader = GetHeaderAddress(pProlog);
+        currentMemorySize-=pBlockHeader->GetRequestedSize();
         BlockHeader::RemoveNode(pBlockHeader);
         pBlockHeader->~BlockHeader();
Index: XIOS/trunk/src/memtrack.hpp
===================================================================
--- XIOS/trunk/src/memtrack.hpp	(revision 1136)
+++ XIOS/trunk/src/memtrack.hpp	(revision 1137)
@@ -61,5 +61,6 @@
     void TrackDumpBlocks();
     void TrackListMemoryUsage();
-
+    size_t getCurrentMemorySize(void) ;
+    size_t getMaxMemorySize(void) ;
     /* ---------------------------------------- operator * (MemStamp, ptr) */
 
Index: XIOS/trunk/src/node/context.cpp
===================================================================
--- XIOS/trunk/src/node/context.cpp	(revision 1136)
+++ XIOS/trunk/src/node/context.cpp	(revision 1137)
@@ -15,4 +15,5 @@
 #include "xios_spl.hpp"
 #include "timer.hpp"
+#include "memtrack.hpp"
 
 
@@ -1197,5 +1198,7 @@
       calendar->update(step);
       info(50) << "updateCalendar : after : " << calendar->getCurrentDate() << endl;
-
+#ifdef XIOS_MEMTRACK_LIGHT
+      info(50) << " Current memory used by XIOS : "<<  MemTrack::getCurrentMemorySize()*1.0/(1024*1024)<<" Mbyte, at timestep "<<step<<" of context "<<this->getId()<<endl ;
+#endif
       if (hasClient)
       {
