-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathComputingResourceHelpers.cxx
More file actions
55 lines (51 loc) · 1.77 KB
/
ComputingResourceHelpers.cxx
File metadata and controls
55 lines (51 loc) · 1.77 KB
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
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "ComputingResourceHelpers.h"
#include <thread>
#include <unistd.h>
#include <sstream>
namespace o2::framework
{
long getTotalNumberOfBytes()
{
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
};
ComputingResource ComputingResourceHelpers::getLocalhostResource()
{
ComputingResource result;
result.cpu = std::thread::hardware_concurrency(),
result.memory = getTotalNumberOfBytes();
result.hostname = "localhost";
result.startPort = 22000;
result.lastPort = 27000;
result.usedPorts = 0;
return result;
}
std::vector<ComputingResource> ComputingResourceHelpers::parseResources(std::string const& resourceString)
{
std::vector<ComputingResource> resources;
std::istringstream str{resourceString};
std::string result;
while (std::getline(str, result, ',')) {
std::istringstream in{result};
char colon;
ComputingResource resource;
std::getline(in, resource.hostname, ':');
in >> resource.cpu >> colon >> resource.memory >> colon >> resource.startPort >> colon >> resource.lastPort;
resource.memory = resource.memory * 1000000;
resource.usedPorts = 0;
resources.emplace_back(resource);
}
return resources;
}
} // namespace o2::framework