summaryrefslogtreecommitdiff
path: root/src/core/telemetry_session.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2019-05-28 21:12:23 -0400
committerGravatar Lioncash2019-05-28 22:28:15 -0400
commit215fd827384904f1cb7fa689ff8cd3f61dbbd007 (patch)
tree3c5d144f741228e966e13b576bfa0cadbaebd5fa /src/core/telemetry_session.cpp
parentcore/telemetry_session: Explicitly delete copy and move constructors (diff)
downloadyuzu-215fd827384904f1cb7fa689ff8cd3f61dbbd007.tar.gz
yuzu-215fd827384904f1cb7fa689ff8cd3f61dbbd007.tar.xz
yuzu-215fd827384904f1cb7fa689ff8cd3f61dbbd007.zip
core/telemetry_session: Remove usages of the global system accessor
Makes the dependency explicit in the TelemetrySession's interface instead of making it a hidden dependency. This also revealed a hidden issue with the way the telemetry session was being initialized. It was attempting to retrieve the app loader and log out title-specific information. However, this isn't always guaranteed to be possible. During the initialization phase, everything is being constructed. It doesn't mean an actual title has been selected. This is what the Load() function is for. This potentially results in dead code paths involving the app loader. Instead, we explicitly add this information when we know the app loader instance is available.
Diffstat (limited to 'src/core/telemetry_session.cpp')
-rw-r--r--src/core/telemetry_session.cpp60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index 4b17bada5..4f8aff816 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -12,7 +12,6 @@
12#include "common/file_util.h" 12#include "common/file_util.h"
13#include "common/logging/log.h" 13#include "common/logging/log.h"
14 14
15#include "core/core.h"
16#include "core/file_sys/control_metadata.h" 15#include "core/file_sys/control_metadata.h"
17#include "core/file_sys/patch_manager.h" 16#include "core/file_sys/patch_manager.h"
18#include "core/loader/loader.h" 17#include "core/loader/loader.h"
@@ -101,7 +100,31 @@ bool VerifyLogin(const std::string& username, const std::string& token) {
101#endif 100#endif
102} 101}
103 102
104TelemetrySession::TelemetrySession() { 103TelemetrySession::TelemetrySession() = default;
104
105TelemetrySession::~TelemetrySession() {
106 // Log one-time session end information
107 const s64 shutdown_time{std::chrono::duration_cast<std::chrono::milliseconds>(
108 std::chrono::system_clock::now().time_since_epoch())
109 .count()};
110 AddField(Telemetry::FieldType::Session, "Shutdown_Time", shutdown_time);
111
112#ifdef ENABLE_WEB_SERVICE
113 auto backend = std::make_unique<WebService::TelemetryJson>(
114 Settings::values.web_api_url, Settings::values.yuzu_username, Settings::values.yuzu_token);
115#else
116 auto backend = std::make_unique<Telemetry::NullVisitor>();
117#endif
118
119 // Complete the session, submitting to web service if necessary
120 field_collection.Accept(*backend);
121 if (Settings::values.enable_telemetry) {
122 backend->Complete();
123 }
124 backend = nullptr;
125}
126
127void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader) {
105 // Log one-time top-level information 128 // Log one-time top-level information
106 AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId()); 129 AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId());
107 130
@@ -112,26 +135,28 @@ TelemetrySession::TelemetrySession() {
112 AddField(Telemetry::FieldType::Session, "Init_Time", init_time); 135 AddField(Telemetry::FieldType::Session, "Init_Time", init_time);
113 136
114 u64 program_id{}; 137 u64 program_id{};
115 const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadProgramId(program_id)}; 138 const Loader::ResultStatus res{app_loader.ReadProgramId(program_id)};
116 if (res == Loader::ResultStatus::Success) { 139 if (res == Loader::ResultStatus::Success) {
117 const std::string formatted_program_id{fmt::format("{:016X}", program_id)}; 140 const std::string formatted_program_id{fmt::format("{:016X}", program_id)};
118 AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id); 141 AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id);
119 142
120 std::string name; 143 std::string name;
121 System::GetInstance().GetAppLoader().ReadTitle(name); 144 app_loader.ReadTitle(name);
122 145
123 if (name.empty()) { 146 if (name.empty()) {
124 auto [nacp, icon_file] = FileSys::PatchManager(program_id).GetControlMetadata(); 147 auto [nacp, icon_file] = FileSys::PatchManager(program_id).GetControlMetadata();
125 if (nacp != nullptr) 148 if (nacp != nullptr) {
126 name = nacp->GetApplicationName(); 149 name = nacp->GetApplicationName();
150 }
127 } 151 }
128 152
129 if (!name.empty()) 153 if (!name.empty()) {
130 AddField(Telemetry::FieldType::Session, "ProgramName", name); 154 AddField(Telemetry::FieldType::Session, "ProgramName", name);
155 }
131 } 156 }
132 157
133 AddField(Telemetry::FieldType::Session, "ProgramFormat", 158 AddField(Telemetry::FieldType::Session, "ProgramFormat",
134 static_cast<u8>(System::GetInstance().GetAppLoader().GetFileType())); 159 static_cast<u8>(app_loader.GetFileType()));
135 160
136 // Log application information 161 // Log application information
137 Telemetry::AppendBuildInfo(field_collection); 162 Telemetry::AppendBuildInfo(field_collection);
@@ -162,27 +187,6 @@ TelemetrySession::TelemetrySession() {
162 Settings::values.use_docked_mode); 187 Settings::values.use_docked_mode);
163} 188}
164 189
165TelemetrySession::~TelemetrySession() {
166 // Log one-time session end information
167 const s64 shutdown_time{std::chrono::duration_cast<std::chrono::milliseconds>(
168 std::chrono::system_clock::now().time_since_epoch())
169 .count()};
170 AddField(Telemetry::FieldType::Session, "Shutdown_Time", shutdown_time);
171
172#ifdef ENABLE_WEB_SERVICE
173 auto backend = std::make_unique<WebService::TelemetryJson>(
174 Settings::values.web_api_url, Settings::values.yuzu_username, Settings::values.yuzu_token);
175#else
176 auto backend = std::make_unique<Telemetry::NullVisitor>();
177#endif
178
179 // Complete the session, submitting to web service if necessary
180 field_collection.Accept(*backend);
181 if (Settings::values.enable_telemetry)
182 backend->Complete();
183 backend = nullptr;
184}
185
186bool TelemetrySession::SubmitTestcase() { 190bool TelemetrySession::SubmitTestcase() {
187#ifdef ENABLE_WEB_SERVICE 191#ifdef ENABLE_WEB_SERVICE
188 auto backend = std::make_unique<WebService::TelemetryJson>( 192 auto backend = std::make_unique<WebService::TelemetryJson>(