CbmRoot
Loading...
Searching...
No Matches
System.cxx
Go to the documentation of this file.
1
/* Copyright (C) 2024 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2
SPDX-License-Identifier: GPL-3.0-only
3
Authors: Felix Weiglhofer [committer] */
4
5
#include "
System.h
"
6
7
#include <cstdio>
8
9
#ifdef __linux__
10
#include <sys/resource.h>
11
#include <unistd.h>
12
#endif
13
14
15
size_t
cbm::algo::GetCurrentRSS
()
16
{
17
// Implementation copied from https://stackoverflow.com/a/14927379
18
#ifndef __linux__
19
return
0;
20
#else
21
unsigned
long
rss = 0L;
22
FILE* fp =
nullptr
;
23
if
((fp = fopen(
"/proc/self/statm"
,
"r"
)) ==
nullptr
) {
24
return
size_t(0L);
/* Can't open? */
25
}
26
if
(fscanf(fp,
"%*s%lu"
, &rss) != 1) {
27
fclose(fp);
28
return
size_t(0L);
/* Can't read? */
29
}
30
fclose(fp);
31
return
size_t(rss) * size_t(sysconf(_SC_PAGESIZE));
32
#endif
33
}
34
35
size_t
cbm::algo::GetPeakRSS
()
36
{
37
// Implementation copied from https://stackoverflow.com/a/14927379
38
#ifndef __linux__
39
return
0;
40
#else
41
struct
rusage rusage;
42
getrusage(RUSAGE_SELF, &rusage);
43
44
return
size_t(rusage.ru_maxrss * 1024L);
45
#endif
46
}
System.h
System functions.
cbm::algo::GetCurrentRSS
size_t GetCurrentRSS()
Get the current resident set size (pyhysical memory usage) of the process.
Definition
System.cxx:15
cbm::algo::GetPeakRSS
size_t GetPeakRSS()
Get the peak resident set size (pyhysical memory usage) of the process.
Definition
System.cxx:35
algo
base
System.cxx
Generated on Mon Feb 3 2025 23:03:43 for CbmRoot by
1.12.0