OGS
MemWatch.cpp
Go to the documentation of this file.
1
15#include "MemWatch.h"
16
17#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__MINGW32__)
18#include <stdio.h>
19#include <unistd.h>
20
21#include <fstream>
22#include <sstream>
23#include <string>
24#endif
25
26namespace BaseLib
27{
32
34{
35#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__MINGW32__)
36 std::string fname("/proc/");
37 std::stringstream str_pid;
38 str_pid << static_cast<unsigned>(getpid());
39 fname += str_pid.str();
40 fname += "/statm";
41 unsigned pages;
42
43 std::ifstream in(fname.c_str(), std::ios::in);
44 if (!in.is_open())
45 {
46 perror("open");
47 return 1;
48 }
49
50 in >> pages;
51 vmem_size_ = static_cast<unsigned long>(pages) *
52 static_cast<unsigned long>(getpagesize());
53 in.close();
54#endif
55
56 return 0;
57}
58
60{
62 return vmem_size_;
63}
64
65} // end namespace BaseLib
Definition of the MemWatch class.
unsigned updateMemUsage()
Definition MemWatch.cpp:33
unsigned long getVirtMemUsage()
Definition MemWatch.cpp:59
unsigned long vmem_size_
Definition MemWatch.h:27