mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-02 00:15:06 +01:00
telemetry_session: Log telemetry ID.
This commit is contained in:
parent
59ad933022
commit
d6a819c7cb
@ -3,8 +3,10 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cryptopp/osrng.h>
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
#include "common/file_util.h"
|
||||||
#include "common/scm_rev.h"
|
#include "common/scm_rev.h"
|
||||||
#include "common/x64/cpu_detect.h"
|
#include "common/x64/cpu_detect.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
@ -29,12 +31,46 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) {
|
|||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u64 GenerateTelemetryId() {
|
||||||
|
u64 telemetry_id{};
|
||||||
|
CryptoPP::AutoSeededRandomPool rng;
|
||||||
|
rng.GenerateBlock(reinterpret_cast<CryptoPP::byte*>(&telemetry_id), sizeof(u64));
|
||||||
|
return telemetry_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u64 GetTelemetryId() {
|
||||||
|
u64 telemetry_id{};
|
||||||
|
static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
|
||||||
|
|
||||||
|
if (FileUtil::Exists(filename)) {
|
||||||
|
FileUtil::IOFile file(filename, "rb");
|
||||||
|
if (!file.IsOpen()) {
|
||||||
|
LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
file.ReadBytes(&telemetry_id, sizeof(u64));
|
||||||
|
} else {
|
||||||
|
FileUtil::IOFile file(filename, "wb");
|
||||||
|
if (!file.IsOpen()) {
|
||||||
|
LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
telemetry_id = GenerateTelemetryId();
|
||||||
|
file.WriteBytes(&telemetry_id, sizeof(u64));
|
||||||
|
}
|
||||||
|
|
||||||
|
return telemetry_id;
|
||||||
|
}
|
||||||
|
|
||||||
TelemetrySession::TelemetrySession() {
|
TelemetrySession::TelemetrySession() {
|
||||||
#ifdef ENABLE_WEB_SERVICE
|
#ifdef ENABLE_WEB_SERVICE
|
||||||
backend = std::make_unique<WebService::TelemetryJson>();
|
backend = std::make_unique<WebService::TelemetryJson>();
|
||||||
#else
|
#else
|
||||||
backend = std::make_unique<Telemetry::NullVisitor>();
|
backend = std::make_unique<Telemetry::NullVisitor>();
|
||||||
#endif
|
#endif
|
||||||
|
// Log one-time top-level information
|
||||||
|
AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId());
|
||||||
|
|
||||||
// Log one-time session start information
|
// Log one-time session start information
|
||||||
const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>(
|
const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
std::chrono::system_clock::now().time_since_epoch())
|
std::chrono::system_clock::now().time_since_epoch())
|
||||||
|
Loading…
Reference in New Issue
Block a user