mirror of https://github.com/OpenTTD/OpenTTD.git
Fix: track "memory installed" for surveys less precisely (#10910)
It turns out, for Windows and Linux having the exact memory allows for easy tracing of an individual. That is exactly against the idea of the survey. And honestly, we don't need this precision.
This commit is contained in:
parent
7d6aff3a34
commit
21adfa7567
|
@ -298,6 +298,33 @@ static void SurveyGameScript(nlohmann::json &survey)
|
|||
survey = fmt::format("{}.{}", Game::GetInfo()->GetName(), Game::GetInfo()->GetVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the bytes of memory into a textual version rounded up to the biggest unit.
|
||||
*
|
||||
* For example, 16751108096 would become 16 GiB.
|
||||
*
|
||||
* @param memory The bytes of memory.
|
||||
* @return std::string A textual representation.
|
||||
*/
|
||||
std::string SurveyMemoryToText(uint64_t memory)
|
||||
{
|
||||
memory = memory / 1024; // KiB
|
||||
memory = CeilDiv(memory, 1024); // MiB
|
||||
|
||||
/* Anything above 512 MiB we represent in GiB. */
|
||||
if (memory > 512) {
|
||||
return fmt::format("{} GiB", CeilDiv(memory, 1024));
|
||||
}
|
||||
|
||||
/* Anything above 64 MiB we represent in a multiplier of 128 MiB. */
|
||||
if (memory > 64) {
|
||||
return fmt::format("{} MiB", Ceil(memory, 128));
|
||||
}
|
||||
|
||||
/* Anything else in a multiplier of 4 MiB. */
|
||||
return fmt::format("{} MiB", Ceil(memory, 4));
|
||||
}
|
||||
|
||||
#endif /* WITH_NLOHMANN_JSON */
|
||||
|
||||
/**
|
||||
|
@ -328,8 +355,6 @@ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
|
|||
{
|
||||
auto &info = survey["info"];
|
||||
SurveyOS(info["os"]);
|
||||
info["os"]["hardware_concurrency"] = std::thread::hardware_concurrency();
|
||||
|
||||
SurveyOpenTTD(info["openttd"]);
|
||||
SurveyConfiguration(info["configuration"]);
|
||||
SurveyFont(info["font"]);
|
||||
|
|
|
@ -16,9 +16,12 @@
|
|||
|
||||
#include <mach-o/arch.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
extern std::string SurveyMemoryToText(uint64_t memory);
|
||||
|
||||
void SurveyOS(nlohmann::json &json)
|
||||
{
|
||||
int ver_maj, ver_min, ver_bug;
|
||||
|
@ -32,7 +35,8 @@ void SurveyOS(nlohmann::json &json)
|
|||
json["min_ver"] = MAC_OS_X_VERSION_MIN_REQUIRED;
|
||||
json["max_ver"] = MAC_OS_X_VERSION_MAX_ALLOWED;
|
||||
|
||||
json["memory"] = MacOSGetPhysicalMemory();
|
||||
json["memory"] = SurveyMemoryToText(MacOSGetPhysicalMemory());
|
||||
json["hardware_concurrency"] = std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
#endif /* WITH_NLOHMANN_JSON */
|
||||
|
|
|
@ -13,10 +13,13 @@
|
|||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sys/utsname.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
extern std::string SurveyMemoryToText(uint64_t memory);
|
||||
|
||||
void SurveyOS(nlohmann::json &json)
|
||||
{
|
||||
struct utsname name;
|
||||
|
@ -32,7 +35,8 @@ void SurveyOS(nlohmann::json &json)
|
|||
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
long page_size = sysconf(_SC_PAGE_SIZE);
|
||||
json["memory"] = pages * page_size;
|
||||
json["memory"] = SurveyMemoryToText(pages * page_size);
|
||||
json["hardware_concurrency"] = std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
#endif /* WITH_NLOHMANN_JSON */
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
#include "../../3rdparty/fmt/format.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
#include <windows.h>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
extern std::string SurveyMemoryToText(uint64_t memory);
|
||||
|
||||
void SurveyOS(nlohmann::json &json)
|
||||
{
|
||||
_OSVERSIONINFOA os;
|
||||
|
@ -31,7 +34,8 @@ void SurveyOS(nlohmann::json &json)
|
|||
status.dwLength = sizeof(status);
|
||||
GlobalMemoryStatusEx(&status);
|
||||
|
||||
json["memory"] = status.ullTotalPhys;
|
||||
json["memory"] = SurveyMemoryToText(status.ullTotalPhys);
|
||||
json["hardware_concurrency"] = std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
#endif /* WITH_NLOHMANN_JSON */
|
||||
|
|
Loading…
Reference in New Issue