Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4MemStat Namespace Reference

Classes

struct  MemStat
 

Functions

std::ostream & operator<< (std::ostream &os, const MemStat &p)
 
MemStat MemoryUsage ()
 

Function Documentation

MemStat G4MemStat::MemoryUsage ( )

Definition at line 55 of file G4MemStat.cc.

56  {
57  MemStat output;
58 
59 #if ( defined(__MACH__) && defined(__clang__) && defined(__x86_64__) ) || \
60  ( defined(__MACH__) && defined(__GNUC__) && __GNUC__>=4 && __GNUC_MINOR__>=7 ) || \
61  defined(__linux__) || defined(_AIX)
62 
63  // 'file' stat seems to give the most reliable results
64  //
65  ifstream stat_stream("/proc/self/stat", ios_base::in);
66 
67  // dummy vars for leading entries in stat that we don't care about
68  //
69  string pid, comm, state, ppid, pgrp, session, tty_nr;
70  string tpgid, flags, minflt, cminflt, majflt, cmajflt;
71  string utime, stime, cutime, cstime, priority, nice;
72  string O, itrealvalue, starttime;
73 
74  // the two fields we want
75  //
76  unsigned long vsize;
77  long rss;
78 
79  stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
80  >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt >> utime
81  >> stime >> cutime >> cstime >> priority >> nice >> O >> itrealvalue
82  >> starttime >> vsize >> rss; // don't care about the rest
83 
84  stat_stream.close();
85 
86  long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
87  output.vmz = vsize / 1024.0;
88  output.mem = rss * page_size_kb;
89 #endif
90 
91  return output;
92  }

Here is the caller graph for this function:

std::ostream & G4MemStat::operator<< ( std::ostream &  os,
const MemStat &  p 
)

Definition at line 94 of file G4MemStat.cc.

95  {
96  return os << "( vmz: " << memStat.vmz << ", " << "mem: " << memStat.mem
97  << ")";
98  }