OpenTTD Source 20241224-master-gee860a5c8e
survey_unix.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "../../stdafx.h"
11#include "../../survey.h"
12
13#include <sys/utsname.h>
14#include <thread>
15#include <unistd.h>
16
17#include "../../safeguards.h"
18
19void SurveyOS(nlohmann::json &json)
20{
21 struct utsname name;
22 if (uname(&name) < 0) {
23 json["os"] = "Unix";
24 return;
25 }
26
27 json["os"] = name.sysname;
28 json["release"] = name.release;
29 json["machine"] = name.machine;
30 json["version"] = name.version;
31
32 long pages = sysconf(_SC_PHYS_PAGES);
33 long page_size = sysconf(_SC_PAGE_SIZE);
34 json["memory"] = SurveyMemoryToText(pages * page_size);
35 json["hardware_concurrency"] = std::thread::hardware_concurrency();
36}
std::string SurveyMemoryToText(uint64_t memory)
Change the bytes of memory into a textual version rounded up to the biggest unit.
Definition survey.cpp:487