diff options
| author | 2017-08-22 20:58:19 -0400 | |
|---|---|---|
| committer | 2017-08-25 23:10:00 -0400 | |
| commit | d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3 (patch) | |
| tree | 509f019ccc3d49f6646b4cd26d36ca3cf2b93b7c | |
| parent | citra_qt: Show one-time callout messages to user. (diff) | |
| download | yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar.gz yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar.xz yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.zip | |
telemetry_session: Log telemetry ID.
| -rw-r--r-- | src/core/telemetry_session.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 94483f385..61ba78457 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -3,8 +3,10 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include <cryptopp/osrng.h> | ||
| 6 | 7 | ||
| 7 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 9 | #include "common/file_util.h" | ||
| 8 | #include "common/scm_rev.h" | 10 | #include "common/scm_rev.h" |
| 9 | #include "common/x64/cpu_detect.h" | 11 | #include "common/x64/cpu_detect.h" |
| 10 | #include "core/core.h" | 12 | #include "core/core.h" |
| @@ -29,12 +31,46 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) { | |||
| 29 | UNREACHABLE(); | 31 | UNREACHABLE(); |
| 30 | } | 32 | } |
| 31 | 33 | ||
| 34 | static u64 GenerateTelemetryId() { | ||
| 35 | u64 telemetry_id{}; | ||
| 36 | CryptoPP::AutoSeededRandomPool rng; | ||
| 37 | rng.GenerateBlock(reinterpret_cast<CryptoPP::byte*>(&telemetry_id), sizeof(u64)); | ||
| 38 | return telemetry_id; | ||
| 39 | } | ||
| 40 | |||
| 41 | static u64 GetTelemetryId() { | ||
| 42 | u64 telemetry_id{}; | ||
| 43 | static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; | ||
| 44 | |||
| 45 | if (FileUtil::Exists(filename)) { | ||
| 46 | FileUtil::IOFile file(filename, "rb"); | ||
| 47 | if (!file.IsOpen()) { | ||
| 48 | LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str()); | ||
| 49 | return {}; | ||
| 50 | } | ||
| 51 | file.ReadBytes(&telemetry_id, sizeof(u64)); | ||
| 52 | } else { | ||
| 53 | FileUtil::IOFile file(filename, "wb"); | ||
| 54 | if (!file.IsOpen()) { | ||
| 55 | LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str()); | ||
| 56 | return {}; | ||
| 57 | } | ||
| 58 | telemetry_id = GenerateTelemetryId(); | ||
| 59 | file.WriteBytes(&telemetry_id, sizeof(u64)); | ||
| 60 | } | ||
| 61 | |||
| 62 | return telemetry_id; | ||
| 63 | } | ||
| 64 | |||
| 32 | TelemetrySession::TelemetrySession() { | 65 | TelemetrySession::TelemetrySession() { |
| 33 | #ifdef ENABLE_WEB_SERVICE | 66 | #ifdef ENABLE_WEB_SERVICE |
| 34 | backend = std::make_unique<WebService::TelemetryJson>(); | 67 | backend = std::make_unique<WebService::TelemetryJson>(); |
| 35 | #else | 68 | #else |
| 36 | backend = std::make_unique<Telemetry::NullVisitor>(); | 69 | backend = std::make_unique<Telemetry::NullVisitor>(); |
| 37 | #endif | 70 | #endif |
| 71 | // Log one-time top-level information | ||
| 72 | AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId()); | ||
| 73 | |||
| 38 | // Log one-time session start information | 74 | // Log one-time session start information |
| 39 | const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>( | 75 | const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>( |
| 40 | std::chrono::system_clock::now().time_since_epoch()) | 76 | std::chrono::system_clock::now().time_since_epoch()) |