openPMD-api
 
Loading...
Searching...
No Matches
MemoryProfiler.hpp
1/* Copyright 2020-2025 Junmin Gu, Axel Huebl
2 *
3 * This file is part of openPMD-api.
4 *
5 * openPMD-api is free software: you can redistribute it and/or modify
6 * it under the terms of of either the GNU General Public License or
7 * the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * openPMD-api is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License and the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * and the GNU Lesser General Public License along with openPMD-api.
19 * If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <chrono>
25#include <fstream>
26#include <iostream>
27
28namespace openPMD
29{
30namespace benchmark
31{
37 {
38 public:
44 MemoryProfiler(int rank, const std::string &tag)
45 : m_Rank(rank), m_Name("")
46 {
47#if defined(__linux)
48 // m_Name = "/proc/meminfo";
49 m_Name = "/proc/self/status";
50 Display(tag);
51#endif
52 }
53
61 void Display(const std::string &tag)
62 {
63 if (0 == m_Name.size())
64 return;
65
66 if (m_Rank > 0)
67 return;
68
69 std::cout << " memory at: " << tag;
70 std::ifstream input(m_Name.c_str());
71
72 if (input.is_open())
73 {
74 for (std::string line; getline(input, line);)
75 {
76 if (line.find("VmRSS") == 0)
77 std::cout << line << " ";
78 if (line.find("VmSize") == 0)
79 std::cout << line << " ";
80 if (line.find("VmSwap") == 0)
81 std::cout << line;
82 }
83 std::cout << std::endl;
84 input.close();
85 }
86 }
87
88 private:
89 int m_Rank;
90 std::string m_Name;
91 };
92} // namespace benchmark
93} // namespace openPMD
MemoryProfiler(int rank, const std::string &tag)
Simple Memory profiler for linux.
Definition MemoryProfiler.hpp:44
void Display(const std::string &tag)
Display virtual memory info.
Definition MemoryProfiler.hpp:61
Public definitions of openPMD-api.
Definition Date.cpp:29