File: utils_unix.cpp

package info (click to toggle)
piler 0~20140707-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 364 kB
  • sloc: cpp: 5,369; makefile: 39
file content (38 lines) | stat: -rwxr-xr-x 673 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "piler2.h"

#if ((unix || __unix) && !(linux || __linux__))

#include <sys/time.h>
#include <sys/resource.h>
#include <sys/unistd.h>

double GetRAMSize()
	{
	struct rlimit RL;
	int Ok = getrlimit(RLIMIT_DATA, &RL);
	if (Ok != 0)
		return 1e9;
	return RL.rlim_cur;
	}

static unsigned g_uPeakMemUseBytes = 1000000;

unsigned GetPeakMemUseBytes()
	{
	return g_uPeakMemUseBytes;
	}

unsigned GetMemUseBytes()
	{
	struct rusage RU;
	int Ok = getrusage(RUSAGE_SELF, &RU);
	if (Ok != 0)
		return 1000000;

	unsigned Bytes = RU.ru_maxrss*1000;
	if (Bytes > g_uPeakMemUseBytes)
		g_uPeakMemUseBytes = Bytes;
	return Bytes;
	}

#endif