telemetry_session.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2017 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include "common/scm_rev.h"
  6. #include "core/telemetry_session.h"
  7. namespace Core {
  8. TelemetrySession::TelemetrySession() {
  9. // TODO(bunnei): Replace with a backend that logs to our web service
  10. backend = std::make_unique<Telemetry::NullVisitor>();
  11. // Log one-time session start information
  12. const auto duration{std::chrono::steady_clock::now().time_since_epoch()};
  13. const auto start_time{std::chrono::duration_cast<std::chrono::microseconds>(duration).count()};
  14. AddField(Telemetry::FieldType::Session, "StartTime", start_time);
  15. // Log one-time application information
  16. const bool is_git_dirty{std::strstr(Common::g_scm_desc, "dirty") != nullptr};
  17. AddField(Telemetry::FieldType::App, "GitIsDirty", is_git_dirty);
  18. AddField(Telemetry::FieldType::App, "GitBranch", Common::g_scm_branch);
  19. AddField(Telemetry::FieldType::App, "GitRevision", Common::g_scm_rev);
  20. }
  21. TelemetrySession::~TelemetrySession() {
  22. // Log one-time session end information
  23. const auto duration{std::chrono::steady_clock::now().time_since_epoch()};
  24. const auto end_time{std::chrono::duration_cast<std::chrono::microseconds>(duration).count()};
  25. AddField(Telemetry::FieldType::Session, "EndTime", end_time);
  26. // Complete the session, submitting to web service if necessary
  27. // This is just a placeholder to wrap up the session once the core completes and this is
  28. // destroyed. This will be moved elsewhere once we are actually doing real I/O with the service.
  29. field_collection.Accept(*backend);
  30. backend->Complete();
  31. backend = nullptr;
  32. }
  33. } // namespace Core