Ignore:
Timestamp:
10/13/22 15:45:43 (21 months ago)
Author:
jderouillat
Message:

Add an option (log_memory : set to false by default), to activate memory monitoring. Logs are now buffered.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/src/mem_checker.cpp

    r2419 r2420  
    11#include "mem_checker.hpp" 
     2#include "cxios.hpp" 
    23#include "mpi.hpp" 
    34#include <string> 
     
    56#include <iostream> 
    67#include <sstream> 
    7 #include <fstream> 
    88 
    99#include <fcntl.h> 
     
    2020  double CMemChecker::vsize_init_=0; 
    2121  double CMemChecker::time_init_=0; 
    22  
     22  std::ofstream CMemChecker::fout_; 
     23  int CMemChecker::flush_counter_=1; 
     24   
    2325  CMemChecker::CMemChecker(const std::string& name) : name_(name)  
    2426  {  
     
    6466  void CMemChecker::logMem( std::string id, bool finalizeLog ) 
    6567  { 
    66     // function get_xios_mem_data() { 
    67     //   return [ 
    68     //        ... 
    69     //        [ "2000-01-01 01:00:10.XXX", "XIOS close context def", 1000], 
    70     //        [ "2000-01-01 01:00:11.XXX", "update timestep"       , 1000], 
    71     //        [ "2000-01-01 01:00:15.XXX", "send field"            , 2000], 
    72     //        ... 
    73     //   ]; 
    74     // } 
    75      
    76     std::ofstream fout; 
     68    if ( !CXios::logMemory ) return ; 
     69 
    7770    int rk = 0; 
    7871    MPI_Comm_rank( MPI_COMM_WORLD, &rk ); 
     
    8073    double mem = getMemRSS(); 
    8174    if (!mem) { 
    82       fout.open( logName ); 
    83       fout << "time,event,memory" << std::endl; 
    84     } 
    85     else 
    86     { 
    87       fout.open( logName, std::ios_base::app ); 
     75      fout_.open( logName ); 
     76      fout_ << "time,event,memory" << std::endl; 
    8877    } 
    8978 
     79    fout_.precision(4); 
    9080    // Time format : YYYY-MM-DD HH:MM:SS.XXX -> seconds * 1000. 
    91     fout << (MPI_Wtime()-time_init_)*1000. << "," << id << "," << mem/1000000. << std::endl; 
     81    fout_ << (MPI_Wtime()-time_init_) << "," << id << "," << mem/1000000. << std::endl; 
    9282 
    93     fout.close(); 
     83    if ((MPI_Wtime()-time_init_)>flush_counter_*600.) 
     84    { 
     85      fout_.flush(); 
     86      flush_counter_++; 
     87    } 
     88     
     89    if (finalizeLog) 
     90    { 
     91      fout_.close(); 
     92    } 
    9493  } 
    9594 
Note: See TracChangeset for help on using the changeset viewer.