From 10f440cb5938c421c4b034e9e360976049e46e1e Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Tue, 18 Aug 2020 14:21:50 -0400
Subject: [PATCH] common/telemetry: Migrate namespace into the Common namespace

Migrates the Telemetry namespace into the Common namespace to make the
code consistent with the rest of our common code.
---
 src/citra/citra.cpp                           |  2 +-
 src/citra_qt/compatdb.cpp                     |  3 +-
 src/citra_qt/main.cpp                         |  2 +-
 src/common/telemetry.cpp                      |  4 +--
 src/common/telemetry.h                        |  4 +--
 src/core/core.cpp                             | 13 ++++----
 src/core/hle/service/apt/apt.cpp              |  4 +--
 src/core/loader/ncch.cpp                      |  3 +-
 src/core/telemetry_session.cpp                |  2 ++
 src/core/telemetry_session.h                  |  5 ++--
 .../renderer_opengl/gl_shader_gen.cpp         |  4 +--
 src/video_core/renderer_opengl/pica_to_gl.h   |  2 +-
 .../renderer_opengl/renderer_opengl.cpp       | 10 +++----
 src/web_service/telemetry_json.cpp            |  2 ++
 src/web_service/telemetry_json.h              | 30 +++++++++----------
 15 files changed, 47 insertions(+), 43 deletions(-)

diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp
index a1455d3734..024980a910 100644
--- a/src/citra/citra.cpp
+++ b/src/citra/citra.cpp
@@ -382,7 +382,7 @@ int main(int argc, char** argv) {
         break; // Expected case
     }
 
-    system.TelemetrySession().AddField(Telemetry::FieldType::App, "Frontend", "SDL");
+    system.TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "SDL");
 
     if (use_multiplayer) {
         if (auto member = Network::GetRoomMember().lock()) {
diff --git a/src/citra_qt/compatdb.cpp b/src/citra_qt/compatdb.cpp
index 50d31a77b3..9f3e0de96e 100644
--- a/src/citra_qt/compatdb.cpp
+++ b/src/citra_qt/compatdb.cpp
@@ -52,7 +52,8 @@ void CompatDB::Submit() {
         back();
         LOG_DEBUG(Frontend, "Compatibility Rating: {}", compatibility->checkedId());
         Core::System::GetInstance().TelemetrySession().AddField(
-            Telemetry::FieldType::UserFeedback, "Compatibility", compatibility->checkedId());
+            Common::Telemetry::FieldType::UserFeedback, "Compatibility",
+            compatibility->checkedId());
 
         button(NextButton)->setEnabled(false);
         button(NextButton)->setText(tr("Submitting"));
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 5c57dbeda4..6ada2628f9 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -1002,7 +1002,7 @@ bool GMainWindow::LoadROM(const QString& filename) {
 
     game_path = filename;
 
-    system.TelemetrySession().AddField(Telemetry::FieldType::App, "Frontend", "Qt");
+    system.TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "Qt");
     return true;
 }
 
diff --git a/src/common/telemetry.cpp b/src/common/telemetry.cpp
index 16d42facde..6241d08b3a 100644
--- a/src/common/telemetry.cpp
+++ b/src/common/telemetry.cpp
@@ -12,7 +12,7 @@
 #include "common/x64/cpu_detect.h"
 #endif
 
-namespace Telemetry {
+namespace Common::Telemetry {
 
 void FieldCollection::Accept(VisitorInterface& visitor) const {
     for (const auto& field : fields) {
@@ -88,4 +88,4 @@ void AppendOSInfo(FieldCollection& fc) {
 #endif
 }
 
-} // namespace Telemetry
+} // namespace Common::Telemetry
diff --git a/src/common/telemetry.h b/src/common/telemetry.h
index a3ebed4a7b..ba5f0c87d1 100644
--- a/src/common/telemetry.h
+++ b/src/common/telemetry.h
@@ -10,7 +10,7 @@
 #include <string>
 #include "common/common_types.h"
 
-namespace Telemetry {
+namespace Common::Telemetry {
 
 /// Field type, used for grouping fields together in the final submitted telemetry log
 enum class FieldType : u8 {
@@ -196,4 +196,4 @@ void AppendCPUInfo(FieldCollection& fc);
 /// such as platform name, etc.
 void AppendOSInfo(FieldCollection& fc);
 
-} // namespace Telemetry
+} // namespace Common::Telemetry
diff --git a/src/core/core.cpp b/src/core/core.cpp
index ee90da82f1..20a9b34b59 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -519,14 +519,13 @@ void System::RegisterImageInterface(std::shared_ptr<Frontend::ImageInterface> im
 void System::Shutdown(bool is_deserializing) {
     // Log last frame performance stats
     const auto perf_results = GetAndResetPerfStats();
-    telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_EmulationSpeed",
+    constexpr auto performance = Common::Telemetry::FieldType::Performance;
+
+    telemetry_session->AddField(performance, "Shutdown_EmulationSpeed",
                                 perf_results.emulation_speed * 100.0);
-    telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_Framerate",
-                                perf_results.game_fps);
-    telemetry_session->AddField(Telemetry::FieldType::Performance, "Shutdown_Frametime",
-                                perf_results.frametime * 1000.0);
-    telemetry_session->AddField(Telemetry::FieldType::Performance, "Mean_Frametime_MS",
-                                perf_stats->GetMeanFrametime());
+    telemetry_session->AddField(performance, "Shutdown_Framerate", perf_results.game_fps);
+    telemetry_session->AddField(performance, "Shutdown_Frametime", perf_results.frametime * 1000.0);
+    telemetry_session->AddField(performance, "Mean_Frametime_MS", perf_stats->GetMeanFrametime());
 
     // Shutdown emulation session
     VideoCore::Shutdown();
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index a22926a9c6..323bebaab3 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -230,8 +230,8 @@ void Module::APTInterface::GetSharedFont(Kernel::HLERequestContext& ctx) {
     IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
 
     // Log in telemetry if the game uses the shared font
-    apt->system.TelemetrySession().AddField(Telemetry::FieldType::Session, "RequiresSharedFont",
-                                            true);
+    apt->system.TelemetrySession().AddField(Common::Telemetry::FieldType::Session,
+                                            "RequiresSharedFont", true);
 
     if (!apt->shared_font_loaded) {
         // On real 3DS, font loading happens on booting. However, we load it on demand to coordinate
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 6f32cc2eb8..3fade83a93 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -199,7 +199,8 @@ ResultStatus AppLoader_NCCH::Load(std::shared_ptr<Kernel::Process>& process) {
     }
 
     auto& system = Core::System::GetInstance();
-    system.TelemetrySession().AddField(Telemetry::FieldType::Session, "ProgramId", program_id);
+    system.TelemetrySession().AddField(Common::Telemetry::FieldType::Session, "ProgramId",
+                                       program_id);
 
     if (auto room_member = Network::GetRoomMember().lock()) {
         Network::GameInfo game_info;
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index 685cbe5e9a..13c58e2f7d 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -20,6 +20,8 @@
 
 namespace Core {
 
+namespace Telemetry = Common::Telemetry;
+
 static u64 GenerateTelemetryId() {
     u64 telemetry_id{};
     CryptoPP::AutoSeededRandomPool rng;
diff --git a/src/core/telemetry_session.h b/src/core/telemetry_session.h
index a5dd57ab1d..f64dd2a640 100644
--- a/src/core/telemetry_session.h
+++ b/src/core/telemetry_session.h
@@ -53,7 +53,7 @@ public:
      * @param value Value for the field to add.
      */
     template <typename T>
-    void AddField(Telemetry::FieldType type, const char* name, T value) {
+    void AddField(Common::Telemetry::FieldType type, const char* name, T value) {
         field_collection.AddField(type, name, std::move(value));
     }
 
@@ -64,7 +64,8 @@ public:
     bool SubmitTestcase();
 
 private:
-    Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
+    /// Tracks all added fields for the session
+    Common::Telemetry::FieldCollection field_collection;
 };
 
 /**
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 9ac385ed9c..0b195f7647 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -1532,8 +1532,8 @@ vec4 secondary_fragment_color = vec4(0.0);
         // Blend the fog
         out += "last_tex_env_out.rgb = mix(fog_color.rgb, last_tex_env_out.rgb, fog_factor);\n";
     } else if (state.fog_mode == TexturingRegs::FogMode::Gas) {
-        Core::System::GetInstance().TelemetrySession().AddField(Telemetry::FieldType::Session,
-                                                                "VideoCore_Pica_UseGasMode", true);
+        Core::System::GetInstance().TelemetrySession().AddField(
+            Common::Telemetry::FieldType::Session, "VideoCore_Pica_UseGasMode", true);
         LOG_CRITICAL(Render_OpenGL, "Unimplemented gas mode");
         out += "discard; }";
         return {std::move(out)};
diff --git a/src/video_core/renderer_opengl/pica_to_gl.h b/src/video_core/renderer_opengl/pica_to_gl.h
index ce25f79075..3b44efd497 100644
--- a/src/video_core/renderer_opengl/pica_to_gl.h
+++ b/src/video_core/renderer_opengl/pica_to_gl.h
@@ -91,7 +91,7 @@ inline GLenum WrapMode(Pica::TexturingRegs::TextureConfig::WrapMode mode) {
 
     if (index > 3) {
         Core::System::GetInstance().TelemetrySession().AddField(
-            Telemetry::FieldType::Session, "VideoCore_Pica_UnsupportedTextureWrapMode",
+            Common::Telemetry::FieldType::Session, "VideoCore_Pica_UnsupportedTextureWrapMode",
             static_cast<u32>(index));
         LOG_WARNING(Render_OpenGL, "Using texture wrap mode {}", index);
     }
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index bf123c4e05..5578c4a031 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -1210,12 +1210,10 @@ VideoCore::ResultStatus RendererOpenGL::Init() {
     LOG_INFO(Render_OpenGL, "GL_RENDERER: {}", gpu_model);
 
     auto& telemetry_session = Core::System::GetInstance().TelemetrySession();
-    telemetry_session.AddField(Telemetry::FieldType::UserSystem, "GPU_Vendor",
-                               std::string(gpu_vendor));
-    telemetry_session.AddField(Telemetry::FieldType::UserSystem, "GPU_Model",
-                               std::string(gpu_model));
-    telemetry_session.AddField(Telemetry::FieldType::UserSystem, "GPU_OpenGL_Version",
-                               std::string(gl_version));
+    constexpr auto user_system = Common::Telemetry::FieldType::UserSystem;
+    telemetry_session.AddField(user_system, "GPU_Vendor", std::string(gpu_vendor));
+    telemetry_session.AddField(user_system, "GPU_Model", std::string(gpu_model));
+    telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string(gl_version));
 
     if (!strcmp(gpu_vendor, "GDI Generic")) {
         return VideoCore::ResultStatus::ErrorGenericDrivers;
diff --git a/src/web_service/telemetry_json.cpp b/src/web_service/telemetry_json.cpp
index 9156ce8028..97d19f6964 100644
--- a/src/web_service/telemetry_json.cpp
+++ b/src/web_service/telemetry_json.cpp
@@ -10,6 +10,8 @@
 
 namespace WebService {
 
+namespace Telemetry = Common::Telemetry;
+
 struct TelemetryJson::Impl {
     Impl(std::string host, std::string username, std::string token)
         : host{std::move(host)}, username{std::move(username)}, token{std::move(token)} {}
diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h
index 5b6d3cfb52..f2cb19840d 100644
--- a/src/web_service/telemetry_json.h
+++ b/src/web_service/telemetry_json.h
@@ -15,25 +15,25 @@ namespace WebService {
  * Implementation of VisitorInterface that serialized telemetry into JSON, and submits it to the
  * Citra web service
  */
-class TelemetryJson : public Telemetry::VisitorInterface {
+class TelemetryJson : public Common::Telemetry::VisitorInterface {
 public:
     TelemetryJson(std::string host, std::string username, std::string token);
     ~TelemetryJson() override;
 
-    void Visit(const Telemetry::Field<bool>& field) override;
-    void Visit(const Telemetry::Field<double>& field) override;
-    void Visit(const Telemetry::Field<float>& field) override;
-    void Visit(const Telemetry::Field<u8>& field) override;
-    void Visit(const Telemetry::Field<u16>& field) override;
-    void Visit(const Telemetry::Field<u32>& field) override;
-    void Visit(const Telemetry::Field<u64>& field) override;
-    void Visit(const Telemetry::Field<s8>& field) override;
-    void Visit(const Telemetry::Field<s16>& field) override;
-    void Visit(const Telemetry::Field<s32>& field) override;
-    void Visit(const Telemetry::Field<s64>& field) override;
-    void Visit(const Telemetry::Field<std::string>& field) override;
-    void Visit(const Telemetry::Field<const char*>& field) override;
-    void Visit(const Telemetry::Field<std::chrono::microseconds>& field) override;
+    void Visit(const Common::Telemetry::Field<bool>& field) override;
+    void Visit(const Common::Telemetry::Field<double>& field) override;
+    void Visit(const Common::Telemetry::Field<float>& field) override;
+    void Visit(const Common::Telemetry::Field<u8>& field) override;
+    void Visit(const Common::Telemetry::Field<u16>& field) override;
+    void Visit(const Common::Telemetry::Field<u32>& field) override;
+    void Visit(const Common::Telemetry::Field<u64>& field) override;
+    void Visit(const Common::Telemetry::Field<s8>& field) override;
+    void Visit(const Common::Telemetry::Field<s16>& field) override;
+    void Visit(const Common::Telemetry::Field<s32>& field) override;
+    void Visit(const Common::Telemetry::Field<s64>& field) override;
+    void Visit(const Common::Telemetry::Field<std::string>& field) override;
+    void Visit(const Common::Telemetry::Field<const char*>& field) override;
+    void Visit(const Common::Telemetry::Field<std::chrono::microseconds>& field) override;
 
     void Complete() override;
     bool SubmitTestcase() override;