Conscience Core
Bridging
EnvironmentInteractionCommands
MetadataBuilder
memtest.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
Util/conscience_log.h
>
4
5
using namespace
conscience_utils::logging
;
6
7
#if defined(__linux__)
8
#include <fstream>
9
#elif defined(__APPLE__)
10
#include <mach/mach.h>
11
#endif
12
13
inline
size_t
getCurrentRSS
()
14
{
15
#if defined(__linux__)
16
std::ifstream file(
"/proc/self/status"
);
17
std::string key;
18
19
while
(file >> key) {
20
if
(key ==
"VmRSS:"
) {
21
size_t
value = 0;
22
std::string unit;
23
file >> value >> unit;
24
return
value * 1024;
25
}
26
27
std::string rest;
28
std::getline(file, rest);
29
}
30
31
return
0;
32
33
#elif defined(__APPLE__)
34
mach_task_basic_info info;
35
mach_msg_type_number_t
count
= MACH_TASK_BASIC_INFO_COUNT;
36
37
const
kern_return_t result = task_info(
38
mach_task_self(),
39
MACH_TASK_BASIC_INFO,
40
reinterpret_cast<
task_info_t
>
(&info),
41
&
count
42
);
43
44
if
(result != KERN_SUCCESS) {
45
return
0;
46
}
47
48
return
static_cast<
size_t
>
(info.resident_size);
49
50
#else
51
return
0;
52
#endif
53
}
54
55
inline
void
logRSS
(
const
std::string& label)
56
{
57
const
double
mb =
static_cast<
double
>
(
getCurrentRSS
()) / 1024.0 / 1024.0;
58
LOG_INFO
(
"[RSS] "
+ label +
": "
+
std::to_string
(mb) +
" MB"
);
59
}
conscience_log.h
nlohmann::to_string
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition:
json.hpp:26470
LOG_INFO
#define LOG_INFO(message)
Definition:
conscience_log.h:175
count
int count
Definition:
PathFinding3D25D.cpp:25
conscience_utils::logging
Definition:
conscience_log.cpp:20
getCurrentRSS
size_t getCurrentRSS()
Definition:
memtest.h:13
logRSS
void logRSS(const std::string &label)
Definition:
memtest.h:55
Generated by
1.8.17