Files
FEX-Emu--FEX/External/FEXCore/Source/Utils/Telemetry.cpp
T
Lioncash 75b2f226f6 General: Migrate over to fmt where possible
Migrates lingering instances of the old logger over to fmt where
applicable. This allows removing some of the old defines and functions.

The only remaining usages of the printf-based variant of the logger is
in Tests/LinuxSyscalls/Syscalls.cpp for the strace handling.
2021-11-23 12:51:57 -05:00

63 lines
1.9 KiB
C++

#include <FEXCore/Config/Config.h>
#include <FEXCore/Utils/LogManager.h>
#include <FEXCore/Utils/Telemetry.h>
#include <array>
#include <filesystem>
#include <fstream>
#include <stddef.h>
#include <string>
#include <string_view>
#include <system_error>
namespace FEXCore::Telemetry {
#ifndef FEX_DISABLE_TELEMETRY
static std::array<Value, FEXCore::Telemetry::TelemetryType::TYPE_LAST> TelemetryValues = {{ }};
const std::array<std::string_view, FEXCore::Telemetry::TelemetryType::TYPE_LAST> TelemetryNames {
"64byte Split Locks",
"16Byte Split atomics",
"VEX instructions (AVX)",
"EVEX instructions (AVX512)",
};
void Initialize() {
auto DataDirectory = Config::GetDataDirectory();
DataDirectory += "Telemetry/";
// Ensure the folder structure is created for our configuration
std::error_code ec{};
if (!std::filesystem::exists(DataDirectory, ec) &&
!std::filesystem::create_directories(DataDirectory, ec)) {
LogMan::Msg::IFmt("Couldn't create telemetry Folder");
}
}
void Shutdown(std::filesystem::path &ApplicationName) {
auto DataDirectory = Config::GetDataDirectory();
DataDirectory += "Telemetry/" + ApplicationName.string() + ".telem";
std::error_code ec{};
if (std::filesystem::exists(DataDirectory, ec)) {
// If the file exists, retain a single backup
auto Backup = DataDirectory + ".1";
std::filesystem::copy_file(DataDirectory, Backup, std::filesystem::copy_options::overwrite_existing, ec);
}
std::fstream fs(DataDirectory, std::ios_base::out | std::ios_base::trunc);
if (fs.is_open()) {
for (size_t i = 0; i < TelemetryType::TYPE_LAST; ++i) {
auto &Name = TelemetryNames.at(i);
auto &Data = TelemetryValues.at(i);
fs << Name << ": " << *Data << std::endl;
}
fs.flush();
fs.close();
}
}
Value &GetObject(TelemetryType Type) {
return TelemetryValues.at(Type);
}
#endif
}