File: system.h

package info (click to toggle)
wsclean 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,196 kB
  • sloc: cpp: 34,504; ansic: 234; python: 174; makefile: 10
file content (71 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef MSIOSYSTEM_H
#define MSIOSYSTEM_H

#include <casacore/casa/OS/HostInfo.h>

#include <stdio.h>
#include <unistd.h>
#include <sched.h>
#include <string.h>

#include <stdexcept>
#include <string>

class System
{
public:
	static long TotalMemory()
	{
		return casacore::HostInfo::memoryTotal()*1024;
	}
	
	static unsigned ProcessorCount()
	{
#ifdef __APPLE__
		return sysconf(_SC_NPROCESSORS_ONLN);
#else
		cpu_set_t cs;
		CPU_ZERO(&cs);
		sched_getaffinity(0, sizeof cs , &cs);

		int count = 0;
		for (int i = 0; i < CPU_SETSIZE; i++)
		{
			if (CPU_ISSET(i, &cs))
			count++;
		}

		return count;
#endif
	}
	
	static std::string StrError(int errnum)
	{
		// Because strerror_r() has different return values on different platforms,
		// two overloads of handle_strerror are used to make this compile and work
		// in either case of int or char*.
		char buffer[1024];
		char* ret = handle_strreturn(strerror_r(errnum, buffer, 1024));
		if(ret == 0)
			return std::string(buffer);
		else
			return std::string(ret);
	}
	
	static std::string FindPythonFilePath(const std::string& filename);
	
private:
	static char* handle_strreturn(int value)
	{
		if(value != 0)
			throw std::runtime_error("strerror_r() reported an error");
		return 0;
	}
	static char* handle_strreturn(char* value)
	{
		return value;
	}

};

#endif //MSIOSYSTEM_H