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.
This commit is contained in:
parent
05af9d915c
commit
215fd82738
@ -144,7 +144,6 @@ struct System::Impl {
|
|||||||
ResultStatus Load(System& system, Frontend::EmuWindow& emu_window,
|
ResultStatus Load(System& system, Frontend::EmuWindow& emu_window,
|
||||||
const std::string& filepath) {
|
const std::string& filepath) {
|
||||||
app_loader = Loader::GetLoader(GetGameFileFromPath(virtual_filesystem, filepath));
|
app_loader = Loader::GetLoader(GetGameFileFromPath(virtual_filesystem, filepath));
|
||||||
|
|
||||||
if (!app_loader) {
|
if (!app_loader) {
|
||||||
LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
|
LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
|
||||||
return ResultStatus::ErrorGetLoader;
|
return ResultStatus::ErrorGetLoader;
|
||||||
@ -167,6 +166,7 @@ struct System::Impl {
|
|||||||
return init_result;
|
return init_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
telemetry_session->AddInitialInfo(*app_loader);
|
||||||
auto main_process = Kernel::Process::Create(system, "main");
|
auto main_process = Kernel::Process::Create(system, "main");
|
||||||
const auto [load_result, load_parameters] = app_loader->Load(*main_process);
|
const auto [load_result, load_parameters] = app_loader->Load(*main_process);
|
||||||
if (load_result != Loader::ResultStatus::Success) {
|
if (load_result != Loader::ResultStatus::Success) {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
|
|
||||||
#include "core/core.h"
|
|
||||||
#include "core/file_sys/control_metadata.h"
|
#include "core/file_sys/control_metadata.h"
|
||||||
#include "core/file_sys/patch_manager.h"
|
#include "core/file_sys/patch_manager.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
@ -101,7 +100,31 @@ bool VerifyLogin(const std::string& username, const std::string& token) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TelemetrySession::TelemetrySession() {
|
TelemetrySession::TelemetrySession() = default;
|
||||||
|
|
||||||
|
TelemetrySession::~TelemetrySession() {
|
||||||
|
// Log one-time session end information
|
||||||
|
const s64 shutdown_time{std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
std::chrono::system_clock::now().time_since_epoch())
|
||||||
|
.count()};
|
||||||
|
AddField(Telemetry::FieldType::Session, "Shutdown_Time", shutdown_time);
|
||||||
|
|
||||||
|
#ifdef ENABLE_WEB_SERVICE
|
||||||
|
auto backend = std::make_unique<WebService::TelemetryJson>(
|
||||||
|
Settings::values.web_api_url, Settings::values.yuzu_username, Settings::values.yuzu_token);
|
||||||
|
#else
|
||||||
|
auto backend = std::make_unique<Telemetry::NullVisitor>();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Complete the session, submitting to web service if necessary
|
||||||
|
field_collection.Accept(*backend);
|
||||||
|
if (Settings::values.enable_telemetry) {
|
||||||
|
backend->Complete();
|
||||||
|
}
|
||||||
|
backend = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader) {
|
||||||
// Log one-time top-level information
|
// Log one-time top-level information
|
||||||
AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId());
|
AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId());
|
||||||
|
|
||||||
@ -112,26 +135,28 @@ TelemetrySession::TelemetrySession() {
|
|||||||
AddField(Telemetry::FieldType::Session, "Init_Time", init_time);
|
AddField(Telemetry::FieldType::Session, "Init_Time", init_time);
|
||||||
|
|
||||||
u64 program_id{};
|
u64 program_id{};
|
||||||
const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadProgramId(program_id)};
|
const Loader::ResultStatus res{app_loader.ReadProgramId(program_id)};
|
||||||
if (res == Loader::ResultStatus::Success) {
|
if (res == Loader::ResultStatus::Success) {
|
||||||
const std::string formatted_program_id{fmt::format("{:016X}", program_id)};
|
const std::string formatted_program_id{fmt::format("{:016X}", program_id)};
|
||||||
AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id);
|
AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id);
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
System::GetInstance().GetAppLoader().ReadTitle(name);
|
app_loader.ReadTitle(name);
|
||||||
|
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
auto [nacp, icon_file] = FileSys::PatchManager(program_id).GetControlMetadata();
|
auto [nacp, icon_file] = FileSys::PatchManager(program_id).GetControlMetadata();
|
||||||
if (nacp != nullptr)
|
if (nacp != nullptr) {
|
||||||
name = nacp->GetApplicationName();
|
name = nacp->GetApplicationName();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!name.empty())
|
if (!name.empty()) {
|
||||||
AddField(Telemetry::FieldType::Session, "ProgramName", name);
|
AddField(Telemetry::FieldType::Session, "ProgramName", name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AddField(Telemetry::FieldType::Session, "ProgramFormat",
|
AddField(Telemetry::FieldType::Session, "ProgramFormat",
|
||||||
static_cast<u8>(System::GetInstance().GetAppLoader().GetFileType()));
|
static_cast<u8>(app_loader.GetFileType()));
|
||||||
|
|
||||||
// Log application information
|
// Log application information
|
||||||
Telemetry::AppendBuildInfo(field_collection);
|
Telemetry::AppendBuildInfo(field_collection);
|
||||||
@ -162,27 +187,6 @@ TelemetrySession::TelemetrySession() {
|
|||||||
Settings::values.use_docked_mode);
|
Settings::values.use_docked_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
TelemetrySession::~TelemetrySession() {
|
|
||||||
// Log one-time session end information
|
|
||||||
const s64 shutdown_time{std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
std::chrono::system_clock::now().time_since_epoch())
|
|
||||||
.count()};
|
|
||||||
AddField(Telemetry::FieldType::Session, "Shutdown_Time", shutdown_time);
|
|
||||||
|
|
||||||
#ifdef ENABLE_WEB_SERVICE
|
|
||||||
auto backend = std::make_unique<WebService::TelemetryJson>(
|
|
||||||
Settings::values.web_api_url, Settings::values.yuzu_username, Settings::values.yuzu_token);
|
|
||||||
#else
|
|
||||||
auto backend = std::make_unique<Telemetry::NullVisitor>();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Complete the session, submitting to web service if necessary
|
|
||||||
field_collection.Accept(*backend);
|
|
||||||
if (Settings::values.enable_telemetry)
|
|
||||||
backend->Complete();
|
|
||||||
backend = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TelemetrySession::SubmitTestcase() {
|
bool TelemetrySession::SubmitTestcase() {
|
||||||
#ifdef ENABLE_WEB_SERVICE
|
#ifdef ENABLE_WEB_SERVICE
|
||||||
auto backend = std::make_unique<WebService::TelemetryJson>(
|
auto backend = std::make_unique<WebService::TelemetryJson>(
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "common/telemetry.h"
|
#include "common/telemetry.h"
|
||||||
|
|
||||||
|
namespace Loader {
|
||||||
|
class AppLoader;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +20,7 @@ namespace Core {
|
|||||||
*/
|
*/
|
||||||
class TelemetrySession {
|
class TelemetrySession {
|
||||||
public:
|
public:
|
||||||
TelemetrySession();
|
explicit TelemetrySession();
|
||||||
~TelemetrySession();
|
~TelemetrySession();
|
||||||
|
|
||||||
TelemetrySession(const TelemetrySession&) = delete;
|
TelemetrySession(const TelemetrySession&) = delete;
|
||||||
@ -25,6 +29,22 @@ public:
|
|||||||
TelemetrySession(TelemetrySession&&) = delete;
|
TelemetrySession(TelemetrySession&&) = delete;
|
||||||
TelemetrySession& operator=(TelemetrySession&&) = delete;
|
TelemetrySession& operator=(TelemetrySession&&) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the initial telemetry info necessary when starting up a title.
|
||||||
|
*
|
||||||
|
* This includes information such as:
|
||||||
|
* - Telemetry ID
|
||||||
|
* - Initialization time
|
||||||
|
* - Title ID
|
||||||
|
* - Title name
|
||||||
|
* - Title file format
|
||||||
|
* - Miscellaneous settings values.
|
||||||
|
*
|
||||||
|
* @param app_loader The application loader to use to retrieve
|
||||||
|
* title-specific information.
|
||||||
|
*/
|
||||||
|
void AddInitialInfo(Loader::AppLoader& app_loader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around the Telemetry::FieldCollection::AddField method.
|
* Wrapper around the Telemetry::FieldCollection::AddField method.
|
||||||
* @param type Type of the field to add.
|
* @param type Type of the field to add.
|
||||||
|
Loading…
Reference in New Issue
Block a user