summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/core.cpp3
-rw-r--r--src/core/core.h16
-rw-r--r--src/core/loader/ncch.cpp3
-rw-r--r--src/core/telemetry_session.cpp42
-rw-r--r--src/core/telemetry_session.h38
6 files changed, 104 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index c733e5d21..57504529f 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -174,6 +174,7 @@ set(SRCS
174 memory.cpp 174 memory.cpp
175 perf_stats.cpp 175 perf_stats.cpp
176 settings.cpp 176 settings.cpp
177 telemetry_session.cpp
177 ) 178 )
178 179
179set(HEADERS 180set(HEADERS
@@ -366,6 +367,7 @@ set(HEADERS
366 mmio.h 367 mmio.h
367 perf_stats.h 368 perf_stats.h
368 settings.h 369 settings.h
370 telemetry_session.h
369 ) 371 )
370 372
371include_directories(../../externals/dynarmic/include) 373include_directories(../../externals/dynarmic/include)
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 881f1e93c..450e7566d 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -132,6 +132,8 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
132 cpu_core = std::make_unique<ARM_DynCom>(USER32MODE); 132 cpu_core = std::make_unique<ARM_DynCom>(USER32MODE);
133 } 133 }
134 134
135 telemetry_session = std::make_unique<Core::TelemetrySession>();
136
135 CoreTiming::Init(); 137 CoreTiming::Init();
136 HW::Init(); 138 HW::Init();
137 Kernel::Init(system_mode); 139 Kernel::Init(system_mode);
@@ -162,6 +164,7 @@ void System::Shutdown() {
162 CoreTiming::Shutdown(); 164 CoreTiming::Shutdown();
163 cpu_core = nullptr; 165 cpu_core = nullptr;
164 app_loader = nullptr; 166 app_loader = nullptr;
167 telemetry_session = nullptr;
165 168
166 LOG_DEBUG(Core, "Shutdown OK"); 169 LOG_DEBUG(Core, "Shutdown OK");
167} 170}
diff --git a/src/core/core.h b/src/core/core.h
index 6c9c936b5..6af772831 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -9,6 +9,7 @@
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/memory.h" 10#include "core/memory.h"
11#include "core/perf_stats.h" 11#include "core/perf_stats.h"
12#include "core/telemetry_session.h"
12 13
13class EmuWindow; 14class EmuWindow;
14class ARM_Interface; 15class ARM_Interface;
@@ -80,6 +81,14 @@ public:
80 return cpu_core != nullptr; 81 return cpu_core != nullptr;
81 } 82 }
82 83
84 /**
85 * Returns a reference to the telemetry session for this emulation session.
86 * @returns Reference to the telemetry session.
87 */
88 Core::TelemetrySession& TelemetrySession() const {
89 return *telemetry_session;
90 }
91
83 /// Prepare the core emulation for a reschedule 92 /// Prepare the core emulation for a reschedule
84 void PrepareReschedule(); 93 void PrepareReschedule();
85 94
@@ -117,6 +126,9 @@ private:
117 /// When true, signals that a reschedule should happen 126 /// When true, signals that a reschedule should happen
118 bool reschedule_pending{}; 127 bool reschedule_pending{};
119 128
129 /// Telemetry session for this emulation session
130 std::unique_ptr<Core::TelemetrySession> telemetry_session;
131
120 static System s_instance; 132 static System s_instance;
121}; 133};
122 134
@@ -124,4 +136,8 @@ inline ARM_Interface& CPU() {
124 return System::GetInstance().CPU(); 136 return System::GetInstance().CPU();
125} 137}
126 138
139inline TelemetrySession& Telemetry() {
140 return System::GetInstance().TelemetrySession();
141}
142
127} // namespace Core 143} // namespace Core
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 1a4e3efa8..beeb13ffa 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -9,6 +9,7 @@
9#include "common/logging/log.h" 9#include "common/logging/log.h"
10#include "common/string_util.h" 10#include "common/string_util.h"
11#include "common/swap.h" 11#include "common/swap.h"
12#include "core/core.h"
12#include "core/file_sys/archive_selfncch.h" 13#include "core/file_sys/archive_selfncch.h"
13#include "core/hle/kernel/process.h" 14#include "core/hle/kernel/process.h"
14#include "core/hle/kernel/resource_limit.h" 15#include "core/hle/kernel/resource_limit.h"
@@ -339,6 +340,8 @@ ResultStatus AppLoader_NCCH::Load() {
339 340
340 LOG_INFO(Loader, "Program ID: %016" PRIX64, ncch_header.program_id); 341 LOG_INFO(Loader, "Program ID: %016" PRIX64, ncch_header.program_id);
341 342
343 Core::Telemetry().AddField(Telemetry::FieldType::Session, "ProgramId", ncch_header.program_id);
344
342 is_loaded = true; // Set state to loaded 345 is_loaded = true; // Set state to loaded
343 346
344 result = LoadExec(); // Load the executable into memory for booting 347 result = LoadExec(); // Load the executable into memory for booting
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
new file mode 100644
index 000000000..ddc8b262e
--- /dev/null
+++ b/src/core/telemetry_session.cpp
@@ -0,0 +1,42 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstring>
6
7#include "common/scm_rev.h"
8#include "core/telemetry_session.h"
9
10namespace Core {
11
12TelemetrySession::TelemetrySession() {
13 // TODO(bunnei): Replace with a backend that logs to our web service
14 backend = std::make_unique<Telemetry::NullVisitor>();
15
16 // Log one-time session start information
17 const auto duration{std::chrono::steady_clock::now().time_since_epoch()};
18 const auto start_time{std::chrono::duration_cast<std::chrono::microseconds>(duration).count()};
19 AddField(Telemetry::FieldType::Session, "StartTime", start_time);
20
21 // Log one-time application information
22 const bool is_git_dirty{std::strstr(Common::g_scm_desc, "dirty") != nullptr};
23 AddField(Telemetry::FieldType::App, "GitIsDirty", is_git_dirty);
24 AddField(Telemetry::FieldType::App, "GitBranch", Common::g_scm_branch);
25 AddField(Telemetry::FieldType::App, "GitRevision", Common::g_scm_rev);
26}
27
28TelemetrySession::~TelemetrySession() {
29 // Log one-time session end information
30 const auto duration{std::chrono::steady_clock::now().time_since_epoch()};
31 const auto end_time{std::chrono::duration_cast<std::chrono::microseconds>(duration).count()};
32 AddField(Telemetry::FieldType::Session, "EndTime", end_time);
33
34 // Complete the session, submitting to web service if necessary
35 // This is just a placeholder to wrap up the session once the core completes and this is
36 // destroyed. This will be moved elsewhere once we are actually doing real I/O with the service.
37 field_collection.Accept(*backend);
38 backend->Complete();
39 backend = nullptr;
40}
41
42} // namespace Core
diff --git a/src/core/telemetry_session.h b/src/core/telemetry_session.h
new file mode 100644
index 000000000..cf53835c3
--- /dev/null
+++ b/src/core/telemetry_session.h
@@ -0,0 +1,38 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <memory>
8#include "common/telemetry.h"
9
10namespace Core {
11
12/**
13 * Instruments telemetry for this emulation session. Creates a new set of telemetry fields on each
14 * session, logging any one-time fields. Interfaces with the telemetry backend used for submitting
15 * data to the web service. Submits session data on close.
16 */
17class TelemetrySession : NonCopyable {
18public:
19 TelemetrySession();
20 ~TelemetrySession();
21
22 /**
23 * Wrapper around the Telemetry::FieldCollection::AddField method.
24 * @param type Type of the field to add.
25 * @param name Name of the field to add.
26 * @param value Value for the field to add.
27 */
28 template <typename T>
29 void AddField(Telemetry::FieldType type, const char* name, T value) {
30 field_collection.AddField(type, name, std::move(value));
31 }
32
33private:
34 Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
35 std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
36};
37
38} // namespace Core