Commit 0e66aca6 authored by Stefan Hoeche's avatar Stefan Hoeche
Browse files

improved memory usage test

parent 47131c4c
......@@ -16,6 +16,7 @@ libToolsOrg_la_SOURCES = \
Return_Value.C \
Shell_Tools.C \
STL_Tools.C \
RUsage.C \
Getter_Function.C \
My_MPI.C \
Exception.C \
......
#include "ATOOLS/Org/RUsage.H"
/*
* Author: David Robert Nadeau
* Site: http://NadeauSoftware.com/
* License: Creative Commons Attribution 3.0 Unported License
* http://creativecommons.org/licenses/by/3.0/deed.en_US
*/
#if defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#include <sys/resource.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <mach/mach.h>
#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
#include <stdio.h>
#endif
#else
#error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
#endif
size_t ATOOLS::GetPeakRSS( )
{
#if defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
/* BSD, Linux, and OSX -------------------------------------- */
struct rusage rusage;
getrusage( RUSAGE_SELF, &rusage );
#if defined(__APPLE__) && defined(__MACH__)
return (size_t)rusage.ru_maxrss;
#else
return (size_t)(rusage.ru_maxrss * 1024L);
#endif
#else
return (size_t)0L; /* Unsupported. */
#endif
}
size_t ATOOLS::GetCurrentRSS( )
{
#if defined(__APPLE__) && defined(__MACH__)
/* OSX ------------------------------------------------------ */
struct mach_task_basic_info info;
mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO,
(task_info_t)&info, &infoCount ) != KERN_SUCCESS )
return (size_t)0L; /* Can't access? */
return (size_t)info.resident_size;
#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
/* Linux ---------------------------------------------------- */
long rss = 0L;
FILE* fp = NULL;
if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL )
return (size_t)0L; /* Can't open? */
if ( fscanf( fp, "%*s%ld", &rss ) != 1 )
{
fclose( fp );
return (size_t)0L; /* Can't read? */
}
fclose( fp );
return (size_t)rss * (size_t)sysconf( _SC_PAGESIZE);
#else
return (size_t)0L; /* Unsupported. */
#endif
}
#include <stddef.h>
namespace ATOOLS {
size_t GetPeakRSS();
size_t GetCurrentRSS();
}// end of namespace ATOOLS
......@@ -17,6 +17,7 @@
#include "PHASIC++/Process/ME_Generator_Base.H"
#include "PHASIC++/Main/Process_Integrator.H"
#include "PHASIC++/Main/Phase_Space_Handler.H"
#include "ATOOLS/Org/RUsage.H"
#ifdef USING__GZIP
#include "ATOOLS/Org/Gzip_Stream.H"
#endif
......@@ -340,20 +341,13 @@ int Matrix_Element_Handler::InitializeProcesses
double retime(ATOOLS::rpa->gen.Timer().RealTime());
#endif
double etime(ATOOLS::rpa->gen.Timer().UserTime());
Data_Reader psread;
psread.SetAddCommandLine(false);
psread.AddWordSeparator("\t");
psread.SetInputPath("/proc/"+ToString(getpid())+"/");
psread.SetInputFile("status");
std::vector<std::string> musage;
if (psread.VectorFromFile(musage,"VmSize:"))
for (size_t i(1);i<musage.size();++i) musage.front()+=" "+musage[i];
size_t rss(GetCurrentRSS());
#ifdef USING__Threading
msg_Info()<<" done ( "<<(musage.size()>0?musage.front():"?")<<", "
msg_Info()<<" done ( "<<rss/(1<<20)<<" MB, "
<<FormatTime(size_t(retime-rbtime))<<" / "
<<FormatTime(size_t(etime-btime))<<" )."<<std::endl;
#else
msg_Info()<<" done ( "<<(musage.size()>0?musage.front():"?")<<", "
msg_Info()<<" done ( "<<rss/(1<<20)<<" MB, "
<<FormatTime(size_t(etime-btime))<<" )."<<std::endl;
#endif
if (m_procs.empty() && m_gens.size()>0)
......@@ -368,15 +362,13 @@ int Matrix_Element_Handler::InitializeProcesses
retime=ATOOLS::rpa->gen.Timer().RealTime();
#endif
etime=ATOOLS::rpa->gen.Timer().UserTime();
psread.RereadInFile();
if (psread.VectorFromFile(musage,"VmSize:"))
for (size_t i(1);i<musage.size();++i) musage.front()+=" "+musage[i];
rss=GetCurrentRSS();
#ifdef USING__Threading
msg_Info()<<" done ( "<<(musage.size()>0?musage.front():"?")<<", "
msg_Info()<<" done ( "<<rss/(1<<20)<<" MB, "
<<FormatTime(size_t(retime-rbtime))<<" / "
<<FormatTime(size_t(etime-btime))<<" )."<<std::endl;
#else
msg_Info()<<" done ( "<<(musage.size()>0?musage.front():"?")<<", "
msg_Info()<<" done ( "<<rss/(1<<20)<<" MB, "
<<FormatTime(size_t(etime-btime))<<" )."<<std::endl;
#endif
msg_Debugging()<<METHOD<<"(): Processes {\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment