OGS
MemWatch.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "MemWatch.h"
5
6#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__MINGW32__)
7#include <stdio.h>
8#include <unistd.h>
9
10#include <fstream>
11#include <sstream>
12#include <string>
13#endif
14
15namespace BaseLib
16{
21
23{
24#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__MINGW32__)
25 std::string fname("/proc/");
26 std::stringstream str_pid;
27 str_pid << static_cast<unsigned>(getpid());
28 fname += str_pid.str();
29 fname += "/statm";
30 unsigned pages;
31
32 std::ifstream in(fname.c_str(), std::ios::in);
33 if (!in.is_open())
34 {
35 perror("open");
36 return 1;
37 }
38
39 in >> pages;
40 vmem_size_ = static_cast<unsigned long>(pages) *
41 static_cast<unsigned long>(getpagesize());
42 in.close();
43#endif
44
45 return 0;
46}
47
49{
51 return vmem_size_;
52}
53
54} // end namespace BaseLib
unsigned updateMemUsage()
Definition MemWatch.cpp:22
unsigned long getVirtMemUsage()
Definition MemWatch.cpp:48
unsigned long vmem_size_
Definition MemWatch.h:16